Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
fragment_scoring_utilities.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 and 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/fragment_scoring_utilities.hh
11 /// @brief functions and data types common for fragment scoring
12 /// @author Dominik Gront
13 
15 
16 #include <utility/vector1.hh>
17 
18 
19 namespace protocols {
20 namespace frag_picker {
21 namespace scores {
22 
23 void create_cache(utility::vector1<Size> & frag_sizes,Size query_len,Size longest_vall_chunk,utility::vector1<Matrix> & cache) {
24 
25  std::sort(frag_sizes.begin(),frag_sizes.end());
26  cache.resize(frag_sizes[frag_sizes.size()]);
27  for(Size i=1;i<=frag_sizes.size();i++) {
28  Matrix m;
29  allocate_matrix(query_len,longest_vall_chunk,m);
30  cache[frag_sizes[i]] = m;
31  }
32 }
33 
34 void allocate_matrix(Size i_size,Size j_size,Matrix & dst) {
35 
36  dst.clear();
37  for(Size i = 1; i <= i_size;i++) {
38  utility::vector1<Real> row(j_size);
39  dst.push_back( row );
40  }
41 }
42 
43 void do_one_line(Size start_i,Size start_j,Matrix & small_scores,Size frag_len,Matrix & frag_scores) {
44 
45  Size stop_i = start_i + frag_len - 1;
46  Size stop_j = start_j + frag_len - 1;
47  Real last_score = small_scores[start_i][start_j];
48 
49  for(Size i=1;i<frag_len;i++) {
50  last_score += small_scores[start_i+i][start_j+i];
51  }
52  frag_scores[start_i][start_j] = last_score;
53  int max_steps = std::min((int) small_scores.size() - (int) start_i - (int) frag_len,
54  (int) small_scores[1].size() - (int) start_j - (int) frag_len) + 1;
55  int cnt = 1;
56  while(cnt<=max_steps) {
57  stop_i++;
58  stop_j++;
59  last_score += small_scores[stop_i][stop_j] - small_scores[start_i][start_j];
60  start_i++;
61  start_j++;
62  frag_scores[start_i][start_j] = last_score;
63  cnt++;
64  }
65 }
66 
67 void rolling_score(Matrix & small_scores,Size frag_len,Matrix & frag_scores) {
68 
69  do_one_line(1,1,small_scores,frag_len,frag_scores);
70  for(Size i=2;i<=small_scores.size()-frag_len+1;i++)
71  do_one_line(i,1,small_scores,frag_len,frag_scores);
72  for(Size i=2;i<=small_scores[1].size()-frag_len+1;i++)
73  do_one_line(1,i,small_scores,frag_len,frag_scores);
74 }
75 
76 
77 } // scores
78 } // frag_picker
79 } // protocols
80