Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
QuotaCollector.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/quota/QuotaCollector.hh
11 /// @brief Pure virtual base class for a container holding fragment candidates
12 /// @author Dominik Gront (dgront@chem.uw.edu.pl)
13 
14 
15 // package headers
23 
24 #include <utility/vector1.hh>
25 #include <basic/Tracer.hh>
26 
27 #include <iostream>
28 #include <iomanip>
29 
30 namespace protocols {
31 namespace frag_picker {
32 namespace quota {
33 
34 static basic::Tracer trQuotaCollector(
35  "protocols.frag_picker.quota.QuotaCollector");
36 
37 bool QuotaCollector::add(std::pair<FragmentCandidateOP, scores::FragmentScoreMapOP> candidate) {
38 
39  Size pos = candidate.first->get_first_index_in_query();
40  bool if_inserted = false;
41  for(Size j=1;j<=storage_[pos].size();++j) {
42 // trQuotaCollector.Debug<< "Trying: "<<storage_[pos][j]->get_pool_name()<<" pos: "<<pos<<" pool_id: "<<j<<" of "<<storage_[pos].size()<<std::endl;
43  bool tmp = storage_[pos][j]->add(candidate);
44  if_inserted = if_inserted || tmp;
45  }
46 
47  return if_inserted;
48 }
49 
50 void QuotaCollector::list_pools(std::ostream & where) const {
51 
52  for(Size i=1;i<storage_.size();++i) {
53  where << std::setw(3) << i;
54  for(Size j=1;j<storage_[i].size();++j) {
55  where << std::setw(10) << storage_[i][j]->get_pool_name() << "(" << std::setw(3) << storage_[i][j]->total_size() << ") ";
56  }
57  where << std::endl;
58  }
59 }
60 
61 
63 
64  for(Size i=1;i<=storage_.size();++i)
65  for(Size j=1;j<storage_[i].size();++j)
66  storage_[i][j]->clear();
67 }
68 
70 
71  Size cnt = 0;
72  for(Size j=1;j<storage_[pos].size();++j)
73  cnt += storage_[pos][j]->count_candidates();
74 
75  return cnt;
76 }
77 
79  Size cnt = 0;
80  for(Size i=1;i<=storage_.size();++i)
81  for(Size j=1;j<storage_[i].size();++j)
82  cnt += storage_[i][j]->count_candidates();
83 
84  return cnt;
85 }
86 
87  /// @brief Describes what has been collected
89  std::ostream & output,
91 ) const {
92 
93  using namespace ObjexxFCL::fmt;
94 
95  output<<"QuotaCollector contains the following number of fragments at each position:\n";
96  for(Size i=1;i<=storage_.size();++i) {
97  output<< I(4, i);
98  for(Size j=1;j<=storage_[i].size();++j) {
99  output<<" "<<RJ(10,storage_[i][j]->get_pool_name())
100  <<" "<<I(3,storage_[i][j]->current_size());
101  }
102  output<<"\n";
103  }
104  output<<std::endl;
105 }
106 
108 
109  frags_for_pos_.clear();
110  for(Size j=1;j<=storage_[position_in_query].size();++j) {
111  for(Size k=1;k<=storage_[position_in_query][j]->count_candidates();k++) {
112  ScoredCandidatesVector1 & content = storage_[position_in_query][j]->get_candidates(0);
113  for(Size l=1;l<=content.size();l++)
114  frags_for_pos_.push_back( content[l] );
115  }
116  }
117  trQuotaCollector << frags_for_pos_.size()<<" candidates collected for pos. "<<position_in_query<<std::endl;
118 
119  return frags_for_pos_;
120 }
121 
122 
124 
125  for(Size i=1;i<=storage_.size();++i) {
126  Real sum = 0.0;
127  for(Size j=1;j<=i;++j)
128  sum += storage_[i][j]->get_fraction();
129  for(Size j=1;j<=i;++j)
130  storage_[i][j]->set_fraction( storage_[i][j]->get_fraction()/sum );
131  }
132 }
133 
134 
136  Real prediction_fraction,
138  std::string name,
139  Size n_candidates,
140  utility::vector1<Size> components,
141  utility::vector1<Real> weights,
142  Size n_scores
143 ) {
144 
145  Size n;
146  Real f;
147  Size middle = frag_size_ / 2 + 1;
148  for(Size i=1;i<=storage_.size();++i) {
149 
150  trQuotaCollector.Trace << "Quota pools at pos: "<<i<<std::endl;
151  f = prediction->helix_fraction(i+middle-1)*prediction_fraction;
152  n = (Size) (n_candidates * f );
153  Size buffer_factor = 3;
154  if(n == 0)
155  trQuotaCollector.Debug << "Pool >"<<name<<"< for H would have size 0, not created"<<std::endl;
156  else {
157  SecondaryStructurePoolOP pool = new SecondaryStructurePool(n_candidates,name+":H",'H',components,weights,f,n_scores,buffer_factor);
158  storage_[i].push_back( pool );
159  if(trQuotaCollector.Trace.visible()) {
160  trQuotaCollector.Trace << "Pool >"<<name<<":E< added at query pos: "<<i<<" as number: "<<storage_[i].size()<<std::endl;
161  trQuotaCollector.Trace<<"Scoring scheme for the quota pool sorting is:";
162  for(Size l=1;l<=weights.size();l++)
163  trQuotaCollector.Trace<<"\n\t"<<components[l]<<"\t"<<weights[l];
164  trQuotaCollector.Trace<<std::endl;
165  }
166  }
167 
168  f = prediction->sheet_fraction(i+middle-1)*prediction_fraction;
169  n = (Size) (n_candidates * f );
170  if(n == 0)
171  trQuotaCollector.Debug << "Pool >"<<name<<"< for E would have size 0, not created"<<std::endl;
172  else {
173  SecondaryStructurePoolOP pool = new SecondaryStructurePool(n_candidates,name+":E",'E',components,weights,f,n_scores,buffer_factor);
174  storage_[i].push_back( pool );
175  if(trQuotaCollector.Trace.visible()) {
176  trQuotaCollector.Trace << "Pool >"<<name<<":E< added at query pos: "<<i<<" as number: "<<storage_[i].size()<<std::endl;
177  trQuotaCollector.Trace<<"Scoring scheme for the quota pool sorting is:";
178  for(Size l=1;l<=weights.size();l++)
179  trQuotaCollector.Trace<<"\n\t"<<components[l]<<"\t"<<weights[l];
180  trQuotaCollector.Trace<<std::endl;
181  }
182  }
183 
184  f = prediction->loop_fraction(i+middle-1)*prediction_fraction;
185  n = (Size) (n_candidates * f );
186  if(n == 0)
187  trQuotaCollector.Debug << "Pool >"<<name<<"< for L would have size 0, not created"<<std::endl;
188  else {
189  SecondaryStructurePoolOP pool = new SecondaryStructurePool(n_candidates,name+":L",'L',components,weights,f,n_scores,buffer_factor);
190  storage_[i].push_back( pool );
191  if(trQuotaCollector.Trace.visible()) {
192  trQuotaCollector.Trace << "Pool >"<<name<<":E< added at query pos: "<<i<<" as number: "<<storage_[i].size()<<std::endl;
193  trQuotaCollector.Trace<<"Scoring scheme for the quota pool sorting is:";
194  for(Size l=1;l<=weights.size();l++)
195  trQuotaCollector.Trace<<"\n\t"<<components[l]<<"\t"<<weights[l];
196  trQuotaCollector.Trace<<std::endl;
197  }
198  }
199  }
200 }
201 
202 } // quota
203 } // frag_picker
204 } // protocols
205