Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SS_Killhairpins_Info.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 core/scoring/SS_Killhairpins_Info.hh
11 /// @brief Scoring manager class header
12 /// @author Robert Vernon (rvernon@u.washington.edu)
13 
14 
15 /// Unit headers
17 
18 /// Package headers
19 // AUTO-REMOVED #include <core/conformation/Residue.hh>
20 // AUTO-REMOVED #include <core/pose/Pose.hh>
21 
22 #include <ObjexxFCL/format.hh>
23 
24 // Numeric Headers
25 // AUTO-REMOVED #include <numeric/random/random.hh>
26 
27 // utility headers
28 #include <basic/Tracer.hh>
29 #include <utility/io/izstream.hh>
30 #include <utility/string_util.hh>
31 #include <string>
32 #include <utility/exit.hh>
33 
34 // option key includes
35 #include <basic/options/option.hh>
36 #include <basic/options/keys/abinitio.OptionKeys.gen.hh>
37 #include <basic/options/keys/OptionKeys.hh>
38 
39 
40 /// C++ Headers
41 #include <iostream>
42 
43 #include <utility/vector1.hh>
44 
45 //Auto Headers
46 #include <numeric/random/random.fwd.hh>
47 
48 namespace core {
49 namespace scoring {
50 
51 static basic::Tracer trKillHairpinsIO("core.score.SS_Killhairpins_Info");
52 
53 //////////////////////////////////////////////////////////////////////////////////////////////////////
54 
55 /// @brief default constructor
57 {}
58 
60 {
61  range_pair_ = std::make_pair( std::make_pair( s1_1, s1_2 ), std::make_pair( s2_1, s2_2 ) );
62 }
63 
65 {}
66 
68 Hairpin::s1_start() const { return range_pair_.first.first; }
69 
71 Hairpin::s1_end() const { return range_pair_.first.second; }
72 
74 Hairpin::s2_start() const { return range_pair_.second.first; }
75 
77 Hairpin::s2_end() const { return range_pair_.second.second; }
78 
79 /// @brief copy assignment
80 Hairpin const &
82 {
83  if ( this != &s ) {
85  }
86  return *this;
87 }
88 
89 
90 std::ostream &
91 operator<< ( std::ostream & out, Hairpin const & s )
92 {
93  using ObjexxFCL::fmt::I;
94  out << "Hairpin - Strand1: " << I(5,s.s1_start()) << "-" << I(5,s.s1_end()) << " Strand2: "
95  << I(5,s.s2_start()) << "-" << I(5,s.s2_end()) << "\n";
96  return out;
97 }
98 
99 
100 
101 /// @brief default constructor
103 {}
104 
105 /// @brief copy constructor
107  Hairpins const & s
108  ) : hairpin_list_( s.hairpin_list_ )
109 {}
110 
111 /// @brief default destructor
113 {}
114 
115 /// @brief copy assignment
116 Hairpins const &
118 {
119  if ( this != &s ) {
121  }
122  return *this;
123 }
124 
125 void
127 {
128  Hairpin new_hairpin(s1_1, s1_2, s2_1, s2_2);
129 
130  hairpin_list_.push_back(new_hairpin);
131 }
132 
133 void
135 {
136  hairpin_list_.clear();
137 }
138 
141 {
142  return hairpin_list_;
143 }
144 
147 {
148  return hairpin_list_.size();
149 }
150 
151 std::ostream &
152 operator<< ( std::ostream & out, Hairpins const & s )
153 {
154  using ObjexxFCL::fmt::I;
155 
156  utility::vector1< Hairpin > temp_list( s.list() );
157  core::Size count(0);
158 
159  for ( utility::vector1< Hairpin >::iterator it= temp_list.begin(),
160  ite= temp_list.end(); it != ite; ++it ) {
161  count++;
162  }
163  return out;
164 }
165 
167  CacheableData(),
168  kill_parallel_( false ),
169  kill_antiparallel_( true )
170 {}
171 
172 
174  CacheableData(),
175  kill_parallel_( src.kill_parallel_ ),
176  kill_antiparallel_( src.kill_antiparallel_ ),
177  hairpins_ ( src.hairpins_ )
178 {}
179 
180 bool
181 SS_Killhairpins_Info::check_hairpin( core::Size const & strand1_res, core::Size const & strand2_res )
182 {
183  for ( core::Size i = 1; i <= hairpins_.list().size(); ++i) {
184  if ( (strand1_res >= hairpins_.list()[i].s1_start()) && (strand1_res <= hairpins_.list()[i].s1_end())
185  && (strand2_res >= hairpins_.list()[i].s2_start()) && (strand2_res <= hairpins_.list()[i].s2_end()) ) {
186  return true;
187  }
188  }
189  return false;
190 }
191 
192 void
193 SS_Killhairpins_Info::setup_from_psipred(utility::io::izstream & input_file)
194 {
195  utility::vector1< Hairpin > all_hairpins;
196 
197  std::string line;
198 
199  utility::vector1< core::Real > strand_prob;
202 
203  while (!input_file.eof()) {
204  getline(input_file, line);
205  if (line.length() > 5) {
206  std::istringstream line_stream(line);
207 
208  char aa, ss;
209  core::Real E_freq, L_freq, H_freq;
210  core::Size res;
211 
212  line_stream >> res >> aa >> ss >> L_freq >> H_freq >> E_freq;
213 
214  strand_prob.push_back(E_freq);
215  helix_prob.push_back(H_freq);
216  loop_prob.push_back(L_freq);
217 
218  if ((strand_prob.size() != res) || (strand_prob.size() != helix_prob.size())
219  || (loop_prob.size() != helix_prob.size())) {
220  utility_exit_with_message("[ERROR] -kill_hairpins can't parse psipred_ss2 file");
221  }
222  }
223  }
224 
225  ///////////////////
226  // The following picks out potential hairpins from the psipred_ss2 file
227  // Rules:
228  // -Strands start when the E_pred jumps above 0.5, and end when it drops below 0.5
229  // -Strands must be at least 3 residues long
230  // -Adjacent strands are considered hairpin candidates if the H_pred values between
231  // them sum up to less than 3.0 (eg: < 3 100% helix residues or < 6 50% helix)
232  //
233  // Also, this nest of if statements made sense at the time.
234  // -rmv
235  ///////////////////
236 
237  core::Real helix_prob_sum(0.0);
238  bool has_helix(false), on_strand(false), has_strand(false);
239  std::pair< core::Size, core::Size > working_strand;
240  std::pair< core::Size, core::Size > last_strand;
241  for (core::Size i=1; i <= strand_prob.size(); ++i) {
242 
243  if (!on_strand) {
244 
245  if ( i <= strand_prob.size() - 2 ) {
246 
247  if (( strand_prob[i] >= 0.5 ) &&
248  ( strand_prob[i+1] >= 0.5 ) &&
249  ( strand_prob[i+2] >= 0.5) ){
250 
251  on_strand = true;
252 
253  working_strand.first = i;
254 
255  if( kill_parallel_ ) {
256  has_strand = true;
257  } else {
258  if ( !has_helix ) {
259  has_strand = true;
260  } else {
261  has_strand = false;
262  }
263  }
264 
265  has_helix = false;
266  helix_prob_sum = 0.0;
267 
268  } else {
269 
270  helix_prob_sum += helix_prob[i];
271 
272  if ( helix_prob_sum >= 3.0 ) {
273  has_helix = true;
274  }
275  }
276  }
277  } else {
278 
279  if (( strand_prob[i] < 0.5 ) || ( i == strand_prob.size())) {
280  working_strand.second = i-1;
281 
282  if ( ( has_strand == true ) && ( last_strand.first != last_strand.second ) ) {
283  runtime_assert( last_strand != working_strand );
284 
285  runtime_assert( (last_strand.first<=last_strand.second)
286  && (last_strand.second<=working_strand.first)
287  && (working_strand.first<=working_strand.second));
288 
289  Hairpin new_hairpin( last_strand.first, last_strand.second,
290  working_strand.first, working_strand.second );
291  all_hairpins.push_back( new_hairpin );
292  }
293 
294  last_strand = working_strand;
295  working_strand.first = 0;
296  working_strand.second = 0;
297  on_strand = false;
298  has_strand = true;
299  }
300  }
301  }
302 
303  core::Real freq_limit( basic::options::option[ basic::options::OptionKeys::abinitio::kill_hairpins_frequency ] );
304 
305  for (core::Size i=1; i<= all_hairpins.size(); ++i) {
306 
307  core::Real freq_attempt(numeric::random::uniform());
308 
309  trKillHairpinsIO.Info << "KHP: Hairpin Detected in Psipred File: " << all_hairpins[i].s1_start() << "-" << all_hairpins[i].s1_end() << " " << all_hairpins[i].s2_start() << "-" << all_hairpins[i].s2_end();
310  if ( freq_attempt <= freq_limit ) {
311  hairpins_.append_hairpin(all_hairpins[i].s1_start(),
312  all_hairpins[i].s1_end(),
313  all_hairpins[i].s2_start(),
314  all_hairpins[i].s2_end());
315 
316  trKillHairpinsIO.Info << " KILLED!";
317  }
318  trKillHairpinsIO.Info << std::endl;
319  }
320 }
321 
322 void
323 SS_Killhairpins_Info::setup_from_kill_hairpins_file(utility::io::izstream & input_file)
324 {
325  std::string line;
326 
327  while (!input_file.eof()) {
328  getline(input_file, line);
329 
330  if (line.length() > 5) {
331  std::istringstream line_stream(line);
332 
333  core::Real frequency;
334  core::Size res1, res2, res3, res4;
335 
336  line_stream >> frequency >> res1 >> res2 >> res3 >> res4;
337 
338  runtime_assert((res1<=res2) && (res2<=res3) && (res3<=res4));
339 
340  core::Real freq_attempt(numeric::random::uniform());
341 
342  trKillHairpinsIO.Info << "KHP: Hairpin Read from Kill Hairpins File: " << res1 << "-" << res2 << " " << res3 << "-" << res4;
343 
344  if (freq_attempt <= frequency) {
345  hairpins_.append_hairpin( res1, res2, res3, res4 );
346  trKillHairpinsIO.Info << " KILLED!";
347  }
348  trKillHairpinsIO.Info << std::endl;
349  }
350  }
351 }
352 
353 void
355 {
356  hairpins_.clear();
357 
358  if ( basic::options::option[ basic::options::OptionKeys::abinitio::kill_hairpins ].user() ) {
359  utility::io::izstream input_file( basic::options::option[ basic::options::OptionKeys::abinitio::kill_hairpins ] );
360 
361  if (!input_file) {
362  utility_exit_with_message("[ERROR] Unable to open kill_hairpins file");
363  }
364 
365  std::string line, a(""), b("");
366  getline(input_file, line);
368  if ( tokens.size() == 4 ) {
369  a = tokens[ 3 ];
370  b = tokens[ 4 ];
371  } else if ( tokens.size() == 3 ) {
372  a = tokens[ 3 ];
373  } else if ( tokens.size() == 2 ) {
374  } else {
375  utility_exit_with_message("[ERROR] invalid header input for kill_hairpins file. ");
376  }
377 
378  if( a != "ANTI" && a != "PARA" && a != "" ) {
379  utility_exit_with_message("[ERROR] invalid kill type for kill_hairpins. ANTI or PARA, is required. ");
380  }
381  if( b != "ANTI" && b != "PARA" && b != "" ) {
382  utility_exit_with_message("[ERROR] invalid kill type for kill_hairpins. ANTI or PARA, is required. ");
383  }
384 
385  if ( a == "ANTI" || b == "ANTI" ) {
386  kill_antiparallel_ = true; // as default, kill_parallel_ is false
387  }
388  if ( a == "PARA" || b == "PARA" ) {
389  kill_parallel_ = true; // as default, kill_antiparallel_ is true
390  }
391 
392  std::string keyword = tokens[ 2 ];
393  if ( keyword == "PSIPRED" ) {
394  setup_from_psipred(input_file);
395  } else {
396  if ( keyword == "KILL" ) {
397  setup_from_kill_hairpins_file(input_file);
398  } else {
399  utility_exit_with_message("[ERROR] Unknown file type for kill_hairpins file (need psipred_ss2 or kill). File type is autodetected by file header; check your header.");
400  }
401  }
402  }
403 }
404 
405 
406 //////////////////////////////////////////////////////////////////////////////////////////////////////
407 
408 
409 } // ns scoring
410 } // ns core
411