Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
VallProvider.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 protocols/frag_picker/VallProvider.cc
11 /// @brief reads a vall library and serves the data in chunks
12 /// @author Dominik Gront (dgront@chem.uw.edu.pl)
13 
14 
15 // type headers
16 #include <core/types.hh>
17 
19 
20 // package headers
23 
24 // project headers
25 #include <basic/Tracer.hh>
27 #include <core/pose/Pose.hh>
29 
30 
31 // utility headers
32 #include <utility/exit.hh>
33 #include <utility/io/izstream.hh>
34 
35 // C++ headers
36 #if defined(WIN32) || defined(__CYGWIN__)
37  #include <ctime>
38 #endif
39 
40 
41 #include <sstream>
42 #include <string>
43 
44 //Auto Headers
46 
47 
48 // Tracer instance for this file
49 // Named after the original location of this code
50 static basic::Tracer TR("protocols.frag_picker.VallProvider");
51 
52 namespace protocols {
53 namespace frag_picker {
54 
55 using namespace core;
56 
58 
59 VallChunkOP VallProvider::find_chunk(std::string pdb_id, char chain_id, Size residue_id) {
60 
61  for (Size i = 1; i <= chunks_.size(); ++i) {
62  VallChunkOP c = chunks_[i];
63  if (c->get_pdb_id().compare(pdb_id) != 0)
64  continue;
65  if (c->get_chain_id() != chain_id)
66  continue;
67  for (Size j = 1; j < c->size(); ++j) {
68  if (c->at(j)->resi() == residue_id)
69  return c;
70  }
71  }
72 
73  TR.Warning << "Can't find chunk that contains the residue number "
74  << residue_id << " in a protein " << pdb_id << " in a chain "
75  << chain_id << std::endl;
76 
77  return 0;
78 }
79 
81 
82  std::string key = source_chunk->chunk_key();
83  TR.Debug << "looking for a pose for " << key << std::endl;
84  if (key.compare(cached_pose_id_) == 0)
85  return cached_pose_;
86 
87  TR.Debug << "caching a pose for >" << key << "< the previous key was: >"
88  << cached_pose_id_ << "< (" << key.compare(cached_pose_id_)
89  << ")... ";
90 
91  for (Size i = 1; i <= source_chunk->size(); ++i) {
92  VallResidueOP r = source_chunk->at(i);
93  cached_pose_->set_phi(i, r->phi());
94  cached_pose_->set_psi(i, r->psi());
95  cached_pose_->set_omega(i, r->omega());
96  }
97  TR.Debug << " has " << source_chunk->size() << " residues." << std::endl;
98 
99  cached_pose_id_.clear();
100  cached_pose_id_.assign(key);
101 
102 // pose->dump_pdb("dump-"+chunk->get_pdb_id()+".pdb");
103 
104  return cached_pose_;
105 }
106 
108 
109  std::string key = source_chunk->chunk_key();
110  TR.Debug << "looking for a profile for " << key << std::endl;
111  if (key.compare(cached_profile_id_) == 0)
112  return cached_profile_;
113  TR.Debug << "caching a sequence profile for >" << key
114  << "< the previous key was: >" << cached_profile_id_ << "< ("
115  << key.compare(cached_pose_id_) << ")... ";
116 
118  for (Size i = 1; i <= source_chunk->size(); ++i) {
119  prof.push_back(source_chunk->at(i)->profile());
120  }
121  cached_profile_id_.clear();
122  cached_profile_id_.assign(key);
123 
124  if (cached_profile_ == 0)
125  cached_profile_ = new core::sequence::SequenceProfile();
126  cached_profile_->profile(prof);
127  cached_profile_->sequence(source_chunk->get_sequence());
128 
129  TR.Debug << " has " << cached_profile_->length() << " columns."
130  << std::endl;
131 
132  return cached_profile_;
133 }
134 
136 
137  using std::string;
138  using utility::vector1;
139 
141  for ( iter it = fns.begin(), end = fns.end(); it != end; ++it ) {
142  vallChunksFromLibrary( *it );
143  }
144 
145  return 0;
146 }
148  Size num_lines;
149  utility::io::izstream stream(filename);
150  if (!stream)
151  utility_exit_with_message( "can't open file: " + filename );
152  num_lines = 0;
153  std::string line;
154  getline(stream, line);
155  while(line[0] == '#') {
156  getline(stream, line);
157  }
158  while(getline(stream,line)) {
159  num_lines++;
160  }
161  return num_lines;
162 }
163 
165 
166  TR.Info << "vallChunksFromLibrary" << std::endl;
167 
168  utility::io::izstream stream(filename);
169  if (!stream)
170  utility_exit_with_message( "can't open file: " + filename );
171 
172  // statistics
173  Size n_lines = 0;
174 
175  TR.Info << "Reading Vall library from " << filename << " ... startline: " << startline << " endline: " << endline << std::endl;
176 
177  time_t time_start = time(NULL);
178 
179  Size last_key = 0;
180  if(chunks_.size() > 0) {
181  VallChunkOP last_chunk = chunks_[ chunks_.size() ];
182  last_key = last_chunk->at( last_chunk->size() )->key();
183  }
184  std::string prior_id = "";
185  Size prior_resi = 0;
186  VallChunkOP current_section = new VallChunk(this);
187  std::string line;
188  getline(stream, line);
189  while(line[0] == '#') getline(stream, line);
190 
191  VallResidueOP firstRes = new VallResidue();
192  firstRes->key(1);
193 
194  //Decides if vall is in the old nnmake format
195  //if not it tries to use the nnmake + chemical shift's format
196  if (line.length() > 300)
197  firstRes->fill_from_string_version1(line);
198  else if (line.length() > 240)
199  firstRes->fill_from_string_cs(line);
200  else if (line.length() > 110)
201  firstRes->fill_from_string(line);
202  else
203  firstRes->fill_from_string_residue_depth_version1(line);
204 
205  current_section->push_back(firstRes);
206  prior_id = firstRes->id();
207  prior_resi = firstRes->resi();
208  // parse Vall from file
209  n_lines = 1;
210 
211  while (getline(stream, line)) {
212  ++n_lines;
213  if( n_lines < startline ) continue;
214 
215  // If endline is 0, just read to the end of the file
216  if( endline != 0 && n_lines > endline ) break;
217 
218  VallResidueOP current_residue = new VallResidue();
219 
220  if (line.length() > 300)
221  current_residue->fill_from_string_version1(line);
222  else if (line.length() > 240)
223  current_residue->fill_from_string_cs(line);
224  else if (line.length() > 110)
225  current_residue->fill_from_string(line);
226  else
227  current_residue->fill_from_string_residue_depth_version1(line);
228 
229  current_residue->key( n_lines + last_key );
230  // check for start of new continuous stretch
231  if ( (current_residue->resi() != prior_resi + 1)
232  || (current_residue->id() != prior_id)) {
233  push_back(current_section);
234  Size t = current_section->size();
235  if (t > largest_chunk_size_)
236  largest_chunk_size_ = t;
237  TR.Debug << "Created a new chunk for : " << current_section->get_pdb_id()
238  << " having " << current_section->size() << " residues "
239  << " at index " << size() << ". The largest chunk's size is: "
240  <<largest_chunk_size_<<std::endl;
241  current_section = new VallChunk(this);
242  prior_id = current_residue->id();
243  }
244  prior_resi = current_residue->resi();
245  current_section->push_back(current_residue);
246 // if (n_lines % 100000 == 0) {
247 // TR.Info << " " << n_lines << std::endl;
248 // TR.flush();
249 // }
250 
251  } // line loop
252 
253  push_back(current_section);
254  TR.Debug << "Created a new chunk for : " << current_section->get_pdb_id()
255  << " having " << current_section->size() << " residues "
256  << " at index " << size() << std::endl;
257  Size t = current_section->size();
258  if (t > largest_chunk_size_) largest_chunk_size_ = t;
259 
260  time_t time_end = time(NULL);
261 
262  TR.Info << "... done. Read " << n_lines << " lines. Time elapsed: "
263  << (time_end - time_start) << " seconds." << std::endl;
264 
265  TR.Info << "Total chunks: " << size() << std::endl;
266  TR.Info << "Largest chunk: " << largest_chunk_size_ << " aa" << std::endl;
267 
268  // create cached pose
269  for (Size i = 1; i <= largest_chunk_size_; i++) poly_A_seq_ += "A";
270  cached_pose_ = new core::pose::Pose();
271  core::pose::make_pose_from_sequence(*cached_pose_, poly_A_seq_,
272  *(chemical::ChemicalManager::get_instance()->residue_type_set("fa_standard")));
273  TR.flush();
274  return n_lines;
275 }
276 
277 } // frag_picker
278 } // protocols