Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PartialSecondarySimilarity.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/PartialSecondarySimilarity.cc
11 /// @brief scores a fragment by secondary structure similarity
12 /// but throws out the worst 20% of the residue matches
13 /// @author Robert Vernon (rvernon@u.washington.edu)
14 
16 
17 // type headers
18 #include <core/types.hh>
19 
20 // package headers
24 // AUTO-REMOVED #include <protocols/frag_picker/scores/fragment_scoring_utilities.hh>
25 
27 
28 // AUTO-REMOVED #include <basic/prof.hh>
29 
30 // project headers
31 #include <basic/Tracer.hh>
32 
33 #include <utility/vector1.hh>
34 
35 
36 namespace protocols {
37 namespace frag_picker {
38 namespace scores {
39 
40 static basic::Tracer trPartialSecondarySimilarity(
41  "protocols.frag_picker.scores.PartialSecondarySimilarity");
42 
44 
45  std::string & tmp = chunk->chunk_key();
46  if (tmp.compare(cached_scores_id_) == 0)
47  return;
48  cached_scores_id_ = tmp;
49 
50  //assert(query_ss_);
51  utility::vector1<Size> chunk_ss_id( chunk->size() );
52  for (Size j = 1; j <= chunk->size(); ++j) {
53  char s(chunk->at(j)->ss());
54  if (s == 'H') chunk_ss_id[j] = 1;
55  if (s == 'E') chunk_ss_id[j] = 2;
56  if (s == 'L') chunk_ss_id[j] = 3;
57  }
58 
59  for (Size i = 1; i <= query_len_; ++i) {
60  for (Size j = 1; j <= chunk->size(); ++j) {
61  scores_[i][j] = raw_probs_[i][chunk_ss_id[j]];
62  }
63  }
64  trPartialSecondarySimilarity.Debug << "precomputed matrix of scores " << scores_.size()
65  << "x" << chunk->size() << std::endl;
66 }
67 
69 
71  values.resize(f->get_length());
72 
73  for (Size i = 1; i <= f->get_length(); i++) {
74  values[i] = 0.0;
75  VallChunkOP chunk = f->get_chunk();
76 
77  char s(chunk->at(f->get_first_index_in_vall() + i - 1)->ss());
78  if (s == 'H') {
79  values[i] = raw_probs_[f->get_first_index_in_query() + i - 1][1];
80  } else {
81  if (s == 'E') {
82  values[i] = raw_probs_[f->get_first_index_in_query() + i - 1][2];
83  } else {
84  if (s == 'L')
85  values[i] = raw_probs_[f->get_first_index_in_query() + i - 1][3];
86  }
87  }
88  }
89 
90  std::sort( values.begin(), values.end() );
91  Real totalScore = 0.0;
92 
93  for (Size i = 1; i <= f->get_length(); i++) {
94  //~1 at 1, ~0.05 at f->get_length, 0.5 at 0.7*f->get_length()
95  Real sigmoid_weight( 1 / ( 1 + exp( (10*( (Real) i ) / f->get_length()) - 7 ) ) );
96 
97  totalScore += sigmoid_weight*values[i];
98  }
99 
100  totalScore /= (Real) f->get_length();
101 
102  // Real best80 = ( static_cast< Real > ( f->get_length() ) ) * 0.8;
103 // Size best80i = static_cast< Size > ( best80 );
104 
105 // Real totalScore = 0.0;
106 // for (Size i = 1; i<= best80i; i++) {
107 // totalScore += values[i];
108 // }
109 // totalScore /= (Real) best80i;
110 
111  empty_map->set_score_component(totalScore, id_);
112  if ((totalScore > lowest_acceptable_value_) && (use_lowest_ == true))
113  return false;
114  return true;
115 }
116 
117 
119  FragmentScoreMapOP empty_map) {
120 
121  //REMOVED CACHING FOR NOW!
122  score(f, empty_map);
123 
124  return true;
125  // std::string & tmp = f->get_chunk()->chunk_key();
126 // if (tmp.compare(cached_scores_id_) != 0) {
127 // do_caching(f->get_chunk());
128 // }
129 
130 // Real totalScore = cache_[f->get_length()][f->get_first_index_in_query()][f->get_first_index_in_vall()];
131 
132 // totalScore /= (Real) f->get_length();
133 
134 // empty_map->set_score_component(totalScore, id_);
135 // if ((totalScore > lowest_acceptable_value_) && (use_lowest_ == true))
136 // return false;
137 // return true;
138 }
139 
140 PartialSecondarySimilarity::PartialSecondarySimilarity(Size priority, Real lowest_acceptable_value, bool use_lowest,
141  core::fragment::SecondaryStructureOP query_prediction, std::string prediction_name,
142  Size sequence_length, Size longest_vall_chunk) :
143  CachingScoringMethod(priority, lowest_acceptable_value, use_lowest,
144  "PartialSecondarySimilarity") , prediction_name_(prediction_name) {
145  query_len_ = sequence_length;
146  //query_ss_ = query_prediction;
147 
148  //Normalize Secondary Structure Scores
149  // so: 0.5 H 0.5 E 0.0 L ---> 1.0 H 1.0 E 0.0 L
150  norm_query_H_.resize(query_len_);
151  norm_query_E_.resize(query_len_);
152  norm_query_L_.resize(query_len_);
153  for (Size i = 1; i <= query_len_; ++i) {
154  Real highest_ss_pred(query_prediction->helix_fraction(i));
155 
156  if (highest_ss_pred < query_prediction->strand_fraction(i)) {
157  highest_ss_pred = query_prediction->strand_fraction(i);
158  }
159  if (highest_ss_pred < query_prediction->loop_fraction(i)) {
160  highest_ss_pred = query_prediction->loop_fraction(i);
161  }
162 
163  norm_query_H_[i] = query_prediction->helix_fraction(i) / highest_ss_pred;
164  norm_query_E_[i] = query_prediction->strand_fraction(i) / highest_ss_pred;
165  norm_query_L_[i] = query_prediction->loop_fraction(i) / highest_ss_pred;
166  }
167 
168 
169  //scores_ vector = query_size x vall_size for per residue scores
170  //prow vector = query_size x 3, used to store 1->0 scores for the 0->1 probabilities
171  for (Size i = 1; i <= query_len_; ++i) {
172  utility::vector1<Real> row(longest_vall_chunk);
173  scores_.push_back(row);
174  utility::vector1<Real> prow(3);
175  prow[1] = 1 - norm_query_H_[i];
176  prow[2] = 1 - norm_query_E_[i];
177  prow[3] = 1 - norm_query_L_[i];
178  raw_probs_.push_back(prow);
179  }
180 
181 }
182 
183 } // scores
184 } // frag_picker
185 } // protocols
186 
187