Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SequenceCoupling.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 SequenceCoupling.hh
11 /// @brief class definition for a sequence coupling profile that
12 // represents a probability distribution over the entire protein.
13 /// @author Hetu Kamisetty
14 
15 #include <core/types.hh>
16 #include <basic/Tracer.hh>
20 
21 #include <utility/exit.hh>
22 #include <utility/io/izstream.hh>
23 #include <utility/file/FileName.hh>
24 #include <utility/pointer/owning_ptr.hh>
25 
26 #include <core/chemical/AA.hh>
27 
28 // AUTO-REMOVED #include <ObjexxFCL/string.functions.hh>
29 #include <iostream>
30 #include <string>
31 
32 #include <utility/vector1.hh>
33 
34 namespace core {
35 namespace sequence {
36 
37 static basic::Tracer tr( "core.sequence.SequenceCoupling" );
38 
39 /*
40  void SequenceCoupling::profile(utility::vector1< utility::vector1< Real > > const & new_profile){
41  SequenceProfile::profile(new_profile);
42  }
43 
44 utility::vector1< utility::vector1< Real > > const & SequenceCoupling::profile() const{
45  SequenceProfile::profile();
46  }
47  */
49  using utility::vector1;
50  vector1< vector1< vector1< Real > > > newEdgePots;
51  for(core::Size i=1;i<=edgeList_.size();i++){
52  vector1 < Real > vertices = edgeList_[i];
53  if(!(vertices[1]==pos || vertices[2]==pos)){
54  newEdgePots.push_back(edgePots_[i]);
55  }
56  if(vertices[1]>pos){
57  vertices[1]--;
58  }
59  if(vertices[2]>pos){
60  vertices[2]--;
61  }
62  }
63  edgePots(newEdgePots);
64  numVerts_--;
65  numEdges_ = edgePots_.size();
66 
68 }
69 void SequenceCoupling::insert_char(core:: Size pos, char new_char){
70  SequenceProfile::insert_char(pos,new_char);
71  numVerts_++;
72  for(core::Size i=1;i<=edgeList_.size();i++){
74  if(vertices[1]>=pos){
75  vertices[1]++;
76  }
77  if(vertices[2]>=pos){
78  vertices[2]++;
79  }
80  }
81 }
83  utility::file::FileName const & fn
84 ) {
85  read_from_file(fn,1.0);
86 }
88  utility::file::FileName const & fn,
89  core::Real temp)
90 {
91 
93  order.resize( 20 );
100  order[ 7] = core::chemical::aa_from_oneletter_code( 'E');
101  order[ 8] = core::chemical::aa_from_oneletter_code( 'G');
102  order[ 9] = core::chemical::aa_from_oneletter_code( 'H');
103  order[10] = core::chemical::aa_from_oneletter_code( 'I');
104  order[11] = core::chemical::aa_from_oneletter_code( 'L');
105  order[12] = core::chemical::aa_from_oneletter_code( 'K');
106  order[13] = core::chemical::aa_from_oneletter_code( 'M');
107  order[14] = core::chemical::aa_from_oneletter_code( 'F');
108  order[15] = core::chemical::aa_from_oneletter_code( 'P');
109  order[16] = core::chemical::aa_from_oneletter_code( 'S');
110  order[17] = core::chemical::aa_from_oneletter_code( 'T');
111  order[18] = core::chemical::aa_from_oneletter_code( 'W');
112  order[19] = core::chemical::aa_from_oneletter_code( 'Y');
113  order[20] = core::chemical::aa_from_oneletter_code( 'V');
114  //order[21] = core::chemical::aa_from_oneletter_code( '-');
115  utility::io::izstream input( fn );
116 
117  temp_ = temp;
118  if ( !input ) {
119  std::string msg(
120  "ERROR: Unable to open file " +
121  static_cast< std::string > (fn) +
122  "!"
123  );
124  utility_exit_with_message( msg );
125  }
126  std::string line;
127 
128  tr.Debug << "reading from " << fn << std::endl;
129 
130  /*format*
131  * GREMLIN - v1
132  * <num_verts> <num_edges>
133  * vert_pot1_A vert_pot1_R ...
134  * vert_pot2_A vert_pot2_R ...
135  * ..(num_vert_lines)
136  * edgei edgej edge_pot1_AA edge_pot1_AR ...
137  * edgei' edgej' edge_pot2_AA ..
138  * ..(num_edge lines)
139  */
140  //one header line. ignored for now.
141  getline( input, line );
142  // initialize headers
143  getline( input, line );
144  std::istringstream line_stream( line );
145  line_stream >> numVerts_;
146  if ( line_stream.fail() ) {
147  utility_exit_with_message( "ERROR: failed while reading numVerts!" );
148  }
149  line_stream >> numEdges_;
150  if ( line_stream.fail() ) {
151  utility_exit_with_message( "ERROR: failed while reading numEdges!" );
152  }
153  std::string aa_seq;
154  core::Size lineCount=0;
156  while(lineCount<numVerts_ && getline(input,line)){
158  vertPot.resize( order.size() );
159  std::istringstream ls( line );
160  core::Real aa_pot;
161  core::Real min_pot = 1e9;
162  core::Size minPotAA=0;
163  Size count=1;
164  while(ls>>aa_pot){
165  vertPot[order[count]]=aa_pot;
166  if(min_pot>aa_pot){
167  min_pot = aa_pot;
168  minPotAA=count;
169  }
170  count++;
171  }
172  if(minPotAA>order.size()){
173  std::cout << " minpotAA" << minPotAA << "count " << count << std::endl;
174  utility_exit_with_message("minPotAA was of wrong size. quitting");
175  }
176  aa_seq +=core::chemical::oneletter_code_from_aa(order[minPotAA]);//dummy sequence set to most favored aa according to vertexPot
177  vertexPots.push_back(vertPot);
178  lineCount++;
179  }
180  //done vertexpots
181  profile(vertexPots);
182  core::Size edgeCount=0;
183  while(edgeCount<numEdges_ && getline(input,line)){
185  edgePot.resize(order.size());
187  std::istringstream ls( line );
188  core::Size verti, vertj;
189 
190  //read vertices
191  ls>>verti;
192  ls>>vertj;
193  edge.push_back(verti);
194  edge.push_back(vertj);
195  edgeList_.push_back(edge);
196 
197  //read edgepots
198  for(core::Size i=1; i<=order.size(); i++){
200  edgePotLine.resize( order.size() );
201  for(core::Size j=1; j<=order.size(); j++){
202  core::Real edgeWt;
203  ls>>edgeWt;
204  //edgePotLine.push_back(edgeWt);
205  edgePotLine[order[j]] = edgeWt;
206  }
207  //edgePot.push_back(edgePotLine);
208  edgePot[order[i]] = edgePotLine;
209  }
210  edgePots_.push_back(edgePot);
211  edgeCount++;
212  }
213 }
215  Size i=0;
216  for(i=1;i<=edgeList_.size();i++){
217  utility::vector1 < Real > vertices = edgeList_[i];
218  if(vertices[1]==vert1 && vertices[2] ==vert2){
219  return i;
220  }
221  }
222  return 0;
223  }
224  utility::vector1< utility::vector1 < Real > > const & SequenceCoupling::edgePotBetween(Size vert1, Size vert2) const {//direction important. if (i,j) edge exists, will not return if (j,i) asked
225  runtime_assert( vert1<= profile().size() && vert2 <= profile().size());
226  Size edgeId = findEdgeId(vert1,vert2);
227  return edgePotBetween(edgeId);
228  }
229  utility::vector1< utility::vector1 < Real > > const & SequenceCoupling::edgePotBetween(Size edgeId) const {//direction important. if (i,j) edge exists, will not return if (j,i) asked
230  runtime_assert(edgeId>0);
231  return edgePots_[edgeId];
232  }
233 }//ns sequence
234 }//ns core
235