Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ReplicateFilter.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 sw=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/filters/ReplicateFilter.cc
11 /// @brief Repeat a subfilter multiple times, and pass a value based on the aggregate results
12 /// @author Rocco Moretti (rmoretti@u.washington.edu)
13 
16 
17 #include <core/pose/Pose.hh>
18 #include <utility/tag/Tag.hh>
22 #include <basic/Tracer.hh>
23 #include <core/types.hh>
25 
26 #include <utility/vector1.hh>
27 #include <numeric/util.hh>
28 
29 #include <algorithm>
30 
31 namespace protocols {
32 namespace filters {
33 
34 static basic::Tracer TR( "protocols.filters.ReplicateFilter" );
35 
36 ///@brief default ctor
38  Filter( "ReplicateFilter" ),
39  replicates_(1),
40  upper_trim_(0),
41  lower_trim_(0),
42  median_(false),
43  threshold_(0)
44 {}
45 
47  Filter( "ReplicateFilter" ),
48  subfilter_(subfilter),
49  replicates_(replicates),
50  upper_trim_(upper_trim),
51  lower_trim_(lower_trim),
52  median_(false),
53  threshold_(0)
54 {}
55 
56 bool
58 {
59  core::Real value = compute(pose);
60  return value <= threshold_;
61 }
62 
65 {
66  return( compute(pose) );
67 }
68 
69 void
70 ReplicateFilter::report( std::ostream & out, core::pose::Pose const & pose) const
71 {
72  out<<"ReplicateFilter returns "<< compute(pose) <<std::endl;
73 }
74 
77  runtime_assert( subfilter_ );
79  TR.Warning << "Replicate Filter trims off all values - returning 0." << std::endl;
80  }
82  for( core::Size ii(1); ii <= replicates_; ++ii) {
83  values.push_back( subfilter_->report_sm( pose ) );
84  }
85  std::sort( values.begin(), values.end() );
86  if( values[1] == values[replicates_] && replicates_ != 1) { // Exact comparison of Real values is intentional
87  TR.Warning << "Replicate Filter used, but all " << replicates_ << " replicates are identical! " << std::endl;
88  }
90  TR << "Replicate filter: ";
91  for( core::Size jj(1); jj <= replicates_; ++jj ) {
92  if( jj == replicates_ - upper_trim_ + 1 ) { TR << "| "; }
93  TR << values[jj] << " ";
94  if( jj == lower_trim_ ) { TR << "| "; }
95  if( jj >= lower_trim_ + 1 && jj <= replicates_ - upper_trim_ ) {
96  value_trim.push_back( values[jj] );
97  }
98  }
99  core::Real value;
100  if( median_ ) {
101  TR << "=> median ";
102  value = numeric::median( value_trim );
103  } else {
104  TR << "=> mean ";
105  value = numeric::mean( value_trim );
106  }
107  TR << "=> " << value << std::endl;
108  return value;
109 }
110 
111 void
114  protocols::filters::Filters_map const & filters,
116  core::pose::Pose const &)
117 {
118  subfilter_ = protocols::rosetta_scripts::parse_filter( tag_ptr->getOption<std::string>( "filter_name" ) , filters );
119  replicates_ = tag_ptr->getOption<core::Size>( "replicates", 1 );
120  core::Real upper_cut = tag_ptr->getOption<core::Real>( "upper_cut", 0 );
121  core::Real lower_cut = tag_ptr->getOption<core::Real>( "lower_cut", 0 );
122  lower_trim_ = core::Size(lower_cut);
123  if (lower_cut < 1.0) {
124  lower_trim_ = core::Size(lower_cut * replicates_); // Truncation is desired
125  }
126  upper_trim_ = core::Size(upper_cut);
127  if (upper_cut < 1.0) {
128  upper_trim_ = core::Size(upper_cut * replicates_); // Truncation is desired
129  }
130  if( lower_trim_ + upper_trim_ >= replicates_ ) {
131  utility_exit_with_message("In ReplicateFilter, the number of items removed by upper and lower cuts exceed the total number of items.");
132  }
133  median_ = tag_ptr->getOption< bool >( "median", false );
134  threshold_ = tag_ptr->getOption<core::Real>( "threshold", 0.0 );
135 }
136 
137 FilterOP
139 
141 ReplicateFilterCreator::keyname() const { return "ReplicateFilter"; }
142 
143 } // filters
144 } // protocols