Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
partial_thread.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 partial_thread.cc
11 /// @brief
12 /// @author James Thompson
13 /// @author Ray Wang
14 
15 #include <core/types.hh>
16 #include <devel/init.hh>
17 
18 #include <basic/Tracer.hh>
19 
20 #include <core/chemical/util.hh>
21 
22 #include <core/id/SequenceMapping.hh>
23 #include <core/io/pdb/pdb_writer.hh>
24 
25 #include <basic/options/option.hh>
26 
27 #include <utility/io/ozstream.hh>
28 
29 #include <core/sequence/util.hh>
30 #include <core/sequence/Sequence.hh>
31 #include <core/sequence/SequenceAlignment.hh>
33 
34 
35 #include <core/pose/Pose.hh>
36 #include <core/pose/Pose.fwd.hh>
37 #include <core/pose/annotated_sequence.hh>
38 
39 #include <protocols/comparative_modeling/PartialThreadingMover.hh>
40 
41 #include <utility/exit.hh>
42 #include <utility/vector1.hh>
43 #include <utility/string_util.hh>
44 #include <utility/file/FileName.hh>
46 
49 
50 // C++ headers
51 #include <map>
52 #include <iostream>
53 #include <string>
54 
57 
58 #include <core/import_pose/import_pose.hh>
59 
60 //Auto Headers
61 #include <core/conformation/Residue.hh>
62 #include <core/kinematics/Jump.hh>
63 
64 
65 std::map< std::string, core::pose::Pose >
67  utility::vector1< std::string > const & fn_list
68 ) {
69  using std::map;
70  using std::string;
71  using core::pose::Pose;
73  using utility::vector1;
74  using core::import_pose::pose_from_file;
75  using namespace core::chemical;
76 
77  ResidueTypeSetCOP rsd_set( rsd_set_from_cmd_line() );
78  map< string, Pose > poses;
79 
81  for ( iter it = fn_list.begin(), end = fn_list.end(); it != end; ++it ) {
82  if ( file_exists(*it) ) {
83  Pose pose;
84  core::import_pose::pose_from_file( pose, *rsd_set, *it , core::import_pose::PDB_file);
85  string name = utility::file_basename( *it );
86  name = name.substr( 0, 5 );
87  poses[name] = pose;
88  }
89  }
90 
91  return poses;
92 }
93 
94 int
95 main( int argc, char* argv [] ) {
96  try{
97  // options, random initialization
98  devel::init( argc, argv );
99 
100  using std::map;
101  using std::string;
102  using core::Real;
103  using core::Size;
104  using core::pose::Pose;
105  using core::pose::PoseOP;
106  using utility::vector1;
107  using core::import_pose::pose_from_file;
108  using core::pose::make_pose_from_sequence;
109  using protocols::comparative_modeling::PartialThreadingMover;
110 
111  using namespace basic::options;
112  using namespace basic::options::OptionKeys;
113  using namespace core::chemical;
114  using namespace core::sequence;
115 
116  basic::Tracer tr( "partial_thread" );
117 
118  SequenceOP fasta_seq = core::sequence::read_fasta_file(
119  option[ in::file::fasta ]()[1]
120  )[1];
121 
122 
123  vector1< string > align_fns = option[ in::file::alignment ]();
124 
125  map< string, Pose > poses = poses_from_cmd_line(
127  );
128 
129  typedef vector1< string >::const_iterator aln_iter;
130  // in this block, when compiler sees aln_iter, it converts to
131  // vector1< string >::const_iterator. We could have used this:
132  // vector1< string >::iterator. We do not, because we don't want
133  // to change the vector1< string >. This is called "const-correctness"
134  // in C++, and is a very important topic.
135  //
136  // equivalent to:
137  //for ( vector1< string >::const_iterator aln_fn = aln_fns.begin(),
138  // aln_end = aln_fns.end();
139  // aln_fn != aln_end; ++aln_fn )
140  for ( aln_iter aln_fn = align_fns.begin(), aln_end = align_fns.end();
141  aln_fn != aln_end; ++aln_fn
142  ) {
143  vector1< SequenceAlignment > alns = core::sequence::read_aln(
144  option[ cm::aln_format ](), *aln_fn
145  );
146 
147  for ( vector1< SequenceAlignment >::iterator it = alns.begin(),
148  end = alns.end();
149  it != end; ++it
150  ) {
151  string const template_id( it->sequence(2)->id().substr(0,5) ); //Why in the world do we only use 5 residues. Lets split the string and go from there.
152 
153 
154  tr << *it << std::endl;
155  tr << "id " << it->sequence(2)->id() << " => " << template_id
156  << std::endl;
157  string const ungapped_query( it->sequence(1)->ungapped_sequence() );
158 
159  // calc rmsd/gdt stats
160  map< string, Pose >::iterator pose_it = poses.find( template_id );
161  if ( pose_it == poses.end() ) {
162  string msg( "Error: can't find pose (id = "
163  + template_id + ")"
164  );
165  //utility_exit_with_message(msg);
166  tr.Error << msg << std::endl;
167  } else {
168  Pose query_pose, template_pose;
169  make_pose_from_sequence(
170  query_pose,
171  //ungapped_query,
172  fasta_seq->sequence(),
173  *(rsd_set_from_cmd_line().lock())
174  );
175  template_pose = pose_it->second;
176  PartialThreadingMover mover(*it,template_pose);
177  mover.apply(query_pose);
178  // line below is equivalent to this:
179  //(*(*it).sequence(2)).id();
180  // so the object->method() is syntax for saying (*object).method()
181  string const id_out( it->sequence(2)->id() );
182  //query_pose.dump_pdb(id_out + ".pdb");
183 
184  // print out query-anchored alignment
185  utility::io::ozstream output( id_out+".pdb" ); //This is stupid. new branch to fix this.
186 
187  core::id::SequenceMapping map( it->sequence_mapping(1,2) );
188  output << "REMARK query_anchored_aln ";
189  for ( core::Size ii = 1; ii <= fasta_seq->sequence().size(); ++ii ) {
190  if ( map[ii] ) output << fasta_seq->at(ii);
191  else output << "-";
192  }
193  output << std::endl;
194  core::io::pdb::dump_pdb( query_pose, output );
195  output.close();
196 
197  } // template pdb check
198  } // alns
199  } // for ( it in aligns )
200 
201  tr.Debug << "finished building partial models." << std::endl;
202  tr.flush_all_channels();
203  } catch ( utility::excn::EXCN_Base const & e ) {
204  std::cout << "caught exception " << e.msg() << std::endl;
205  return -1;
206  }
207 } // int main( int argc, char * argv [] )
StringOptionKey const aln_format
virtual std::string const msg() const
Definition: EXCN_Base.hh:70
utility::keys::KeyLookup< KeyType >::const_iterator const_iterator
Key collection iterators.
void init(int argc, char *argv[])
Command line init() version.
Definition: init.cc:23
FileVectorOptionKey const template_pdb
core::pose::Pose Pose
Definition: supercharge.cc:101
Platform independent operations on files (except I/O)
FileVectorOptionKey const fasta
int main(int argc, char *argv[])
basic::options::OptionKeys collection
common derived classes for thrown exceptions
void flush_all_channels()
flush tracer buffer and flush buffers of all sub-channels ie: Fatal, Error, Warning, Info, Debug, Trace
Definition: Tracer.cc:319
std::string file_basename(const std::string &full_path)
Definition: string_util.cc:428
std::map< std::string, core::pose::Pose > poses_from_cmd_line(utility::vector1< std::string > const &fn_list)
FileVectorOptionKey const alignment
Program exit functions and macros.
Tracer IO system.
BooleanOptionKey const sequence
TracerProxy Error
Definition: Tracer.hh:262
File name class supporting Windows and UN*X/Linux format names.
basic::options::OptionKeys collection
rule< Scanner, options_closure::context_t > options
Definition: Tag.cc:377
utility::options::OptionCollection option
OptionCollection global.
Definition: option.cc:46
Output file stream wrapper for uncompressed and compressed files.
double Real
Definition: types.hh:39
ocstream cout(std::cout)
Wrapper around std::cout.
Definition: ocstream.hh:287
vector1: std::vector with 1-based indexing
Class for handling user debug/warnings/errors. Use instance of this class instead of 'std::cout' for ...
Definition: Tracer.hh:134
bool file_exists(std::string const &path)
Does File Exist?
rule< Scanner, string_closure::context_t > name
Definition: Tag.cc:376
ozstream: Output file stream wrapper for uncompressed and compressed files
Definition: ozstream.hh:53
Some std::string helper functions.
Program options global and initialization function.
THREAD_LOCAL basic::Tracer tr("struc_set_fragment_picker")
BooleanOptionKey const chemical
StringOptionKey const output
Definition: contacts.py:31
platform::Size Size
Definition: random.fwd.hh:30
TracerProxy Debug
Definition: Tracer.hh:262