Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ChemicalShiftSequence.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 ChemicalShiftSequence.cc
11 /// @author James Thompson
12 
13 #include <core/types.hh>
14 #include <basic/Tracer.hh>
17 
18 #include <utility/exit.hh>
19 #include <utility/io/izstream.hh>
20 #include <utility/file/FileName.hh>
21 #include <utility/pointer/owning_ptr.hh>
22 
23 // AUTO-REMOVED #include <core/chemical/AA.hh>
24 
25 #include <map>
26 #include <iostream>
27 #include <string>
28 
29 #include <ObjexxFCL/format.hh>
30 
31 #include <utility/vector1.hh>
32 
33 
34 
35 namespace core {
36 namespace sequence {
37 
38 static basic::Tracer tr( "core.sequence.ChemicalShiftSequence" );
39 
41  utility::file::FileName const & fn
42 ) {
43  using core::Size;
44  using core::Real;
45  using std::string;
46  using utility::vector1;
47 
48  // order of amino acids in the 2nd_inCS.tab file
49  // C
50  // CA
51  // CB
52  // HA
53  // HN
54  // N
55  static bool init_order(false);
56  static std::map< string, Size > order;
57  static Real const bad_shift ( 9999.000 );
58  static Real const upper_limit( 20.0 );
59 
60  if ( !init_order ) {
61  order[ "C" ] = 1;
62  order[ "CA" ] = 2;
63  order[ "CB" ] = 3;
64  order[ "HA" ] = 4;
65  order[ "HN" ] = 5;
66  order[ "N" ] = 6;
67  //avg_vsigma[ "C" ] = 0.948093982461;
68  //avg_vsigma[ "CA" ] = 0.828795509906;
69  //avg_vsigma[ "CB" ] = 0.969003290496;
70  //avg_vsigma[ "HA" ] = 0.231641960268;
71  //avg_vsigma[ "HN" ] = 0.725943902221;
72  //avg_vsigma[ "N" ] = 2.78164308475;
73  alphabet_.push_back( "C" );
74  alphabet_.push_back( "CA" );
75  alphabet_.push_back( "CB" );
76  alphabet_.push_back( "HA" );
77  alphabet_.push_back( "HN" );
78  alphabet_.push_back( "N" );
79  init_order = true;
80  }
81 
82  string aa_seq;
83  utility::io::izstream input(fn);
84  id(fn.name());
85 
86  if ( !input ) {
87  string msg( "ERROR: Unable to open file " + fn.name() );
88  utility_exit_with_message(msg);
89  }
90 
91  //std::cout << "reading data from " << fn.name() << std::endl;
92 
93  std::string line;
94  while ( line.substr(0,13) != "DATA SEQUENCE" ) {
95  getline( input, line );
96  }
97 
98  while ( line.substr(0,13) == "DATA SEQUENCE" ) {
99  std::string dummy;
100  std::istringstream ls( line );
101  ls >> dummy >> dummy;
102  while ( ls.good() ) {
103  ls >> dummy;
104  aa_seq += dummy;
105  }
106  getline(input,line);
107  }
108  for ( Size ii = 1; ii <= 3; ++ii ) {
109  getline( input, line );
110  }
111 
112  vector1< Real > prof_row( order.size(), bad_shift );
113  //vector1< vector1< Real > > new_prof(
114  // aa_seq.size(), prof_row
115  // //( order.size(), bad_shift )
116  //);
117 
118  vector1< vector1< Real > > new_prof;
119 
120  //std::cout << "SEQUENCE: " << aa_seq << std::endl;
121  Size last_res_no(0);
122  aa_seq = "";
123  while( getline( input, line ) ) {
124  std::istringstream ls( line );
125  core::Size res_no;
126  std::string atm_name;
127  char aa;
128  core::Real chemical_shift;
129  ls >> res_no >> aa >> atm_name >> chemical_shift;
130 
131  if ( res_no != last_res_no ) {
132  for ( Size ii = last_res_no; ii <= res_no; ++ii ) {
133  new_prof.push_back(
134  vector1< Real >( order.size(), bad_shift )
135  );
136  }
137  aa_seq += aa;
138  }
139 
140  last_res_no = res_no;
141 
142  if ( chemical_shift > upper_limit ) {
143  chemical_shift = bad_shift;
144  }
145 
146  std::cout << line << std::endl;
147  std::cout << "res_no = " << res_no << std::endl;
148  std::cout << "aa = " << aa << std::endl;
149  std::cout << "aa_seq[" << res_no-1 << "] = " << aa_seq[res_no-1]
150  << std::endl;
151  Size const idx( order[atm_name] );
152  std::cout << "idx = " << idx << std::endl;
153  std::cout << std::endl << std::endl;
154 
155  if ( idx != 0 ) new_prof[ res_no ][ idx ] = chemical_shift;
156  //runtime_assert( aa_seq[res_no-1] == aa );
157  }
158  input.close();
159  sequence(aa_seq);
160  //std::cout << "sequence = " << sequence() << std::endl;
161  //std::cout << "finished reading." << std::endl;
162 
163  sequence( aa_seq );
164  profile( new_prof );
165 
167 }
168 
170  Size /*pos*/, Size idx
171 ) {
172  // hacky - assumed order of atoms:
173  if ( idx == 1 ) {
174  return 0.948093982461;
175  } else if ( idx == 2 ) {
176  return 0.828795509906;
177  } else if ( idx == 3 ) {
178  return 0.969003290496;
179  } else if ( idx == 4 ) {
180  return 0.231641960268;
181  } else if ( idx == 5 ) {
182  return 0.725943902221;
183  } else if ( idx == 6 ) {
184  return 2.78164308475;
185  } else {
186  utility_exit_with_message("Error: invalid index!");
187  }
188  return 0.0;
189 }
190 
191 std::ostream & operator<<(
192  std::ostream & out, const ChemicalShiftSequence & p
193 ) {
194  Size width = 8;
195  Size precision = 3;
196 
197  out << p.to_string() << std::endl;
198  for ( Size i = 1; i <= p.length(); ++i ) {
199  for ( Size j = 1; j <= p.width(); ++j ) {
200  out << ObjexxFCL::fmt::F( width, precision, p.prof_row(i)[j] );
201  }
202  out << std::endl;
203  }
204 
205  return out;
206 }
207 
209  using core::Real;
210  using utility::vector1;
211 
212  runtime_assert( profile().size() == length() );
213 
214  for ( Size i = 1; i <= profile().size(); ++i ) {
215  //std::cout << profile()[i].size() << " " << alphabet_.size() << std::endl;
216  //runtime_assert( profile()[i].size() == alphabet_.size() );
217  runtime_assert( profile()[i].size() == 6 );
218  }
219 }
220 
221 
222 } // sequence
223 } // core