Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Aligner.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 Aligner.cc
11 /// @brief class definition for a class that aligns two Sequence objects using
12 /// dynamic programming algorithms.
13 /// @author James Thompson
14 
15 #include <core/types.hh>
16 #include <core/sequence/Aligner.hh>
17 
21 
22 
23 // AUTO-REMOVED #include <iostream>
24 #include <string>
25 
26 #include <utility/exit.hh>
27 
28 #include <utility/vector1.hh>
29 
31 
32 #ifdef WIN32
34 #endif
35 
36 
37 namespace core {
38 namespace sequence {
39 
41  SequenceOP seq_y,
42  SequenceOP seq_x,
44 ) {
45  runtime_assert( ss != 0 );
46  runtime_assert( seq_x != 0 );
47  runtime_assert( seq_y != 0 );
48 
49  // must have ungapped sequences!
50  runtime_assert( seq_y->ungapped_length() == seq_y->length() );
51  runtime_assert( seq_x->ungapped_length() == seq_x->length() );
52 }
53 
55  SequenceOP seq_x,
56  SequenceOP seq_y,
57  DP_Matrix /*matrix*/,
59 ) {
60  // traceback
61  CellOP current_cell = start;
62  std::string aligned_seq_x(""), aligned_seq_y("");
63 
64  while( 1 ) {
65  Size current_x = current_cell->x();
66  Size current_y = current_cell->y();
67 
68  //std::cout << "at " << current_x << "," << current_y << std::endl;
69 
70  if ( current_cell->came_from() == diagonal ) {
71  //std::cout << " came from diagonal from score of " << current_cell->next()->score() << std::endl;
72  aligned_seq_x = (*seq_x)[ current_x ] + aligned_seq_x;
73  aligned_seq_y = (*seq_y)[ current_y ] + aligned_seq_y;
74  } else if ( current_cell->came_from() == left ) {
75  //std::cout << " came from left from score of " << current_cell->next()->score() << std::endl;
76  aligned_seq_x = (*seq_x)[current_x] + aligned_seq_x;
77  aligned_seq_y = '-' + aligned_seq_y;
78  seq_y->insert_gap( current_y + 1 );
79  // std::cout << "seq_x[" << current_x << "] = " << seq_x[current_x] << std::endl;
80  } else if ( current_cell->came_from() == above ) {
81  //std::cout << " came from above from score of " << current_cell->next()->score() << std::endl;
82  aligned_seq_x = '-' + aligned_seq_x;
83  aligned_seq_y = (*seq_y)[current_y] + aligned_seq_y;
84  seq_x->insert_gap( current_x + 1 );
85  } else {
86  //std::string const msg(
87  // "Unhandled case in traceback, not pointing to anything (" +
88  // "\n"
89  // //string_of(current_x) + "," +
90  // //string_of(current_y) + ")!\n"
91  //);
92  //utility_exit_with_message( msg );
93  utility_exit_with_message( "Error in traceback: pointer doesn't go anywhere!\n" );
94  }
95 
96  if ( current_cell->next()->came_from() == end ) {
97  break;
98  }
99 
100  current_cell = current_cell->next();
101  //std::cout << aligned_seq_x << std::endl << aligned_seq_y << std::endl << std::endl;
102  } // while ( current_cell->next() != 0 )
103 
104  //std::cout << std::endl << (*seq_x) << std::endl << (*seq_y) << std::endl;
105  //std::cout << matrix << std::endl;
106 
107  SequenceAlignment alignment;
108  // set starting point for both sequences. Don't forget to add whatever offset existed
109  // in Sequence.start() coming into this function. Also, subtract one for the extra gap
110  // inserted at the beginning of new_seq_x and new_seq_y.
111  SequenceOP seq_x_clone = seq_x->clone();
112  SequenceOP seq_y_clone = seq_y->clone();
113 
114  seq_x_clone->start( current_cell->x() - 2 + seq_x->start() );
115  seq_y_clone->start( current_cell->y() - 2 + seq_y->start() );
116 
117  seq_x_clone->sequence( aligned_seq_x );
118  seq_y_clone->sequence( aligned_seq_y );
119 
120  alignment.add_sequence( seq_y_clone );
121  alignment.add_sequence( seq_x_clone );
122 
123  alignment.remove_gapped_positions();
124  alignment.score( start->score() );
125 
126  return alignment;
127 } // traceback
128 
129 } // sequence
130 } // core