Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TalosSSSimilarity.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 && 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/scores/TalosSSSimilarity.cc
11 /// @brief scores a fragment by secondary structure similarity
12 /// @author rvernon@u.washington.edu
13 
15 
16 // type headers
17 #include <core/types.hh>
18 
19 // package headers
24 
26 
27 // AUTO-REMOVED #include <basic/prof.hh>
28 
29 // option key includes
30 // AUTO-REMOVED #include <core/init.hh>
31 #include <basic/options/option.hh>
32 #include <basic/options/keys/OptionKeys.hh>
33 #include <basic/options/keys/frags.OptionKeys.gen.hh>
34 
35 // project headers
36 #include <basic/Tracer.hh>
37 
38 #include <utility/vector1.hh>
39 
40 
41 namespace protocols {
42 namespace frag_picker {
43 namespace scores {
44 
45 using namespace basic::options;
46 using namespace basic::options::OptionKeys;
47 
48 static basic::Tracer trTalosSSSimilarity(
49  "protocols.frag_picker.scores.TalosSSSimilarity");
50 
52 
54  values.resize(f->get_length());
55 
56  Real totalScore = 0.0;
57  for (Size i = 1; i <= f->get_length(); i++) {
58  //mjo commenting out 'ss_weight' because it is unused and causes a warning
59  //Real ss_weight(0.0);
60  VallChunkOP chunk = f->get_chunk();
61 
62  char s(chunk->at(f->get_first_index_in_vall() + i - 1)->ss());
63  Size ss_id(3);
64  if (s == 'H') ss_id = 1;
65  if (s == 'E') ss_id = 2;
66  if (s == 'L') ss_id = 3;
67 
68  values[i] = raw_probs_[f->get_first_index_in_query()+i-1][ss_id];
69 
70  //totalScore += ss_weight;
71  }
72 
73  //H
74  std::sort( values.begin(), values.end() );
75  totalScore = 0.0;
76  for (Size i = 1; i <= f->get_length(); i++) {
77  //~1 at 1, ~0.05 at f->get_length, 0.5 at 0.7*f->get_length()
78  Real sigmoid_weight( 1 / ( 1 + exp( (10*( (Real) i ) / f->get_length()) - 7 ) ) );
79  totalScore += sigmoid_weight*values[i];
80  }//H
81 
82 
83  totalScore /= (Real) f->get_length();
84  empty_map->set_score_component(totalScore, id_);
85  if ((totalScore > lowest_acceptable_value_) && (use_lowest_ == true))
86  return false;
87  return true;
88 }
89 
90 
92 
93  std::string & tmp = chunk->chunk_key();
94  if (tmp.compare(cached_scores_id_) == 0)
95  return;
96  cached_scores_id_ = tmp;
97 
98  do_caching_simple(chunk);
99  for(Size fl=1;fl<=cache_.size();fl++) {
100  if(cache_[fl].size() != 0) {
101  trTalosSSSimilarity.Trace << "caching secondary score for " << chunk->get_pdb_id()
102  << " of size " << chunk->size() << " for fragment size "<<fl<<std::endl;
103  rolling_score(scores_,fl,cache_[fl]);
104  }
105  }
106 }
107 
109 
110  assert(query_ss_);
111  utility::vector1<Size> chunk_ss_id( chunk->size() );
112  for (Size j = 1; j <= chunk->size(); ++j) {
113  char s(chunk->at(j)->ss());
114  if (s == 'H') chunk_ss_id[j] = 1;
115  if (s == 'E') chunk_ss_id[j] = 2;
116  if (s == 'L') chunk_ss_id[j] = 3;
117  }
118 
119  for (Size i = 1; i <= query_len_; ++i) {
120  for (Size j = 1; j <= chunk->size(); ++j) {
121  scores_[i][j] = raw_probs_[i][chunk_ss_id[j]];
122  }
123  }
124  trTalosSSSimilarity.Debug << "precomputed matrix of scores " << scores_.size()
125  << "x" << chunk->size() << std::endl;
126 }
127 
128 
130  FragmentScoreMapOP empty_map) {
131 
132  //return score(f, empty_map);
133 
134  /*
135  std::string & tmp = f->get_chunk()->chunk_key();
136  if (tmp.compare(cached_scores_id_) != 0)
137  do_caching(f->get_chunk());
138  */
139 
140 
141  Real totalScore = cache_[f->get_length()][f->get_first_index_in_query()][f->get_first_index_in_vall()];
142 
143  totalScore /= (Real) f->get_length();
144 
145  empty_map->set_score_component(totalScore, id_);
146  if ((totalScore > lowest_acceptable_value_) && (use_lowest_ == true))
147  return false;
148  return true;
149 }
150 
151 TalosSSSimilarity::TalosSSSimilarity(Size priority, Real lowest_acceptable_value, bool use_lowest,
152  core::fragment::SecondaryStructureOP query_prediction, std::string prediction_name,
153  Size sequence_length, utility::vector1<Size> & frag_sizes, Size longest_vall_chunk) :
154  CachingScoringMethod(priority, lowest_acceptable_value, use_lowest,
155  "TalosSSSimilarity") , prediction_name_(prediction_name) {
156  query_len_ = sequence_length;
157  query_ss_ = query_prediction;
158 
159  H_mult_ = option[frags::seqsim_H](); // Default is 1.0
160  E_mult_ = option[frags::seqsim_E](); // Default is 1.0
161  L_mult_ = option[frags::seqsim_L](); // Default is 1.0
162 
163  for (Size i = 1; i <= query_len_; ++i) {
164  utility::vector1<Real> row(longest_vall_chunk);
165  scores_.push_back(row);
166  utility::vector1<Real> prow(3);
167  //prow[1] = 1 - H_mult_*query_prediction->helix_fraction(i);
168  //prow[2] = 1 - E_mult_*query_prediction->strand_fraction(i);
169  //prow[3] = 1 - L_mult_*query_prediction->loop_fraction(i);
170 
171  Real hf;
172  Real sf;
173  Real lf;
174  Real confidence;
175  if ( i<=query_prediction->total_residue() ) {
176  hf = query_prediction->helix_fraction(i);
177  sf = query_prediction->strand_fraction(i);
178  lf = query_prediction->loop_fraction(i);
179  confidence = query_prediction->confidence(i);
180  } else {
181  hf = sf = lf = 1.0/3.0;
182  confidence = 0.0;
183  }
184 
185  Real average( (hf+sf+lf)/ 3.0 );
186  Real sdev( sqrt( (pow(hf-average,2) + pow(sf-average,2) + pow(lf-average,2))/3.0 ) );
187 
188  // Real highest_ss_pred(query_prediction->helix_fraction(i));
189 
190 // if (highest_ss_pred < query_prediction->strand_fraction(i)) {
191 // highest_ss_pred = query_prediction->strand_fraction(i);
192 // }
193 // if (highest_ss_pred < query_prediction->loop_fraction(i)) {
194 // highest_ss_pred = query_prediction->loop_fraction(i);
195 // }
196 
197 // if ( highest_ss_pred > 0 ) {
198 // hf = hf / highest_ss_pred;
199 // sf = sf / highest_ss_pred;
200 // }
201 
202  if ( ( sdev <= 0.1 ) || (confidence <= 0.1) ) {
203  prow[1] = 0.0;//-3*( 1 / ( 1 + exp(-5*hf + 5) ) );
204  prow[2] = 0.0;//-3*( 1 / ( 1 + exp(-5*sf + 5) ) );
205  prow[3] = 0.0;// - query_prediction->loop_fraction(i);
206  } else {
207  //prow[1] = -3*( 1 / ( 1 + exp(-5*hf + 5) ) )*confidence;
208  //prow[2] = -3*( 1 / ( 1 + exp(-5*sf + 5) ) )*confidence;
209  //prow[3] = 0.0;// - query_prediction->loop_fraction(i);
210 
211  prow[1] = (-2*( 1 / ( 1 + exp(-7*hf + 5) ) ))*sqrt(confidence);
212  prow[2] = (-2*( 1 / ( 1 + exp(-7*sf + 5) ) ))*sqrt(confidence);
213  prow[3] = (-2*( 1 / ( 1 + exp(-7*lf + 5) ) ))*sqrt(confidence);
214 
215 
216  //prow[1] =
217  //prow[2] =
218  //prow[3] = 0.0;// - query_prediction->loop_fraction(i);
219  }
220 
221  //sep_2fx20.6_px_m2
222  //+2 when prediction is 0.0 (SS Penalty)
223  //-2 when prediction is 1.0
224  // 0 when prediction is 0.33
225  //prow[1] = -(2 * ( (1 / ( 1 + exp((-20*hf + 6)))) + hf) - 2);
226  //prow[2] = -(2 * ( (1 / ( 1 + exp((-20*sf + 6)))) + sf) - 2);
227  //prow[3] = 0.0;// - query_prediction->loop_fraction(i);
228 
229 
230  //BEST SO FAR!
231  //prow[1] = -3*( 1 / ( 1 + exp(-5*hf + 5) ) );
232  // prow[2] = -3*( 1 / ( 1 + exp(-5*sf + 5) ) );
233  //prow[3] = 0.0;// - query_prediction->loop_fraction(i);
234 
235 
236  //sep_2fx20.6_px_m2
237  //+2 when prediction is 0.0 (SS Penalty)
238  //-2 when prediction is 1.0
239  // 0 when prediction is 0.33
240  //prow[1] = -1*( (1 / ( 1 + exp((-25*hf + 5)))) + (1 / ( 1 + exp((-12.5*hf + 9)))) - 1);
241  //prow[2] = -1*( (1 / ( 1 + exp((-25*sf + 5)))) + (1 / ( 1 + exp((-12.5*sf + 9)))) - 1);
242  //prow[3] = 0.0;// - query_prediction->loop_fraction(i);
243 
244 
245  //if (prow[1] < 0.0) {
246  // prow[1] = 0.0;
247  //}
248  //if (prow[2] < 0.0) {
249  // prow[2] = 0.0;
250  //}
251  raw_probs_.push_back(prow);
252  }
253 
254  create_cache(frag_sizes,query_len_,longest_vall_chunk,cache_);
255 }
256 
257 } // scores
258 } // frag_picker
259 } // protocols
260 
261