Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LAMBEGO_IO.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/LAMBEGO_IO.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.LAMBEGO_IO");
32 
34  bin_names_.push_back( 'L' );
35  bin_names_.push_back( 'A' );
36  bin_names_.push_back( 'M' );
37  bin_names_.push_back( 'B' );
38  bin_names_.push_back( 'E' );
39  bin_names_.push_back( 'G' );
40  bin_names_.push_back( 'O' );
41 }
42 
44  std::istream & input
45 ) {
46  using core::Real;
47  using std::string;
48  using utility::vector1;
49  using std::istringstream;
50 
51  string line;
52  getline( input, line );
53  tracer.Debug << "read header " << line << std::endl;
54 
55  probs_.clear();
56  sequence_.clear();
57  while( getline( input, line ) ) {
58  if ( line.substr(0,1) == "#" ) continue;
59  istringstream line_stream( line );
60  tracer.Debug << "line " << line << std::endl;
61 
62  char aa;
63  Size resi;
64  vector1< Real > per_residue_probs( bin_names_.size(), 0.0 );
65  line_stream >> resi;
66  line_stream >> aa;
67  sequence_ += aa;
68  for ( Size ii = 1, n_bins = bin_names_.size(); ii <= n_bins; ++ii ) {
69  line_stream >> per_residue_probs[ii];
70  }
71  if ( line_stream.fail() ) {
72  utility_exit_with_message( "Error reading in LAMBEGO_IO::read()!" );
73  }
74  runtime_assert( per_residue_probs.size() == bin_names_.size() );
75  probs_.push_back( per_residue_probs );
76  }
77 }
78 
79 void LAMBEGO_IO::write( std::ostream & output ) {
80  using core::Real;
81  using utility::vector1;
82 
83  output << "resi aa ";
84  for ( vector1< char >::const_iterator it = bin_names_.begin(),
85  end = bin_names_.end(); it != end; ++it
86  ) {
87  output << *it;
88  if ( it + 1 != end ) output << ' ';
89  }
90  output << std::endl;
91 
92  Size seq_idx(1);
93  for ( vector1< vector1< Real > >::const_iterator row_it = probs_.begin(),
94  row_end = probs_.end(); row_it != row_end; ++row_it
95  ) {
96  output << seq_idx << ' ' << sequence_[seq_idx-1] << ' ';
97  for ( vector1< Real >::const_iterator it = row_it->begin(),
98  end = row_it->end(); it != end; ++it
99  ) {
100  output << *it;
101  if ( it + 1 != end ) output << ' ';
102  }
103  output << std::endl;
104  seq_idx++;
105  }
106 }
107 
109 LAMBEGO_IO::prof_row( Size const idx ) const {
110  runtime_assert( idx <= probs_.size() );
111  return probs_[ idx ];
112 }
113 
115  return probs_;
116 }
117 
119  return probs_.size();
120 }
121 
122 } // frag_picker
123 } // protocols