Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
NoesyModule.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 NoesyModule.cc
11 /// @brief main hook-up for the automatic NOESY assignment module
12 /// @detailed
13 /// handling of input-output options
14 /// class NoesyModule:
15 /// read input files
16 /// write assignments, constraints
17 /// run assignment
18 ///
19 /// @author Oliver Lange
20 
21 // Unit Headers
23 
24 // Package Headers
31 
32 // Project Headers
35 
36 // for switching residue type set to centroid
37 #include <core/pose/Pose.hh>
42 
43 // Utility headers
44 #include <utility/io/izstream.hh>
45 #include <utility/io/ozstream.hh>
46 #include <utility/excn/Exceptions.hh>
47 
48 #include <basic/Tracer.hh>
49 #include <basic/options/option_macros.hh>
50 #include <basic/options/keys/in.OptionKeys.gen.hh>
51 #include <basic/prof.hh>
52 
53 //Auto Headers
57 #include <utility/vector1.hh>
58 
59 OPT_2GRP_KEY( File, noesy, in, resonances )
60 OPT_2GRP_KEY( FileVector, noesy, in, peaks )
61 OPT_2GRP_KEY( FileVector, noesy, in, peak_resonance_pairs )
62 OPT_2GRP_KEY( Boolean, noesy, in, use_assignments )
63 OPT_2GRP_KEY( File, noesy, in, decoys )
64 OPT_2GRP_KEY( File, noesy, in, local_dist_table )
65 
66 OPT_2GRP_KEY( File, noesy, out, resonances )
67 OPT_2GRP_KEY( File, noesy, out, peaks )
68 OPT_2GRP_KEY( File, noesy, out, talos )
69 OPT_2GRP_KEY( Boolean, noesy, out, names )
70 OPT_2GRP_KEY( Boolean, noesy, out, separate_peak_files )
71 OPT_2GRP_KEY( Boolean, noesy, out, unambiguous )
72 OPT_2GRP_KEY( String, noesy, out, format )
73 OPT_2GRP_KEY( Real, noesy, out, minVC )
74 OPT_2GRP_KEY( Real, noesy, out, padding )
75 
76 OPT_1GRP_KEY( Boolean, noesy, no_decoys )
77 
78 // OPT_1GRP_KEY( Boolean, noesy, no_symm )
79 // OPT_1GRP_KEY( Boolean, noesy, no_cs )
80 // OPT_1GRP_KEY( Boolean, noesy, no_upper )
81 // OPT_1GRP_KEY( Boolean, noesy, no_remove_diagonal )
82 // OPT_1GRP_KEY( Boolean, noesy, no_calibrate )
83 
84 bool protocols::noesy_assign::NoesyModule::options_registered_( false );
85 
86 
87 bool protocols::noesy_assign::NoesyModule::cmdline_options_activated() {
88  using namespace basic::options;
89  using namespace OptionKeys;
90  return ( option[ noesy::in::resonances ].user() && option[ noesy::in::peaks ].user() )
91  || option[ noesy::in::peak_resonance_pairs ].user();
92 }
93 
95  using namespace basic::options;
96  using namespace OptionKeys;
97 
100  if ( options_registered_ ) return;
101  options_registered_ = true;
102 
103  //....
104  NEW_OPT( noesy::in::resonances, "file with assigned chemical shifts", "" );
105 
106  NEW_OPT( noesy::in::peaks, "file with noesy peaks", "" );
107  NEW_OPT( noesy::in::peak_resonance_pairs, "pairs of files that belong together: cc.peaks cc.prot ilv.peaks ilv.prot", "" );
108  NEW_OPT( noesy::in::use_assignments, "when reading peaks the already existing assignments are not ignored", false );
109  NEW_OPT( noesy::in::decoys, "silent file with decoys used for 3D structural compatibility test", "" );
110  NEW_OPT( noesy::in::local_dist_table, "file with distances determined for instances with FragToAtomDist ", "" );
111 
112  NEW_OPT( noesy::out::resonances, "the parsed resonances file with translated atom names etc.", "cs_out.dat" );
113  NEW_OPT( noesy::out::peaks, "the parsed peaks file with assignments", "NOE_out.dat" );
114  NEW_OPT( noesy::out::talos, "write the resonances also as talos file", "cs_prot.tab" );
115  NEW_OPT( noesy::out::names, "write atom-names rather then resonance ID for assignments", true );
116  NEW_OPT( noesy::out::separate_peak_files, "write peaks to independent files with out::peaks as prefix", false );
117  NEW_OPT( noesy::out::unambiguous, "write only the assignment with hightest VC", false );
118  NEW_OPT( noesy::out::minVC, "write only assignments that contribute more than X to the peak-volume", 0.0 );
119  NEW_OPT( noesy::out::format, "write as xeasy or sparky file", "xeasy" );
120  NEW_OPT( noesy::out::padding, "add padding of X Angstrom to final constraints", 0.0 );
121  NEW_OPT( noesy::no_decoys, "check comp. with decoys", false );
122 
123 }
124 
125 static basic::Tracer tr("protocols.noesy_assign.NoesyModule");
126 
127 using core::Real;
128 using namespace core;
129 using namespace basic;
130 using namespace basic::options;
131 //using namespace OptionKeys;
132 ///// templates
133 
134 namespace protocols {
135 namespace noesy_assign {
136 
137 /// @details Auto-generated virtual destructor
138 NoesyModule::~NoesyModule() {}
139 
140 
141 ///Constructor - read input files / requires options to be initialized
142 NoesyModule::NoesyModule( std::string const& fasta_sequence ) :
143  crosspeaks_( NULL ),
144  main_resonances_( new ResonanceList( fasta_sequence ) )
145 {
147  runtime_assert( options_registered_ );
148  // moved this option into PeakAssignmentParameters.cc
149  // skip_network_analysis_ = basic::options::option[ options::OptionKeys::noesy::no_network ]();
150 }
151 
152 
153 ///delete all data and read input files again... aka fresh_instance()
155  crosspeaks_ = NULL;
156  main_resonances_ = new ResonanceList( main_resonances_->sequence() );
158 }
159 
160 ///read peak- and resonance files
162  basic::ProfileThis doit( basic::NOESY_ASSIGN_READ_INPUT );
163  using namespace basic::options;
164  //read resonances
165  if ( option[ OptionKeys::noesy::in::resonances ].user() ) {
166  utility::io::izstream input_file( option[ OptionKeys::noesy::in::resonances ]() );
167  utility::io::ozstream output_file( option[ OptionKeys::noesy::out::resonances ]() );
168  if ( input_file.good() ) {
169  main_resonances_->read_from_stream( input_file );
170  main_resonances_->write_to_stream( output_file );
171  if ( option[ OptionKeys::noesy::out::talos ].user() ) {
172  utility::io::ozstream talos_file( option[ OptionKeys::noesy::out::talos ]() );
173  main_resonances_->write_talos_format( talos_file, true /*backbone only*/ );
174  }
175  } else {
176  tr.Error << "cannot read " << input_file << std::endl;
177  throw utility::excn::EXCN_FileNotFound( option[ OptionKeys::noesy::in::resonances ]() );
178  }
179  }
180 
181  { //scope
182  //read peak lists
183  crosspeaks_ = new CrossPeakList();
184  Size nfiles( option[ OptionKeys::noesy::in::peaks ]().size() );
185 
186  //loop-all files: read one file at a time
187  for ( core::Size ifile = 1; ifile <= nfiles; ++ifile ) { //as many as there are files
188  std::string file( option[ OptionKeys::noesy::in::peaks ]()[ ifile ] );
189  utility::io::izstream input_file( file );
190  if ( input_file.good() ) {
191  if ( main_resonances_->size() < 1 ) {
192  throw utility::excn::EXCN_BadInput( "attempt to read Peak-Files with option -noesy:in:peaks without a global resonance file: -noesy:in:resonances" );
193  }
194  PeakFileFormat_xeasy format;
195  format.set_filename( option[ OptionKeys::noesy::in::peaks ]()[ ifile ].base() );
196  format.set_ignore_assignments( !option[ OptionKeys::noesy::in::use_assignments ]() );
197  tr.Info << "reading " << file << "... " << std::endl;
198  crosspeaks_->read_from_stream( input_file, format, main_resonances_ );
199  } else {
200  tr.Error << "cannot read " << file << std::endl;
201  }
202  }
203  } // scope end
204 
205  //specific resonances for a given peak-file
206  if ( option[ OptionKeys::noesy::in::peak_resonance_pairs ].user() ) { //scope
207  Size n_pair_files( option[ OptionKeys::noesy::in::peak_resonance_pairs ]().size() );
208  if ( n_pair_files % 2 != 0 ) {
209  throw utility::excn::EXCN_BadInput( "odd number of entries in option -noesy:in:peak_resonance_pairs, always provide pairs of files <*.peaks> <*.prot>" );
210  }
211  for ( core::Size ifile = 1; ifile <= n_pair_files; ifile += 2 ) {
213  utility::io::izstream res_input_file( option[ OptionKeys::noesy::in::peak_resonance_pairs ]()[ ifile+1 ] );
214  if ( res_input_file.good() ) {
215  resonances->read_from_stream( res_input_file );
216  } else {
217  tr.Error << "cannot read " << res_input_file << std::endl;
218  throw utility::excn::EXCN_FileNotFound( option[ OptionKeys::noesy::in::resonances ]() );
219  }
220  std::string file( option[ OptionKeys::noesy::in::peak_resonance_pairs ]()[ ifile ] );
221  utility::io::izstream input_file( file );
222  if ( input_file.good() ) {
223  PeakFileFormat_xeasy format;
224  format.set_filename( option[ OptionKeys::noesy::in::peak_resonance_pairs ]()[ ifile ].base() );
225  format.set_ignore_assignments( ! option[ OptionKeys::noesy::in::use_assignments ]() );
226  tr.Info << "reading " << file << "... " << std::endl;
227  crosspeaks_->read_from_stream( input_file, format, resonances );
228  } else {
229  tr.Error << "cannot read " << file << std::endl;
230  }
231  }
232  } // scope end
233 
234  if ( option[ OptionKeys::noesy::in::local_dist_table ].user() ) {
235  CovalentCompliance::get_nonconst_instance()->load_dist_table( option[ OptionKeys::noesy::in::local_dist_table ]() );
236  }
237 }
238 
240  using namespace core::scoring::constraints;
241  for ( CrossPeakList::iterator it = crosspeaks_->begin(); it != crosspeaks_->end(); ++it ) {
242  if ( (*it)->eliminated() ) continue;
243  if ( (*it)->min_seq_separation_residue_assignment( 0.1 ) < 1 ) continue;
244  for ( CrossPeak::iterator ait = (*it)->begin(); ait != (*it)->end(); ++ait ) {
245  FuncOP func( new BoundFunc(1.5, (*it)->distance_bound(), 1, "NOE Peak " ) );
246  AmbiguousNMRDistanceConstraintOP new_cst( (*ait)->create_constraint( native_pose, func ) );
247  (*ait)->set_native_distance_viol( new_cst->score( native_pose ) );
248  }
249  }
250 }
251 
252 ///@brief write peak assignments into peak-file (sparky, cyana)
254  using namespace basic::options;
255 
256  ProfileThis doit( NOESY_ASSIGN_WRITE_ASSIGNMENTS );
257  if ( file_name == "use_cmd_line" ) {
258  file_name = option[ OptionKeys::noesy::out::peaks ]();
259  }
260  PeakFileFormatOP format;
261  std::string const format_str( option[ OptionKeys::noesy::out::format ]() );
262  if ( format_str == "xeasy" ) {
263  format = new PeakFileFormat_xeasy( main_resonances_ );
264  } else if ( format_str == "sparky" ) {
265  format = new PeakFileFormat_Sparky( main_resonances_ );
266  } else utility_exit_with_message( "NOE_data output format "+format_str+" is not known! ");
267  format->set_write_atom_names( option[ OptionKeys::noesy::out::names ]() );
268  format->set_write_only_highest_VC( option[ OptionKeys::noesy::out::unambiguous ]() );
269  format->set_min_VC_to_write( option[ OptionKeys::noesy::out::minVC ]() );
270  if ( option[ OptionKeys::noesy::out::separate_peak_files ]() ) {
271  crosspeaks_->write_peak_files( file_name, *format );
272  } else {
273  utility::io::ozstream output_file( file_name );
274  crosspeaks_->write_to_stream( output_file, *format );
275  }
276 }
277 
278 ///@brief assign peaks ( no explicit decoys - wrapper )
280  using namespace basic::options;
281  using namespace OptionKeys;
282 
284  std::string file_name("NO_FILE");
285  if ( !option[ noesy::no_decoys ]() ) {
286  if ( option[ noesy::in::decoys ].user() ) {
287  file_name = option[ noesy::in::decoys ]();
288  sfd.read_file( file_name );
289  }
290  if ( sfd.size() == 0 && option[ OptionKeys::in::file::silent ].user() ) {
291  file_name = option[ OptionKeys::in::file::silent ]()[ 1 ];
292  sfd.read_file( file_name );
293  }
294  }
295  if ( sfd.begin() != sfd.end() ) {
296  if ( sfd.begin()->sequence().one_letter_sequence() != resonances().sequence() ) {
297  std::ostringstream str;
298  str << "Sequence of input structures in file " << file_name << " does not match the sequence in resonance file and fasta-file\n";
299  str << "Resonances: " << resonances().sequence() << "\n";
300  str << "Ensemble: " << sfd.begin()->sequence().one_letter_sequence();
301  utility_exit_with_message( str.str() );
302  }
303  }
304  assign( sfd.begin(), sfd.end() );
305 }
306 
307 ///@brief generate constraint files from assignments
309  core::pose::Pose const& pose,
310  std::string const& cst_fa_file,
311  std::string const& cst_centroid_file,
312  core::Size min_seq_separation,
313  core::Size min_quali,
314  core::Size max_quali,
315  bool ignore_elimination_candidates, /*default = true*/
316  bool elimination_candidates /*default = false */
317 ) const {
318 
319  PROF_START( NOESY_ASSIGN_GEN_CST );
320 
321  using namespace core::scoring::constraints;
322  using namespace basic::options;
323  using namespace OptionKeys;
324 
325  core::pose::Pose centroid_pose = pose;
327 
328  ConstraintSetOP cstset = new ConstraintSet;
329  ConstraintSetOP centroid_cstset = new ConstraintSet;
330  tr.Info << "generate constraints..." << std::endl;
331  crosspeaks_->generate_fa_and_cen_constraints(
332  cstset,
333  centroid_cstset,
334  pose,
335  centroid_pose,
336  min_seq_separation,
337  min_quali,
338  max_quali,
339  option[ noesy::out::padding ](),
340  ignore_elimination_candidates,
341  elimination_candidates
342  );
343 
344  PROF_STOP( NOESY_ASSIGN_GEN_CST );
345 
346  tr.Info << "write constraints..." << std::endl;
347  PROF_START( NOESY_ASSIGN_WRITE_CST );
348 
349  ConstraintIO::write_constraints( cst_fa_file, *cstset, pose );
350  ConstraintIO::write_constraints( cst_centroid_file, *centroid_cstset, centroid_pose );
351 
352  PROF_STOP( NOESY_ASSIGN_WRITE_CST );
353 }
354 
355 }
356 }
357 
358