Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ProfileScoreSubMatrix.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/ProfileScoreSubMatrix.cc
11 /// @brief scores a fragment by substitution matrix (e.g. Blosum62) profile score
12 /// @author Dan Kulp (dwkulp@gmail.com), based on code from Dominik Gront (dgront@chem.uw.edu.pl)
13 
14 
15 // type headers
16 #include <core/types.hh>
17 
19 
20 // package headers
25 
26 
27 // mini headers
30 #include <core/chemical/AA.hh>
31 
32 #include <utility/file/FileName.hh>
33 
34 // option key includes
35 #include <basic/options/keys/OptionKeys.hh>
36 
37 // utils
38 #include <basic/prof.hh>
39 #include <basic/Tracer.hh>
40 
41 #include <utility/vector1.hh>
42 
43 
44 namespace protocols {
45 namespace frag_picker {
46 namespace scores {
47 
48 using namespace basic::options;
49 using namespace basic::options::OptionKeys;
50 using namespace core::chemical;
51 
52 static basic::Tracer trProfScoreSubMatrix(
53  "protocols.frag_picker.scores.ProfileScoreSubMatrix");
54 
56 
57 ProfileScoreSubMatrix::ProfileScoreSubMatrix(Size priority, Real lowest_acceptable_value, bool use_lowest,
58  std::string sequence,Size longest_vall_chunk,std::string subMatrixFile) :
59  CachingScoringMethod(priority, lowest_acceptable_value, use_lowest,
60  "ProfileScoreSubMatrix")
61 {
62  // Store local copies
63  sequence_ = sequence;
64  subMatrixFile_ = subMatrixFile;
65 
66  // Setup scores to be the proper size, each sequence position has an entry for each chunk position.
67  for (Size i = 1; i <= sequence.size(); ++i) {
68  utility::vector1<Real> row(longest_vall_chunk);
69  scores_.push_back(row);
70  }
71 
72  // Read in the SubMatrix, should be BLOSUM62 format?
73  sequence::MatrixScoringScheme sub_matrix_reader;
74  sub_matrix_reader.read_from_file(subMatrixFile_);
75  sub_matrix_ = sub_matrix_reader.scoring_matrix();
76 
77 
78  // Convert score matrix to probability matrix ?
79 
80 }
81 
82 
84 
85  std::string & tmp = chunk->chunk_key();
86  if (tmp.compare(cached_scores_id_) == 0)
87  return;
88  cached_scores_id_ = tmp;
89  Size size_q = sequence_.size();
90 
91  trProfScoreSubMatrix.Debug << "caching profile score for " << chunk->get_pdb_id()
92  << " of size " << chunk->size() << std::endl;
93  PROF_START( basic::FRAGMENTPICKING_PROFILE_CAHING );
94 
95  // For each position in sequence
96  for (Size i = 1; i <= size_q; ++i) {
97 
98  AA seqAA = aa_from_oneletter_code( sequence_[i-1] );
99 
100  // For each position in chunk
101  for (Size j = 1; j <= chunk->size(); ++j) {
102 
103  AA chunkAA = aa_from_oneletter_code( chunk->at(j)->aa() );
104 
105  // For BLOSUM62, a positive score means likely to mutate (F -> Y is 3)
106  // Here lower score is better, so invert the substition matrix
107  scores_[i][j] = - sub_matrix_[seqAA][chunkAA];
108  }
109  }
110 
111  PROF_STOP( basic::FRAGMENTPICKING_PROFILE_CAHING );
112  trProfScoreSubMatrix.Debug << "precomputed matrix of scores " << scores_.size()
113  << "x" << chunk->size() << std::endl;
114 }
115 
117 
118  std::string & tmp = f->get_chunk()->chunk_key();
119 
120  if (tmp.compare(cached_scores_id_) != 0)
121  do_caching(f->get_chunk());
122 
123  Real totalScore = 0.0;
124  for (Size i = 1; i <= f->get_length(); i++) {
125 
126  // Check sizes of fragment/chunk and scores
127  assert(f->get_first_index_in_query() + i - 1 <= scores_.size());
128  assert(f->get_first_index_in_vall() + i - 1<= scores_[1].size());
129 
130  totalScore += scores_[f->get_first_index_in_query() + i - 1][f->get_first_index_in_vall() + i - 1];
131  }
132  totalScore /= (Real) f->get_length();
133  empty_map->set_score_component(totalScore, id_);
134 
135  if ((totalScore > lowest_acceptable_value_) && (use_lowest_ == true))
136  return false;
137 
138  return true;
139 }
140 
142  return cached_score( f, empty_map);
143 }
144 
145 // MISC = Substitution Matrix File Name ... the reader will spit out an error if the file does not exist.
146 FragmentScoringMethodOP MakeProfileScoreSubMatrix::make(Size priority, Real lowest_acceptable_value, bool use_lowest, FragmentPickerOP picker, std::string misc) {
147 
148  Size len = picker->get_vall()->get_largest_chunk_size();
149 
150  trProfScoreSubMatrix << "Profile scoring method is: SubMatrix" << std::endl;
151 
153  priority,
154  lowest_acceptable_value,
155  use_lowest,
156  picker->get_query_seq()->sequence(),
157  len,
158  misc // is the substituion matrix file location
159  );
160 }
161 
162 } //scores
163 } // frag_picker
164 } // protocols