Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FavorSequenceProfile.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/simple_moves/FavorSequenceProfile.cc
11 /// @brief Add a SequenceProfileConstraint to a pose.
12 /// @author Rocco Moretti (rmoretti@u.washington.edu)
13 
14 // Unit Headers
17 
19 #include <core/pose/Pose.hh>
20 // AUTO-REMOVED #include <core/id/AtomID.hh> // needed for Windows build
23 #include <core/sequence/util.hh>
27 
29 #include <utility/tag/Tag.hh>
30 
31 #include <basic/options/option.hh>
32 #include <basic/options/keys/in.OptionKeys.gen.hh>
33 #include <basic/Tracer.hh>
34 
35 #include <utility/string_util.hh>
36 #include <utility/exit.hh>
37 
38 #include <utility/vector0.hh>
39 #include <utility/excn/Exceptions.hh>
40 #include <utility/vector1.hh>
41 
42 
43 // #include <boost/foreach.hpp>
44 // #define foreach BOOST_FOREACH
45 
46 
47 namespace protocols {
48 namespace simple_moves {
49 
50 using namespace core;
51 using namespace std;
52 using namespace core::scoring;
53 
54 static basic::Tracer TR( "protocols.simple_moves.FavorSequenceProfile" );
55 
57 {
59 }
60 
63  return new FavorSequenceProfile;
64 }
65 
68  return "FavorSequenceProfile";
69 }
70 
71 
73  protocols::moves::Mover( "FavorSequenceProfile" ),
74  weight_( 1.0 ),
75  use_current_(false),
76  matrix_("BLOSUM62"),
77  scaling_("prob"),
78  chain_(0)
79 {}
80 
81 void
83  weight_ = weight;
84 }
85 
86 void
88  if (ref_profile_) {
89  TR.Warning << "Overwriting existing profile in FavorSequenceProfile." << std::endl;
90  }
92  ref_profile_->generate_from_sequence(seq, matrix);
93 }
94 
95 void
97  if (ref_profile_) {
98  TR.Warning << "Overwriting existing profile in FavorSequenceProfile." << std::endl;
99  }
101 }
102 
103 void
105  if( scaling != "prob" && scaling != "none" && scaling != "global" ) {
106  utility_exit_with_message("Scaling in FavorSequenceProfile must be one of 'prob', 'none', or 'global'.");
107  }
108  scaling_ = scaling;
109 }
110 
111 void
113 {
115  if( use_current_ ) {
116  core::sequence::Sequence seq(pose);
117  profile = new core::sequence::SequenceProfile;
118  profile->generate_from_sequence(seq, matrix_);
119  } else {
120  runtime_assert( ref_profile_ );
122  }
123 
124  if( scaling_ == "prob" ) {
125  profile->convert_profile_to_probs( 1.0 );
126  } else if( scaling_ == "none" ) {
127  // pass
128  } else if( scaling_ == "global" ) {
129  profile->global_auto_rescale();
130  } else {
131  utility_exit_with_message("Unrecognized scaling type '" + scaling_ + "' in FavorSequenceProfile.");
132  }
133 
134  if( weight_ != 1.0 ) {
135  profile->rescale(weight_);
136  }
137  //using varibles for start/stop in case a sequence for only one chain was specified
138  core::Size start_seq = 1;
139  core::Size stop_seq = pose.total_residue();
140 
141  if( chain_ > 0 ){
142  start_seq = pose.conformation().chain_begin( chain_ );
143  stop_seq = pose.conformation().chain_end( chain_ );
144  }
145 
146  for( core::Size seqpos( start_seq ), end( stop_seq ); seqpos <= end; ++seqpos ) {
147  pose.add_constraint( new core::scoring::constraints::SequenceProfileConstraint( pose, seqpos, profile ) );
148  }
149 }
150 
151 void
153 {
154  weight_ = tag->getOption<core::Real>( "weight", 1 );
155 
156  if ( tag->hasOption("scorefxns") ) {
157  std::string const sf_val( tag->getOption<std::string>("scorefxns") );
158  typedef utility::vector1< std::string > StringVec;
159  StringVec const sf_keys( utility::string_split( sf_val, ',' ) );
160  for ( StringVec::const_iterator it( sf_keys.begin() ), end( sf_keys.end() ); it != end; ++it ) {
161  ScoreFunctionOP scorefxn( *data.get< ScoreFunction * >( "scorefxns", *it ) );
162  if( scorefxn->get_weight( res_type_constraint ) == 0.0 ){
163  scorefxn->set_weight( res_type_constraint, 1 );
164  TR<<"Turning on res_type_constraint weight in scorefxn "<<*it<<std::endl;
165  }
166  }
167  }
168 
169  core::Size num_struct(0);
170  if( tag->getOption< bool >( "use_native", false ) ) ++num_struct;
171  if( tag->getOption< bool >( "use_fasta", false ) ) ++num_struct;
172  if( tag->getOption< bool >( "use_starting", false ) ) ++num_struct;
173  if( tag->getOption< bool >( "use_current", false ) ) ++num_struct;
174  if( tag->hasOption("pdbname") ) ++num_struct;
175 
176  if( ! num_struct && ! tag->hasOption("pssm") ) {
177  throw utility::excn::EXCN_RosettaScriptsOption("Must set one of 'pssm', 'use_native', 'use_fasta', 'use_starting', 'use_current', or 'pdbname' in FavorSequenceProfile");
178  }
179  if( num_struct && tag->hasOption("pssm") ) {
180  throw utility::excn::EXCN_RosettaScriptsOption("Cannot set both 'pssm' and one of 'use_native', 'use_fasta', 'use_starting', 'use_current', or 'pdbname' in FavorSequenceProfile");
181  }
182  if( num_struct > 1 ) {
183  throw utility::excn::EXCN_RosettaScriptsOption("Can only set one of 'use_native', 'use_fasta', 'use_starting', 'use_current', or 'pdbname' in FavorSequenceProfile");
184  }
185  if( tag->hasOption("matrix") && tag->hasOption("pssm") ) {
186  TR.Warning << "WARNING In option matrix not used with pssm specification." << std::endl;
187  }
188  if( tag->hasOption("chain"))
189  chain_ = tag->getOption<core::Size>("chain", 0 );
190 
191  set_scaling( tag->getOption< std::string >( "scaling", "prob" ) );
192 
193  matrix_ = tag->getOption< std::string >( "matrix", "BLOSUM62" );
194  if( tag->getOption< bool >( "use_native", false ) ) {
195  core::pose::Pose nat_pose;
196  core::import_pose::pose_from_pdb( nat_pose, basic::options::option[ basic::options::OptionKeys::in::file::native ] );
197  core::sequence::Sequence seq(nat_pose.sequence(), basic::options::option[ basic::options::OptionKeys::in::file::native ]);
198  set_sequence( seq, matrix_ );
199  }
200  if( tag->getOption< bool >( "use_fasta", false ) ) {
201  std::string fasta_file( core::sequence::read_fasta_file_str( basic::options::option[ basic::options::OptionKeys::in::file::fasta ]()[1] )[1] );
202  std::string name("unknown");
203  core::sequence::Sequence seq( fasta_file, name );
204  std::cout << seq << std::endl;
205  set_sequence( seq, matrix_ );
206  }
207  if( tag->getOption< bool >( "use_starting", false ) ) {
208  core::sequence::Sequence seq(pose);
209  set_sequence( seq, matrix_ );
210  }
211  if( tag->getOption< bool >( "use_current", false ) ) {
212  use_current_ = true;
213  }
214  if( tag->hasOption("pdbname") ) {
215  core::pose::Pose ref_pose;
216  core::import_pose::pose_from_pdb( ref_pose, tag->getOption<std::string>( "pdbname" ) );
217  core::sequence::Sequence seq(ref_pose.sequence(), tag->getOption<std::string>( "pdbname" ) );
218  set_sequence( seq, matrix_ );
219  }
220  if( tag->hasOption("pssm") ) {
222  ref_profile_->read_from_file( tag->getOption< std::string >( "pssm" ) );
223  }
224 }
225 
226 void FavorSequenceProfile::parse_def( utility::lua::LuaObject const & def,
227  utility::lua::LuaObject const & /*score_fxns*/,
228  utility::lua::LuaObject const & /*tasks*/,
229  protocols::moves::MoverCacheSP /*cache*/ ) {
230 
231  weight_ = def["weight"] ? def["weight"].to<core::Real>() : 1;
232 
233  core::Size num_struct(0);
234  if( def["use_native"] && def["use_native"].to<bool>() ) ++num_struct;
235  if( def["use_fasta"] && def["use_fasta"].to<bool>() ) ++num_struct;
236  if( def["use_starting"] && def["use_starting"].to<bool>() ) ++num_struct;
237  if( def["use_current"] && def["use_current"].to<bool>() ) ++num_struct;
238  if( def["pdbname"]) ++num_struct;
239 
240  if( ! num_struct && ! def["pssm"] ) {
241  utility_exit_with_message("Must set one of 'pssm', 'use_native', 'use_fasta', 'use_starting', 'use_current', or 'pdbname' in FavorSequenceProfile");
242  }
243  if( num_struct && def["pssm"] ) {
244  utility_exit_with_message("Cannot set both 'pssm' and one of 'use_native', 'use_fasta', 'use_starting', 'use_current', or 'pdbname' in FavorSequenceProfile");
245  }
246  if( num_struct > 1 ) {
247  utility_exit_with_message("Can only set one of 'use_native', 'use_fasta', 'use_starting', 'use_current', or 'pdbname' in FavorSequenceProfile");
248  }
249  if( def["matrix"] && def["pssm"] ) {
250  TR.Warning << "WARNING In option matrix not used with pssm specification." << std::endl;
251  }
252  if( def["chain"] )
253  chain_ = def["chain"].to<core::Size>();
254 
255  set_scaling( def["set_scaling"] ? def[ "set_scaling" ].to<std::string>() : "prob" );
256 
257  matrix_ = def["matrix"] ? def[ "matrix" ].to<std::string>() : "BLOSUM62";
258  if( def["use_native"] && def["use_native"].to<bool>() ) {
259  core::pose::Pose nat_pose;
260  core::import_pose::pose_from_pdb( nat_pose, basic::options::option[ basic::options::OptionKeys::in::file::native ] );
261  core::sequence::Sequence seq(nat_pose.sequence(), basic::options::option[ basic::options::OptionKeys::in::file::native ]);
262  set_sequence( seq, matrix_ );
263  }
264  if( def["use_fasta"] && def["use_fasta"].to<bool>() ) {
265  std::string fasta_file( core::sequence::read_fasta_file_str( basic::options::option[ basic::options::OptionKeys::in::file::fasta ]()[1] )[1] );
266  std::string name("unknown");
267  core::sequence::Sequence seq( fasta_file, name );
268  std::cout << seq << std::endl;
269  set_sequence( seq, matrix_ );
270  }
271  /*
272  if( def["use_starting"] && def["use_starting"].to<bool>() ) {
273  core::sequence::Sequence seq(pose);
274  set_sequence( seq, matrix_ );
275  }
276  */
277  if( def["use_current"] && def["use_current"].to<bool>() ) {
278  use_current_ = true;
279  }
280  if( def["pdbname"] ) {
281  core::pose::Pose ref_pose;
282  core::import_pose::pose_from_pdb( ref_pose, def["pdbname"].to<std::string>() );
283  core::sequence::Sequence seq(ref_pose.sequence(), def["pdbname"].to<std::string>() );
284  set_sequence( seq, matrix_ );
285  }
286  if( def["pssm"] ) {
288  ref_profile_->read_from_file( def["pssm"].to<std::string>() );
289  }
290 }
291 
292 } //moves
293 } //protocols
294