Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FragmentReader.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/jd2/parser/FragmentReader.cc
11 /// @brief
12 /// @author Nobuyasu Koga ( nobuyasu@uw.edu )
13 
14 // Unit Headers
16 
17 // Package Headers
18 // AUTO-REMOVED #include <core/io/pdb/pose_io.hh>
20 // AUTO-REMOVED #include <core/chemical/ResidueTypeSet.hh>
24 #include <core/fragment/FragSet.hh>
27 #include <core/fragment/Frame.hh>
28 // AUTO-REMOVED #include <core/fragment/FragID.hh> // REQUIRED FOR WINDOWS
32 #include <core/fragment/util.hh>
33 #include <core/pose/Pose.hh>
34 #include <basic/Tracer.hh>
35 
38 
40 // AUTO-REMOVED #include <protocols/fldsgn/topology/HSSTriplet.hh> // REQUIRED FOR WINDOWS
41 
42 #include <utility/exit.hh> // runtime_assert, utility_exit_with_message
43 #include <utility/string_util.hh>
44 #include <utility/tag/Tag.hh>
45 #include <utility/vector1.hh>
46 
50 #include <utility/vector0.hh>
51 
52 
53 static basic::Tracer TR( "protocols.jd2.parser.FragmentReader" );
54 
55 
56 namespace protocols {
57 namespace jd2 {
58 namespace parser {
59 
60 /// @brief default constructor
62  Parent()
63 {}
64 
65 /// @brief value constructor
67  Parent()
68 {
69  parse_tag( tag );
70 }
71 
72 /// @brief destructor
74 
75 /// @brief parse tag
76 void
78 {
79  /// the way of reading fragments: from pdbs, silent, fragfiles, or vall
80  read_type_ = tag->getOption< String >( "type", "" );
81  if( read_type_.empty() ){
82  TR.Error << "No type option. " << std::endl;
83  runtime_assert( false );
84  }
85  if( read_type_ != "pdb" && read_type_ != "silent" && read_type_ != "vall" && read_type_ != "fragfile" ){
86  TR.Error << "Read type " << read_type_ << " is not registered " << std::endl;
87  runtime_assert( false );
88  }
89 
90  filename_ = tag->getOption< String >( "filename", "" );
91  if( read_type_ == "pdb" || read_type_ == "silent" || read_type_ == "fragfile" ){
92  runtime_assert( !filename_.empty() );
93  }
94 
95  // length of fragments
96  frag_size_ = tag->getOption<Size>( "size", 0 );
97 
98  // the begin of sequence positions where fragments are stealed and inserted
99  begin_ = tag->getOption<Size>( "begin", 0 );
100 
101  // the end of sequence positions where fragments are stealed and inserted
102  end_ = tag->getOption<Size>( "end", 0 );
103 
104  // number of fragments per position
105  nfrags_ = tag->getOption<Size>( "nfrags", 200 );
106 
107  if( read_type_ == "vall" ){
108 
109  runtime_assert( frag_size_ != 0 );
110 
111  /// secondary structure assignments to pick fragments from vall
112  // read from blueprint
113  String const blueprint( tag->getOption<String>( "blueprint", "" ) );
114  if( blueprint != "" ){
116  ss_ = blueprint_->secstruct();
117  // pick fragment using sequence information (default false)
118  bool use_sequence_bias( tag->getOption<bool>( "use_sequence_bias", 0 ) );
119  if( use_sequence_bias ) {
120  aa_ = blueprint_->sequence();
121  }
122  }
123 
124  // using abego definition which is given by blueprint file
125  use_abego_ = tag->getOption<bool>( "use_abego", 0 );
126 
127  //
128  if( ss_.empty() ) {
129  ss_ = tag->getOption<String>( "ss", "" );
130  }
131 
132  // make sure ss_ is not empty
133  runtime_assert( !ss_.empty() );
134 
135  // amino acids to pick fragments from vall
136  aa_ = tag->getOption<String>( "aa", "" );
137 
138  if( ! aa_.empty() ){
139  runtime_assert( ss_.length() == aa_.length() );
140  }
141  if( begin_ == 0 ){
142  TR << "Since option begin is emptry, Fragment is defined from the first residue. " << std::endl;
143  begin_ = 1;
144  //TR.Error << "Option begin has to be defined. !!" << std::endl;
145  //runtime_assert( false );
146  }
147  if( end_ != 0 ){
148  runtime_assert( end_ == begin_ + ss_.length() - 1 );
149  }
150  end_ = begin_ + ss_.length() - 1;
151 
152  TR << "Picking fragments from vall for poistions " << begin_ << "-" << end_
153  << " based on ss=" << ss_ << ", aa=" << aa_ << std::endl;
154 
155  } else if( read_type_ == "pdb" || read_type_ == "silent" ){
156 
157  runtime_assert( frag_size_ != 0 );
158 
159  /// number of stealing times
160  steal_times_ = tag->getOption<Size>( "steal_times", 1 );
161 
162  TR << "Picking Fragments from " << filename_ << " for poistions " << begin_ << "-" << end_ << std::endl;
163  }
164  runtime_assert( begin_ <= end_ );
165 
166 }
167 
168 /// @brief
169 void
170 FragmentReader::set_fragments( Pose const & pose_in, FragSetOP const & fragset )
171 {
174  if( begin_ == 0 ){
175  core::fragment::steal_frag_set_from_pose( pose_in, *fragset, new FragData( new IndependentBBTorsionSRFD, frag_size_ ) );
176  }else{
177  core::fragment::steal_frag_set_from_pose( pose_in, begin_, end_ , *fragset, new FragData( new IndependentBBTorsionSRFD, frag_size_ ) );
178  }
179 }
180 
181 /// @brief
182 void
184 {
186 
187  if( read_type_ == "silent" ){
188 
194 
196  SilentFilePoseInputStreamOP silent_input = new SilentFilePoseInputStream( filename_ );
197 
198  Size num( 0 );
199  Pose pose_in;
200  while( num++ <= nfrags_ && silent_input->has_another_pose() ){
201  silent_input->fill_pose( pose_in, *residue_set );
202  runtime_assert( end_ <= pose_in.total_residue() );
203  set_fragments( pose_in, fragset );
204  }
205 
206  }else if( read_type_ == "pdb" ){
207 
208  Pose pose_in;
209  utility::vector1< String > fs ( utility::string_split( filename_, ',' ) );
210  for ( utility::vector1< String>::const_iterator it( fs.begin() ), end( fs.end() ); it!=end; ++it ) {
211  String filename( *it );
212  core::import_pose::centroid_pose_from_pdb( pose_in, filename );
213  runtime_assert( end_ <= pose_in.total_residue() );
214  for( Size c=0; c<steal_times_; c++ ){
215  set_fragments( pose_in, fragset );
216  }
217  }
218 
219  }else if( read_type_ == "fragfile" ){
220 
221  using core::fragment::Frame;
229 
230  FragSetOP fset = FragmentIO().read_data( filename_ );
231  ConstantLengthFragSetOP cf = dynamic_cast< ConstantLengthFragSet * >( fset.get() );
232  OrderedFragSetOP of = dynamic_cast< OrderedFragSet * >( fset.get() );
233 
234  FrameList frames;
235  if ( cf.get() != NULL && of.get() == NULL ) {
236  for( FrameIterator it=cf->begin(), end( cf->end() ); it!=end; ++it ) {
237  frames.push_back( new Frame( **it ) );
238  }
239  } else if ( of.get() != NULL && cf.get() == NULL ) {
240  for( FrameIterator it=of->begin(), end( of->end() ); it!=end; ++it ) {
241  frames.push_back( new Frame( **it ) );
242  }
243  } else {
244  TR << "[ ERROR ] FragmentIO returned not proper fragset. See the code." << std::endl;
245  runtime_assert( false );
246  }
247  fragset->add( frames );
248 
249  }else if( read_type_ == "vall" ){
250 
251  using core::fragment::Frame;
257 
258  FrameList frames;
259  Size length = end_ - begin_ + 1;
260  for ( Size j = 0, je = length; j < je; ++j ) {
261 
262  TR << "picking " << nfrags_ << " " << frag_size_ << "-mers for position " << ( begin_ + j ) << std::endl;
263  String ss_sub = ss_.substr( j, frag_size_ );
264  if ( ss_sub.length() < frag_size_ ) {
265  ss_sub.append( frag_size_ - ss_sub.length(), 'D' );
266  }
267 
268  // make fragments with sequence bias
269  String aa_sub;
270  if ( !aa_.empty() ) {
271  aa_sub = aa_.substr( j, frag_size_ );
272  if ( aa_sub.length() < frag_size_ ) {
273  aa_sub.append( frag_size_ - aa_sub.length(), '.' );
274  }
275  } else {
276  aa_sub = "";
277  }
278 
279  // make fragments with abego bias
280  utility::vector1< String > abego_sub;
281  if( use_abego_ ) {
282  runtime_assert( ss_.length() == blueprint_->abego().size() );
283  Size pos( 1 );
284  abego_sub.resize( frag_size_ );
285  for( Size ii = j + 1 ; ii <= j + frag_size_; ++ii, ++pos ) {
286  if ( ii > blueprint_->abego().size() ) {
287  abego_sub[ pos ] = "X";
288  } else {
289  abego_sub[ pos ] = blueprint_->abego( ii );
290  }
291  }
292  } else {
293  abego_sub.clear();
294  }
295 
296  FrameOP frame = new Frame( begin_ + j, frag_size_ );
297 
298  frame->add_fragment( pick_fragments( ss_sub, aa_sub, abego_sub, nfrags_, true, IndependentBBTorsionSRFD() ) );
299 
300 // if ( !aa_.empty() ) { // make fragments with sequence bias
301 // String aa_sub = aa_.substr( j, frag_size_ );
302 // if ( aa_sub.length() < frag_size_ ) {
303 // aa_sub.append( frag_size_ - aa_sub.length(), '.' );
304 // }
305 // frame->add_fragment( pick_fragments_by_ss_plus_aa( ss_sub, aa_sub, nfrags_, true, IndependentBBTorsionSRFD() ) );
306 // } else {
307 // frame->add_fragment( pick_fragments_by_ss( ss_sub, nfrags_, true, IndependentBBTorsionSRFD() ) );
308 // }
309 
310  frames.push_back( frame );
311  }
312  fragset->add( frames );
313 
314  }
315 
316 }
317 
318 } //namespace parser
319 } //namespace jd2
320 } //namespace protocols
321