Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
validate_silent.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 apps/public/comparative_modeling/validate_silent.cc
11 /// @author Christopher Miles (cmiles@uw.edu)
12 
13 // C/C++ headers
14 #include <iostream>
15 #include <string>
16 
17 // Utility headers
18 #include <basic/options/option.hh>
20 #include <basic/options/keys/in.OptionKeys.gen.hh>
21 #include <basic/options/keys/out.OptionKeys.gen.hh>
22 #include <devel/init.hh>
23 #include <utility/exit.hh>
25 #include <utility/vector1.hh>
26 
27 // Project headers
28 #include <core/io/silent/SilentFileData.hh>
29 #include <core/io/silent/SilentStruct.hh>
30 #include <core/sequence/util.hh>
31 
32 // External headers
33 #include <boost/algorithm/string/predicate.hpp>
34 
35 #define PCT_THRESHOLD 0.9
36 using namespace std;
37 
38 int main(int argc, char* argv[]) {
39  try {
40 
41  using namespace basic::options;
42  using namespace basic::options::OptionKeys;
43  using namespace core::io::silent;
44  devel::init(argc, argv);
45 
46  if ( !option[in::file::fasta].user() ) {
47  utility_exit_with_message("Failed to provide required argument -in:file:fasta");
48  }
49 
50  if ( !option[in::file::silent].user() ) {
51  utility_exit_with_message("Failed to provide required argument -in:file:silent");
52  }
53 
54  if ( !option[out::file::silent].user() ) {
55  utility_exit_with_message("Failed to provide required argument -out:file:silent");
56  }
57 
58  // Prevent the silent file parser from aborting on malformed input
59  option[in::file::silent_read_through_errors].value(true);
60 
61  utility::vector1<string> sequences = core::sequence::read_fasta_file_str(option[in::file::fasta]()[1]);
62  const string ref_sequence = sequences[1];
63  const string input_file = option[in::file::silent]()[1];
64  const string output_file = option[out::file::silent]();
65 
66  cout << "Reference: " << ref_sequence << endl;
67 
68  SilentFileData sfd_in, sfd_out;
69  sfd_in.read_file(input_file);
70 
71  size_t num_good = 0, num_failed = 0, num_mismatch = 0;
72 
73  utility::vector1<string> tags = sfd_in.tags();
74  for ( utility::vector1<string>::const_iterator i = tags.begin(); i != tags.end(); ++i ) {
75  SilentStructOP decoy = sfd_in[*i];
76  string decoy_id = *i;
77  string sequence = decoy->sequence().one_letter_sequence();
78 
79  // Because we're not using jd2, we're responsible for removing failed simulations
80  bool failed_simulation = boost::starts_with(decoy_id, "W_");
81  bool sequence_mismatch = ref_sequence.compare(0, ref_sequence.length(), sequence, 0, ref_sequence.length()) != 0;
82 
83  if ( failed_simulation ) {
84  cerr << "Removed tag " << decoy_id << " (failed simulation)" << endl;
85  ++num_failed;
86  } else if ( sequence_mismatch ) {
87  cerr << "Removed tag " << decoy_id << " (sequence mismatch)" << endl;
88  ++num_mismatch;
89  } else {
90  sfd_out.write_silent_struct(*decoy, output_file, false);
91  ++num_good;
92  }
93  }
94 
95  // print summary statistics
96  double total = num_good + num_failed + num_mismatch;
97  double pct_good = num_good / total;
98  double pct_failed = num_failed / total;
99  double pct_mismatch = num_mismatch / total;
100  cout << "pct_good: " << pct_good << " pct_failed: " << pct_failed << " pct_mismatch: " << pct_mismatch << endl;
101 
102  // If the percentage of failures exceeds a threshold, signal
103  // failure to external callers using the return code
104  return (pct_good >= PCT_THRESHOLD) ? 0 : 1;
105 
106  } catch ( utility::excn::EXCN_Base const & e ) {
107  std::cout << "caught exception " << e.msg() << std::endl;
108  return -1;
109  }
110 }
ocstream cerr(std::cerr)
Wrapper around std::cerr.
Definition: ocstream.hh:290
#define utility_exit_with_message(m)
Exit with file + line + message.
Definition: exit.hh:47
virtual std::string const msg() const
Definition: EXCN_Base.hh:70
#define PCT_THRESHOLD
void init(int argc, char *argv[])
Command line init() version.
Definition: init.cc:23
BooleanOptionKey const user("options:user")
Definition: OptionKeys.hh:40
common derived classes for thrown exceptions
int main(int argc, char *argv[])
Program exit functions and macros.
basic::options::OptionKeys collection
std::vector with 1-based indexing
Definition: vector1.fwd.hh:44
rule< Scanner, options_closure::context_t > options
Definition: Tag.cc:377
super::const_iterator const_iterator
Definition: vector1.hh:62
ocstream cout(std::cout)
Wrapper around std::cout.
Definition: ocstream.hh:287
vector1: std::vector with 1-based indexing
Program options global and initialization function.
int const silent
Named verbosity levels.
rule< Scanner, option_closure::context_t > option
Definition: Tag.cc:378