Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ExtendAlignerSW.cc
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file SWAligner.hh
11 /// @brief class definition for a class that aligns two Sequence objects using ScoringScheme
12 /// and the Smith-Waterman alignment algorithm.
13 /// @author James Thompson
14 
15 #include <core/types.hh>
16 #include <basic/Tracer.hh>
17 
21 
25 
26 #include <utility/vector1.hh>
27 #include <utility/io/izstream.hh>
28 
29 #include <ObjexxFCL/format.hh>
30 #include <iostream>
31 #include <string>
32 
33 namespace core {
34 namespace sequence {
35 
37  SequenceOP seq_y,
38  SequenceOP seq_x,
40  ) {
41 
42  SequenceOP new_seq_x = seq_x->clone();
43  SequenceOP new_seq_y = seq_y->clone();
44 
45  new_seq_x->insert_gap(0);
46  new_seq_y->insert_gap(0);
47 
48  DP_Matrix scores( new_seq_x->length(), new_seq_y->length() );
49  //scores.xlab( new_seq_x->sequence_vec() );
50  //scores.ylab( new_seq_y->sequence_vec() );
51 
52  Real const threshold( 0.0 );
53 
54  CellOP best_cell( new Cell( 0.0 ) );
55  for ( Size y = 2; y <= new_seq_y->length(); ++y ) {
56  for ( Size x = 2; x <= new_seq_x->length(); ++x ) {
57 
58  // score this position
59  Real l_gap_penalty( ss->gap_open() ), u_gap_penalty( ss->gap_open() );
60  if ( scores(x,y-1)->came_from() == above ) u_gap_penalty = ss->gap_extend();
61  if ( scores(x-1,y)->came_from() == left ) l_gap_penalty = ss->gap_extend();
62 
63  Real u_gap = scores( x, y-1 )->score() + u_gap_penalty;
64  Real l_gap = scores( x-1, y )->score() + l_gap_penalty;
65  Real mm = scores( x-1, y-1 )->score() + ss->score( new_seq_x, new_seq_y, x, y );
66  //Real mm = scores( x-1, y-1 )->score() + ss->score( new_seq_x, new_seq_y, x, y ) - 0.45; // hacky
67 
68  // std::cout << scores << std::endl;
69  // std::cout << "(" << x << "," << y << ")"
70  // << " can choose from " << mm << "," << l_gap << "," << u_gap
71  // << std::endl;
72  CellOP current_cell = scores(x,y);
73  if ( mm >= l_gap && mm >= u_gap && mm >= threshold ) {
74  // std::cout << "came from diagonal with a score of " << mm << std::endl;
75  current_cell->score( mm );
76  current_cell->next( scores(x-1,y-1) );
77  current_cell->came_from( diagonal );
78  } else if ( l_gap >= mm && l_gap >= u_gap && l_gap >= threshold ) {
79  // std::cout << "came from left with a score of " << l_gap << std::endl;
80  current_cell->score( l_gap );
81  current_cell->next( scores(x-1,y) );
82  current_cell->came_from( left );
83  } else if ( u_gap >= mm && u_gap >= l_gap && u_gap >= threshold ) {
84  // std::cout << "came from above with a score of " << u_gap << std::endl;
85  current_cell->score( u_gap );
86  current_cell->next( scores(x,y-1) );
87  current_cell->came_from( above );
88  } else {
89  current_cell->score( threshold );
90  current_cell->came_from( end );
91  }
92 
93  if ( current_cell->score() > best_cell->score() ) best_cell = current_cell;
94  } // x
95  } // y
96 
97  // traceback
98  CellOP current_cell = best_cell;
99  //std::cout << "best_cell = " << best_cell->x() << "," << best_cell->y() << std::endl;
100  SequenceAlignment alignment = traceback(
101  new_seq_x,
102  new_seq_y,
103  scores,
104  best_cell
105  );
106 
107  scores.clear();
108  return alignment;
109  } // align
110 
111 } // sequence
112 } // core