Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ProfileScoreBlosum62.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
29 #include <core/chemical/AA.hh>
30 
31 #include <utility/file/FileName.hh>
32 
33 // option key includes
34 #include <basic/options/keys/OptionKeys.hh>
35 
36 // utils
37 #include <basic/prof.hh>
38 #include <basic/Tracer.hh>
39 
40 #include <utility/vector1.hh>
41 
42 
43 namespace protocols {
44 namespace frag_picker {
45 namespace scores {
46 
47 using namespace basic::options;
48 using namespace basic::options::OptionKeys;
49  using namespace core::chemical;
50 
51 static basic::Tracer trProfScoreBlosum62(
52  "protocols.frag_picker.scores.ProfileScoreBlosum62");
53 
55 
56 ProfileScoreBlosum62::ProfileScoreBlosum62(Size priority, Real lowest_acceptable_value, bool use_lowest,
57  sequence::SequenceProfileOP query_profile, Size longest_vall_chunk) :
58  CachingScoringMethod(priority, lowest_acceptable_value, use_lowest,
59  "ProfileScoreBlosum62")
60 {
61  query_profile_ = query_profile;
62 
63  for (Size i = 1; i <= query_profile->length(); ++i) {
64  utility::vector1<Real> row(longest_vall_chunk);
65  scores_.push_back(row);
66  }
67 
68  sequence::MatrixScoringScheme blosum_reader;
69 
70  utility::file::FileName const fn("/work/rvernon/yangshen/adjust_tables/BLOSUM62");
71 
72  blosum_reader.read_from_file(fn);
73 
74  blosum_matrix_ = blosum_reader.scoring_matrix();
75 
76 }
77 
78 
80 
81  std::string & tmp = chunk->chunk_key();
82  if (tmp.compare(cached_scores_id_) == 0)
83  return;
84  cached_scores_id_ = tmp;
85  Size size_q = query_profile_->length();
86 
87  trProfScoreBlosum62.Debug << "caching profile score for " << chunk->get_pdb_id()
88  << " of size " << chunk->size() << std::endl;
89  PROF_START( basic::FRAGMENTPICKING_PROFILE_CAHING );
90  for (Size i = 1; i <= size_q; ++i) {
91  utility::vector1<Real> query_prof_row = query_profile_->prof_row(i);
92 
93  for (Size j = 1; j <= chunk->size(); ++j) {
94 
95  //AA aa = aa_from_oneletter_code( chunk->at(j)->aa() );
96 
97  utility::vector1<Real> tmplt_prof_row = chunk->at(j)->profile();
98  Real score = 0.0;
99  for (Size k1 = 1; k1 <= 20; k1++) {
100  //score -= query_prof_row[k]*blosum_matrix_[k][aa];//*tmplt_prof_row[k];
101  for (Size k2 = 1; k2 <= 20; k2++) {
102 
103  Real diff = query_prof_row[k1]*sqrt(tmplt_prof_row[k2]);
104 
105  Real sign(0.0);
106 
107  if ( blosum_matrix_[k1][k2] < 0 ) {
108  sign = -1.0;
109  } else {
110  sign = 1.0;
111  }
112 
113  Real blosum( pow(abs(blosum_matrix_[k1][k2]), 1/4) );
114 
115  score -= sign/(1+exp((-10*diff*blosum)+5));
116 
117  //score -= query_prof_row[k1]*tmplt_prof_row[k2]*blosum_matrix_[k1][k2];//*tmplt_prof_row[k];;
118  }
119  }
120  scores_[i][j] = score;
121  }
122 
123 
124  //for (Size j = 1; j <= chunk->size(); ++j) {
125  // utility::vector1<Real> tmplt_prof_row = chunk->at(j)->profile();
126  // Real score = 0.0;
127  // for (Size k = 1; k <= 20; k++){
128  // score += std::abs(tmplt_prof_row[k] - query_prof_row[k]);
129  // }
130  // scores_[i][j] = score;
131  //}
132  }
133 
134  PROF_STOP( basic::FRAGMENTPICKING_PROFILE_CAHING );
135  trProfScoreBlosum62.Debug << "precomputed matrix of scores " << scores_.size()
136  << "x" << chunk->size() << std::endl;
137 }
138 
140 
141  std::string & tmp = f->get_chunk()->chunk_key();
142 
143  if (tmp.compare(cached_scores_id_) != 0)
144  do_caching(f->get_chunk());
145 
146  Real totalScore = 0.0;
147  for (Size i = 1; i <= f->get_length(); i++) {
148  assert(f->get_first_index_in_query() + i - 1 <= scores_.size());
149  assert(f->get_first_index_in_vall()
150  + i - 1<= scores_[1].size());
151  totalScore
152  += scores_[f->get_first_index_in_query() + i - 1][f->get_first_index_in_vall()
153  + i - 1];
154  }
155  totalScore /= (Real) f->get_length();
156  empty_map->set_score_component(totalScore, id_);
157 
158  if ((totalScore > lowest_acceptable_value_) && (use_lowest_ == true))
159  return false;
160  return true;
161 }
162 
164 
165  return cached_score( f, empty_map);
166 
167 // PROF_START( basic::FRAGMENTPICKING_PROFILE_SCORE );
168 
169 // Real totalScore = 0.0;
170 // for (Size i = 1; i <= f->get_length(); i++) {
171 // utility::vector1<Real> query_prof_row = query_profile_->prof_row(f->get_first_index_in_query() + i - 1);
172 // VallChunkOP chunk = f->get_chunk();
173 // utility::vector1<Real> tmplt_prof_row = chunk->at(f->get_first_index_in_vall() + i - 1)->profile();
174 // for (Size k = 1; k <= 20; k++){
175 // totalScore += std::abs(tmplt_prof_row[k] - query_prof_row[k]);
176 // }
177 // }
178 // totalScore /= (Real) f->get_length();
179 // empty_map->set_score_component(totalScore, id_);
180 // PROF_STOP( basic::FRAGMENTPICKING_PROFILE_SCORE );
181 // if ((totalScore > lowest_acceptable_value_) && (use_lowest_ == true))
182 // return false;
183 // return true;
184 }
185 
186 
188  Real lowest_acceptable_value, bool use_lowest, FragmentPickerOP picker, std::string) {
189 
190  Size len = picker->get_vall()->get_largest_chunk_size();
191  trProfScoreBlosum62 << "Profile scoring method is: Blosum62" << std::endl;
192  return (FragmentScoringMethodOP) new ProfileScoreBlosum62(priority,
193  lowest_acceptable_value, use_lowest, picker->get_query_seq(), len);
194 }
195 
196 } //scores
197 } // frag_picker
198 } // protocols