Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ProfileScoreL1.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/ProfileScore.cc
11 /// @brief scores a fragment by an amino acid sequence identity
12 /// @author Dominik Gront (dgront@chem.uw.edu.pl)
13 
14 
15 // type headers
16 #include <core/types.hh>
17 
19 
20 // package headers
25 
26 // mini headers
28 
29 // option key includes
30 #include <basic/options/keys/OptionKeys.hh>
31 
32 // utils
33 // AUTO-REMOVED #include <basic/prof.hh>
34 #include <basic/Tracer.hh>
35 
36 #include <utility/vector1.hh>
37 
38 
39 namespace protocols {
40 namespace frag_picker {
41 namespace scores {
42 
43 using namespace basic::options;
44 using namespace basic::options::OptionKeys;
45 
46 static basic::Tracer trProfScoreL1(
47  "protocols.frag_picker.scores.ProfileScoreL1");
48 
50 
51 ProfileScoreL1::ProfileScoreL1(Size priority, Real lowest_acceptable_value, bool use_lowest,
52  sequence::SequenceProfileOP query_profile, utility::vector1<Size> & frag_sizes,
53  Size longest_vall_chunk) :
54  CachingScoringMethod(priority, lowest_acceptable_value, use_lowest,
55  "ProfileScoreL1") {
56  query_profile_ = query_profile;
57 
58  for (Size i = 1; i <= query_profile->length(); ++i) {
59  utility::vector1<Real> row(longest_vall_chunk);
60  scores_.push_back(row);
61  }
62  create_cache(frag_sizes,query_profile->length(),longest_vall_chunk,cache_);
63  if(trProfScoreL1.visible()) {
64  trProfScoreL1 << "Created cache for fraglen:";
65  for(Size i=1;i<=cache_.size();i++)
66  if(cache_[i].size() > 0)
67  trProfScoreL1 <<" "<<i;
68  trProfScoreL1<<std::endl;
69  }
70 }
71 
72 
74 
75  std::string & tmp = chunk->chunk_key();
76  if (tmp.compare(cached_scores_id_) == 0)
77  return;
78  cached_scores_id_ = tmp;
79 
80  do_caching_simple(chunk);
81  for(Size fl=1;fl<=cache_.size();fl++) {
82  if(cache_[fl].size() != 0) {
83  trProfScoreL1.Trace << "caching profile score for " << chunk->get_pdb_id()
84  << " of size " << chunk->size() << " for fragment size "<<fl<<std::endl;
86  }
87  }
88 }
89 
90 
92 
93  Size size_q = query_profile_->length();
94 
95  trProfScoreL1.Debug << "caching profile score for " << chunk->get_pdb_id()
96  << " of size " << chunk->size() << std::endl;
97  for (Size i = 1; i <= size_q; ++i) {
98  utility::vector1<Real> query_prof_row = query_profile_->prof_row(i);
99  for (Size j = 1; j <= chunk->size(); ++j) {
100  utility::vector1<Real> tmplt_prof_row = chunk->at(j)->profile();
101  Real score = 0.0;
102  for (Size k = 1; k <= 20; k++){
103  score += std::abs(tmplt_prof_row[k] - query_prof_row[k]);
104  }
105  scores_[i][j] = score;
106  }
107  }
108 
109  trProfScoreL1.Debug << "precomputed matrix of L1 scores " << scores_.size()
110  << "x" << chunk->size() << std::endl;
111 }
112 
114  FragmentScoreMapOP empty_map) {
115 
116  std::string tmp = f->get_chunk()->chunk_key();
117  if (tmp.compare(cached_scores_id_) != 0)
118  do_caching(f->get_chunk());
119 
120  Real totalScore = cache_[f->get_length()][f->get_first_index_in_query()][f->get_first_index_in_vall()];
121 
122  totalScore /= (Real) f->get_length();
123 
124  empty_map->set_score_component(totalScore, id_);
125  if ((totalScore > lowest_acceptable_value_) && (use_lowest_ == true))
126  return false;
127  return true;
128 }
129 
131 
132  Real totalScore = 0.0;
133  for (Size i = 1; i <= f->get_length(); i++) {
134  utility::vector1<Real> query_prof_row = query_profile_->prof_row(f->get_first_index_in_query() + i - 1);
135  VallChunkOP chunk = f->get_chunk();
136  utility::vector1<Real> tmplt_prof_row = chunk->at(f->get_first_index_in_vall() + i - 1)->profile();
137  for (Size k = 1; k <= 20; k++){
138  totalScore += std::abs(tmplt_prof_row[k] - query_prof_row[k]);
139  }
140  }
141  totalScore /= (Real) f->get_length();
142  empty_map->set_score_component(totalScore, id_);
143  if ((totalScore > lowest_acceptable_value_) && (use_lowest_ == true))
144  return false;
145  return true;
146 }
147 
148 
150  Real lowest_acceptable_value, bool use_lowest, FragmentPickerOP picker, std::string) {
151 
152  Size len = picker->get_vall()->get_largest_chunk_size();
153  trProfScoreL1 << "Profile scoring method is: L1" << std::endl;
154  return (FragmentScoringMethodOP) new ProfileScoreL1(priority,
155  lowest_acceptable_value, use_lowest, picker->get_query_seq(),
156  picker->frag_sizes_,len);
157 }
158 
159 } //scores
160 } // frag_picker
161 } // protocols
162 
163 /*
164 bool ProfileScoreL1::cached_score(FragmentCandidateOP f, FragmentScoreMapOP empty_map) {
165 
166  std::string tmp = f->get_chunk()->chunk_key();
167  if (tmp.compare(cached_scores_id_) != 0)
168  do_caching(f->get_chunk());
169 
170  Real totalScore = 0.0;
171  for (Size i = 1; i <= f->get_length(); i++) {
172  assert(f->get_first_index_in_query() + i - 1 <= scores_.size());
173  assert(f->get_first_index_in_vall()
174  + i - 1<= scores_[1].size());
175  totalScore
176  += scores_[f->get_first_index_in_query() + i - 1][f->get_first_index_in_vall()
177  + i - 1];
178  }
179  totalScore /= (Real) f->get_length();
180  empty_map->set_score_component(totalScore, id_);
181  if ((totalScore > lowest_acceptable_value_) && (use_lowest_ == true))
182  return false;
183  return true;
184 }
185 */