39 #include <basic/Tracer.hh>
40 #include <utility/io/izstream.hh>
43 #include <ObjexxFCL/FArray1D.hh>
44 #include <ObjexxFCL/format.hh>
48 #include <utility/vector1.hh>
55 static basic::Tracer
tr(
"core.fragment");
63 using namespace ObjexxFCL;
64 using namespace ObjexxFCL::fmt;
67 using namespace core::fragment;
69 if ( total_residue_ < frag_nres ) total_residue_ = frag_nres;
70 tr.Info <<
"compute strand/loop fractions for " << total_residue_ <<
" residues... " << std::endl;
71 if ( total_residue_ == 0 ) utility_exit_with_message(
"no fragment to compute secondary structure ");
73 strand_fraction_.dimension( total_residue_, 0.0 );
74 loop_fraction_.dimension( total_residue_, 0.0 );
77 confidence_.dimension( total_residue_, 0.0 );
79 FArray1D_int count( total_residue_, 0 );
81 strand_fraction_(1) = 0.0;
82 strand_fraction_(total_residue_) = 0.0;
85 Size central_residue( static_cast< Size > (it->frame().length()/2.0+0.5) );
86 Size loop_start = bJustCenterResidue ? central_residue : 1;
87 Size loop_end = bJustCenterResidue ? central_residue : it->frame().length();
88 for (
Size fpos = loop_start; fpos <= loop_end; ++fpos ) {
89 char const ss = it->fragment().secstruct( fpos );
90 Size pos = it->frame().seqpos( fpos );
91 if ( ss ==
'E' || ss ==
'L' || ss ==
'H' ) {
93 if ( ss ==
'E' ) strand_fraction_( pos ) += 1.0;
94 else if ( ss ==
'L' ) loop_fraction_( pos ) += 1.0;
96 tr.Warning <<
"found invalid secondary structure assignment in fragment data: " << ss << std::endl;
101 for (
Size pos = 1; pos <= total_residue_; pos++ ) {
102 if ( count( pos ) ) {
103 strand_fraction_(pos) /= count ( pos );
104 loop_fraction_(pos) /= count ( pos );
106 loop_fraction_( pos ) = 1.0;
107 strand_fraction_( pos ) = 0.0;
140 if ( max < strand_fraction( pos ) ) {
141 max = strand_fraction_( pos );
144 if ( max < helix_fraction( pos ) ) {
152 utility::io::izstream data( fn );
154 tr.Fatal <<
"can't secondary structure file!!!" << fn << std::endl;
156 utility::exit( EXIT_FAILURE, __FILE__, __LINE__);
160 getline( data, line);
161 std::istringstream line_stream( line );
165 line_stream >> dummy >> dummy >> dummy >> dummy >> total_residue_;
168 loop_fraction_.dimension( total_residue_, 0.0 );
169 strand_fraction_.dimension( total_residue_, 0.0 );
171 while ( getline( data, line ) ) {
172 std::istringstream line_stream( line );
176 line_stream >> pos >> ef >> hf >> lf;
178 if ( line_stream.fail() ) {
179 tr.Warning <<
"parse error: " << line << std::endl;
183 loop_fraction_( pos ) = lf;
184 strand_fraction_( pos ) = ef;
185 if ( std::abs( helix_fraction( pos ) - hf ) > 0.01 ) {
186 tr.Warning <<
"inconsistency in secondary structure file at position "
187 << pos <<
" H ( read ) = " << hf <<
" 1.0-L-E ( expected ) "
188 << helix_fraction( pos ) << std::endl;
198 strand_fraction_.dimension( total_residue_, 0.0 );
199 loop_fraction_.dimension( total_residue_, 0.0 );
202 if ( ss ==
'L' ) loop_fraction_( pos ) += 1.0;
203 if ( ss ==
'E' ) strand_fraction_( pos ) += 1.0;
209 runtime_assert(components.size() == weights.size());
210 Size size = components[1]->total_residue_;
211 for(
Size i=2;i<=components.size();i++)
212 runtime_assert(components[i]->total_residue_ == size);
213 total_residue_ =
size;
214 strand_fraction_.dimension( size, 0.0 );
215 loop_fraction_.dimension( size, 0.0 );
216 for (
Size pos = 1; pos <=
size; pos++ ) {
220 for(
Size i=1;i<=components.size();i++) {
221 pE += components[i]->strand_fraction(pos) * weights[i];
222 pH += components[i]->helix_fraction(pos) * weights[i];
223 pL += components[i]->loop_fraction(pos) * weights[i];
225 set_fractions(pos,pH,pE,pL);
233 int const width( 10 );
234 os <<
A( width,
"pos") <<
A( width,
"E" ) <<
A( width,
"H" ) <<
A( width,
"L" ) << I( width, 4, total_residue() ) << std::endl;
235 for (
Size i = 1; i<= total_residue(); i++ ) {
236 os << I( width, 4, i)
237 << F( width, 4, strand_fraction( i ) )
238 << F( width, 4, helix_fraction( i ) )
239 << F( width, 4, loop_fraction( i ) )
246 utility::io::izstream data( filename );
248 tr.Fatal <<
"can't secondary structure file!!!" << filename << std::endl;
250 utility::exit( EXIT_FAILURE, __FILE__, __LINE__);
252 read_psipred_ss2( data );
258 getline( data, line);
261 Size total_reserved( 500 );
262 loop_fraction_.dimension( total_reserved, 0.0 );
263 strand_fraction_.dimension( total_reserved, 0.0 );
265 while ( getline( data, line ) ) {
266 if ( line.size() == 0 )
continue;
267 if ( line[ 0 ] ==
'#' )
continue;
268 std::istringstream line_stream( line );
273 line_stream >> pos >> aa >> secstruct_letter >> lf >> hf >> ef;
276 if ( line_stream.fail() ) {
277 tr.Warning <<
"parse error: " << line << std::endl;
281 Real const total( lf + hf + ef );
286 if ( pos > total_reserved ) {
288 loop_fraction_.redimension( total_reserved );
289 strand_fraction_.redimension( total_reserved );
291 for ( last_pos = last_pos+1; last_pos<pos; last_pos++ ) {
292 loop_fraction_( last_pos ) = 1.0/3;
293 strand_fraction_( last_pos ) = 1.0/3;
296 if ( total_residue_ < pos ) total_residue_ = pos;
297 loop_fraction_( pos ) = lf;
298 strand_fraction_( pos ) = ef;
300 if ( std::abs( helix_fraction( pos ) - hf ) > 0.01 ) {
301 tr.Warning <<
"inconsistency in secondary structure file at position "
302 << pos <<
" H ( read ) = " << hf <<
" 1.0-L-E ( expected ) "
303 << helix_fraction( pos ) << std::endl;
315 int const width( 10 );
316 os <<
"# PSIPRED VFORMAT (PSIPRED V2.5 by David Jones)\n\n";
317 for (
Size i = 1; i<= total_residue(); i++ ) {
318 char ss = secstruct( i );
319 if ( ss ==
'L' ) ss =
'C';
320 os << I( width, 4, i);
321 os <<
A( 2, ( sequence.size() >= i ) ? sequence[ i - 1 ] :
'X' )
323 << F( width, 3, loop_fraction( i ) )
324 << F( width, 3, helix_fraction( i ) )
325 << F( width, 3, strand_fraction( i ) )
331 utility::io::izstream data( filename );
333 tr.Fatal <<
"can't secondary structure file!!!" << filename << std::endl;
335 utility::exit( EXIT_FAILURE, __FILE__, __LINE__);
337 read_talos_ss( data );
343 bool header_done(
false);
345 while (!header_done && !data.eof()) {
346 getline( data, line);
347 std::istringstream line_stream( line );
349 line_stream >> keyword;
351 if (keyword ==
"FORMAT") {
357 Size total_reserved( 500 );
358 loop_fraction_.dimension( total_reserved, 0.0 );
359 strand_fraction_.dimension( total_reserved, 0.0 );
360 confidence_.dimension( total_reserved, 0.0 );
362 while ( getline( data, line ) ) {
363 if ( line.size() == 0 )
continue;
364 if ( line[ 0 ] ==
'#' )
continue;
365 std::istringstream line_stream( line );
372 line_stream >> pos >> aa >> junk >> junk >> hf >> ef >> lf >> confidence >> secstruct_letter;
374 if ( line_stream.fail() ) {
375 tr.Warning <<
"parse error: " << line << std::endl;
379 Real const total( lf + hf + ef );
384 if ( pos > total_reserved ) {
386 loop_fraction_.redimension( total_reserved );
387 strand_fraction_.redimension( total_reserved );
388 confidence_.redimension( total_reserved );
390 if ( total_residue_ < pos ) total_residue_ = pos;
391 loop_fraction_( pos ) = lf;
392 strand_fraction_( pos ) = ef;
393 confidence_( pos ) = confidence;
395 if ( std::abs( helix_fraction( pos ) - hf ) > 0.01 ) {
396 tr.Warning <<
"inconsistency in secondary structure file at position "
397 << pos <<
" H ( read ) = " << hf <<
" 1.0-L-E ( expected ) "
398 << helix_fraction( pos ) << std::endl;
400 for ( last_pos = last_pos+1; last_pos<pos; last_pos++ ) {
401 loop_fraction_( last_pos ) = 1.0/3;
402 strand_fraction_( last_pos ) = 1.0/3;
411 if ( nres > total_residue_ ) {
412 loop_fraction_.dimension( nres );
413 strand_fraction_.dimension( nres );
414 for (
Size pos=total_residue_+1; pos<=nres; ++pos ) {
415 loop_fraction_( pos ) = 1.0;
416 strand_fraction_( pos ) = 0.0;