Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FastaInputter.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/inputter/FastaInputter.cc
11 /// @brief An inputter that takes a list of fasta
12 /// @author Ken Jung
13 
14 // Unit Headers
18 #include <core/pose/Pose.hh>
19 #include <utility/lua/LuaIterator.hh>
20 
22 #include <core/sequence/util.hh>
23 
24 #include <core/pose/util.hh>
25 #include <utility/string_util.hh>
26 // tracer
27 #include <basic/Tracer.hh>
28 
29 using core::Size;
30 
31 namespace protocols {
32 namespace inputter {
33 
34 static basic::Tracer TR("protocols.inputter.FastaInputter");
35 
36 #ifdef USELUA
37 void lregister_FastaInputter( lua_State * lstate ) {
38  lregister_Inputter( lstate );
39  luabind::module(lstate, "protocols")
40  [
41  luabind::namespace_("inputter")
42  [
43  luabind::class_<FastaInputter, Inputter>("FastaInputter")
44  ]
45  ];
46 }
47 #endif
48 
50 
52  offset_ = true;
54  core::pose::PoseSP tmppose(new core::pose::Pose());
55  if( multiply_over_all_ ) {
56  // we go through all the filenames once, then more times according to multiplier
57  for( int i = 1; i<n; i++){
58  file_names_[curr_idx_].first++;
59  if( file_names_[curr_idx_].first >= multiplier_ ) {
60  // this only can happen when curr_idx_ == 0
61  file_names_.pop_front();
62  } else {
63  curr_idx_++;
64  curr_idx_ = curr_idx_ == file_names_.size() ? 0 : curr_idx_;
65  }
66  }
67  // assume each fasta file only holds one sequence
69  core::pose::make_pose_from_sequence( *tmppose, sequences[1], *residue_set );
70  for (core::Size i = 1; i <= tmppose->total_residue(); ++i) {
71  tmppose->set_phi(i, -150);
72  tmppose->set_psi(i, 150);
73  tmppose->set_omega(i, 180);
74  }
75  file_names_[curr_idx_].first++;
76  core::pose::add_comment( *tmppose, "inputfile", file_names_[curr_idx_].second );
77  core::pose::add_comment( *tmppose, "filemultiplier", utility::to_string(file_names_[curr_idx_].first) );
78  if( file_names_[curr_idx_].first >= multiplier_ ) {
79  // this only can happen when curr_idx_ == 0
80  file_names_.pop_front();
81  } else {
82  curr_idx_++;
83  curr_idx_ = curr_idx_ == file_names_.size() ? 0 : curr_idx_;
84  }
85  return tmppose;
86  } else {
87  // we go through each file name MULTIPLIER times, then pop it
88  for( int i = 1; i<n; i++){
89  file_names_.front().first++;
90  if( file_names_.front().first >= multiplier_ )
91  file_names_.pop_front();
92  }
93  // assume each fasta file only holds one sequence
95  core::pose::make_pose_from_sequence( *tmppose, sequences[1], *residue_set );
96  for (core::Size i = 1; i <= tmppose->total_residue(); ++i) {
97  tmppose->set_phi(i, -150);
98  tmppose->set_psi(i, 150);
99  tmppose->set_omega(i, 180);
100  }
101  file_names_.front().first++;
102  core::pose::add_comment( *tmppose, "inputfile", file_names_.front().second );
103  core::pose::add_comment( *tmppose, "file_multiplier", utility::to_string(file_names_.front().first) );
104  if( file_names_.front().first >= multiplier_ )
105  file_names_.pop_front();
106  return tmppose;
107  }
108 }
109 
111  int sum = 0;
112  for( Size i = 0; i < file_names_.size(); i++ ) {
113  sum += (multiplier_ - file_names_[i].first );
114  if (sum >= n )
115  return true;
116  }
117  return false;
118 }
119 
121  return InputterSP( new FastaInputter() );
122 }
123 
124 #ifdef USELUA
125 void FastaInputter::parse_def( utility::lua::LuaObject const & def,
126  utility::lua::LuaObject const & tasks,
127  utility::lua::LuaObject & inputters ) {
128  residue_set_ = def["residue_set"] ? def["residue_set"].to<std::string>() : "centroid";
129  if( def["multiplier"] ) multiplier_ = def["multiplier"].to<int>();
130  if( def["multiply_over_all"] ) multiply_over_all_ = def["multiply_over_all"].to<bool>();
131  for (utility::lua::LuaIterator i=def["filelist"].begin(), end; i != end; ++i) {
132  file_names_.push_back( std::pair<int, std::string> ( 0, (*i).to<std::string>()) );
133  }
134 }
135 
136 void FastaInputter::lregister( lua_State * lstate ) {
137  lregister_FastaInputter( lstate );
138 }
139 #endif
140 } // inputter
141 } // protocols