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