Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TorsionBinIO.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 // This file is part of the Rosetta software suite and is made available under license.
5 // The Rosetta software is developed by the contributing members of the Rosetta Commons consortium.
6 // (C) 199x-2009 Rosetta Commons participating institutions and developers.
7 // For more information, see http://www.rosettacommons.org/.
8 
9 /// @file protocols/frag_picker/TorsionBinIO.cc
10 /// @brief
11 /// @author James Thompson
12 
13 // unit headers
15 
16 // project headers
17 #include <core/types.hh>
18 #include <basic/Tracer.hh>
19 
20 // utility headers
21 #include <utility/exit.hh>
22 
23 #include <iostream>
24 #include <string>
25 
26 namespace protocols {
27 namespace frag_picker {
28 
29 using namespace core;
30 
31 static basic::Tracer tracer("protocols.frag_picker.TorsionBinIO");
32 
34  bin_names_.push_back( 'A' );
35  bin_names_.push_back( 'B' );
36  bin_names_.push_back( 'E' );
37  bin_names_.push_back( 'G' );
38  bin_names_.push_back( 'O' );
39 }
40 
42  std::istream & input
43 ) {
44  using core::Real;
45  using std::string;
46  using utility::vector1;
47  using std::istringstream;
48 
49  string line;
50  getline( input, line );
51  tracer.Debug << "read header " << line << std::endl;
52 
53  probs_.clear();
54  sequence_.clear();
55  while( getline( input, line ) ) {
56  if ( line.substr(0,1) == "#" ) continue;
57  istringstream line_stream( line );
58  tracer.Debug << "line " << line << std::endl;
59 
60  char aa;
61  Size resi;
62  vector1< Real > per_residue_probs( bin_names_.size(), 0.0 );
63  line_stream >> resi;
64  line_stream >> aa;
65  sequence_ += aa;
66  for ( Size ii = 1, n_bins = bin_names_.size(); ii <= n_bins; ++ii ) {
67  line_stream >> per_residue_probs[ii];
68  }
69  if ( line_stream.fail() ) {
70  utility_exit_with_message( "Error reading in TorsionBinIO::read()!" );
71  }
72  runtime_assert( per_residue_probs.size() == bin_names_.size() );
73  probs_.push_back( per_residue_probs );
74  }
75 }
76 
77 void TorsionBinIO::write( std::ostream & output ) {
78  using core::Real;
79  using utility::vector1;
80 
81  output << "resi aa ";
82  for ( vector1< char >::const_iterator it = bin_names_.begin(),
83  end = bin_names_.end(); it != end; ++it
84  ) {
85  output << *it;
86  if ( it + 1 != end ) output << ' ';
87  }
88  output << std::endl;
89 
90  Size seq_idx(1);
91  for ( vector1< vector1< Real > >::const_iterator row_it = probs_.begin(),
92  row_end = probs_.end(); row_it != row_end; ++row_it
93  ) {
94  output << seq_idx << ' ' << sequence_[seq_idx-1] << ' ';
95  for ( vector1< Real >::const_iterator it = row_it->begin(),
96  end = row_it->end(); it != end; ++it
97  ) {
98  output << *it;
99  if ( it + 1 != end ) output << ' ';
100  }
101  output << std::endl;
102  seq_idx++;
103  }
104 }
105 
107 TorsionBinIO::prof_row( Size const idx ) const {
108  runtime_assert( idx <= probs_.size() );
109  return probs_[ idx ];
110 }
111 
113  return probs_;
114 }
115 
117  return probs_.size();
118 }
119 
120 } // frag_picker
121 } // protocols