21 #include <utility/exit.hh>
22 #include <utility/io/izstream.hh>
24 #include <ObjexxFCL/string.functions.hh>
30 #include <basic/Tracer.hh>
32 #include <utility/vector1.hh>
43 static basic::Tracer
tr(
"core.sequence.SequenceAlignment" );
54 if (
size() < 1 )
return 0;
60 using ObjexxFCL::string_of;
62 msg +=
"Requested sequence " + string_of(idx)
63 +
" but alignment only has " + string_of(
size()) +
" sequences\n";
64 msg +=
"Alignments:\n" +
to_string() +
"\n";
65 utility_exit_with_message( msg );
90 std::map< std::string, core::Real >::const_iterator it(
94 if ( it ==
scores_.end() )
return 0;
106 retval +=
"# score " + ObjexxFCL::string_of(
score()) +
"\n";
108 for (
Size i = 1; i <=
size(); ++i ) {
109 retval +=
sequence(i)->to_string() +
"\n";
116 return ObjexxFCL::uppercased(
sequence(2)->
id() );
122 utility::io::izstream data( filename );
124 utility_exit_with_message(
125 "ERROR: Unable to open alignment file: " + filename
130 while ( getline( data, line ) ) {
131 std::istringstream input( line );
133 temp_seq->read_data( input );
140 while ( getline( in, line ) ) {
141 std::istringstream input( line );
142 if ( line.substr(0,1) ==
"#" ) {
143 if ( line.substr(2,5) ==
"score" ) {
146 input >> dummy >> dummy >> dummy >> sc;
149 }
else if ( line.substr(0,2) ==
"--" ) {
154 temp_seq->read_data( input );
165 runtime_assert( idx1 <=
size() && idx1 > 0 );
166 runtime_assert( idx2 <=
size() && idx2 > 0);
174 SequenceMapping mapping( (*it1)->ungapped_length(), (*it2)->ungapped_length() );
176 for (
Size pos = 1; pos <=
length(); ++pos ) {
177 Size const seq1_pos( (*it1)->resnum(pos) );
178 Size const seq2_pos( (*it2)->resnum(pos) );
179 if ( seq1_pos != 0 && seq2_pos != 0 ) {
180 mapping[ seq1_pos ] = seq2_pos;
195 while ( pos <=
length() ) {
197 bool delete_column(
true );
202 if ( !(*it)->is_gap(pos) ) {
205 delete_column =
false;
209 if ( delete_column ) {
214 (*it)->delete_position( pos );
234 for ( iter it = scores.begin(),
end = scores.end(); it !=
end; ++it ) {
245 for (
Size i = 1; i <=
size(); ++i ) {
246 for (
Size j = i + 1; j <=
size(); ++j ) {
247 bool last_pos_was_gapped(
false );
253 last_pos_was_gapped =
true;
256 if ( last_pos_was_gapped ) scores[k] += ss->gap_extend();
257 else scores[k] += ss->gap_open();
258 last_pos_was_gapped =
true;
260 bool over_run(
false);
263 tr.Error <<
"Attempting to run off the end of sequence!" << std::endl;
264 tr.Error <<
"asked for position " << k <<
" in seq:" << std::endl;
269 tr.Error <<
"Attempting to run off the end of sequence!" << std::endl;
270 tr.Error <<
"asked for position " << k <<
" in seq:" << std::endl;
275 last_pos_was_gapped =
false;
286 for (
Size jj = 1; jj <=
size(); ++jj ) {
288 std::string msg(
"Error: length mismatch between sequence and alignment" );
289 msg +=
"problem with sequence: " +
sequences_[jj]->to_string();
291 utility_exit_with_message( msg );
309 if ( ident ) ++n_ident;
324 bool in_frame(
true );
330 if ( (*seq1)->is_gap( i ) )
continue;
332 for ( it = seq1 + 1, end =
sequences_.end(); it !=
end; ++it ) {
333 if ( (*it)->is_gap( i ) )
continue;
335 if ( (*seq1)->resnum(i) != (*it)->resnum(i) ) {
341 if ( in_frame ==
false )
break;
350 runtime_assert( column <=
length() );
351 runtime_assert( column > 0 );
359 indices.push_back( (*it)->resnum(column) );
380 Real gap_percentage =
static_cast< Real >
381 ( (*it)->length() - (*it)->ungapped_length() );
382 gap_percentage = gap_percentage /
static_cast< Real > (
length() );
383 max_gp = std::max( max_gp, gap_percentage );
392 bool gapped(
false );
393 for (
Size jj = 1; jj <=
size(); ++jj ) {
417 out <<
"score: " << sa.
score()
424 for (
Size i = 1; i <= sa.
size(); ++i ) {
425 out << (*sa.
sequence(i)) << std::endl;
442 ReferenceCount ( src )
456 for (
Size i = 1; i <= src.
size(); ++i ) {
471 if ( lhs.
size() < rhs.
size() ) {
return true; }
476 for (
Size ii = 1; ii <= lhs.
size(); ++ii ) {
477 l_str += lhs.
sequence(ii)->sequence();
478 r_str += rhs.
sequence(ii)->sequence();
481 return ( l_str < r_str );
492 out <<
"# " << std::endl;
494 out <<
"scores_from_program:";
501 for ( map< string, Real >::const_iterator it =
scores_.begin(),
end =
scores_.end(); it !=
end; ++it )
502 keys.push_back( it->first );
503 std::sort( keys.begin(), keys.end() );
506 out <<
" " <<
score(*it);
512 for (
Size i = 1; i <=
size(); ++i ) {
515 out <<
"--" << std::endl;