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 
55 #include <basic/options/keys/in.OptionKeys.gen.hh>
56 #include <basic/options/keys/cm.OptionKeys.gen.hh>
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(
126  option[ in::file::template_pdb ]()
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) );
152  tr << *it << std::endl;
153  tr << "id " << it->sequence(2)->id() << " => " << template_id
154  << std::endl;
155  string const ungapped_query( it->sequence(1)->ungapped_sequence() );
156 
157  // calc rmsd/gdt stats
158  map< string, Pose >::iterator pose_it = poses.find( template_id );
159  if ( pose_it == poses.end() ) {
160  string msg( "Error: can't find pose (id = "
161  + template_id + ")"
162  );
163  //utility_exit_with_message(msg);
164  tr.Error << msg << std::endl;
165  } else {
166  Pose query_pose, template_pose;
167  make_pose_from_sequence(
168  query_pose,
169  //ungapped_query,
170  fasta_seq->sequence(),
171  *(rsd_set_from_cmd_line().lock())
172  );
173  template_pose = pose_it->second;
174  PartialThreadingMover mover(*it,template_pose);
175  mover.apply(query_pose);
176  // line below is equivalent to this:
177  //(*(*it).sequence(2)).id();
178  // so the object->method() is syntax for saying (*object).method()
179  string const id_out( it->sequence(2)->id() );
180  //query_pose.dump_pdb(id_out + ".pdb");
181 
182  // print out query-anchored alignment
183  utility::io::ozstream output( id_out + ".pdb" );
184  core::id::SequenceMapping map( it->sequence_mapping(1,2) );
185  output << "REMARK query_anchored_aln ";
186  for ( core::Size ii = 1; ii <= fasta_seq->sequence().size(); ++ii ) {
187  if ( map[ii] ) output << fasta_seq->at(ii);
188  else output << "-";
189  }
190  output << std::endl;
191  core::io::pdb::dump_pdb( query_pose, output );
192  output.close();
193 
194  } // template pdb check
195  } // alns
196  } // for ( it in aligns )
197 
198  tr.Debug << "finished building partial models." << std::endl;
199  tr.flush_all_channels();
200  } catch ( utility::excn::EXCN_Base const & e ) {
201  std::cout << "caught exception " << e.msg() << std::endl;
202  return -1;
203  }
204 } // int main( int argc, char * argv [] )
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
core::pose::Pose Pose
Definition: supercharge.cc:101
utility::keys::lookup::end< KeyType > const end
string output
Definition: contacts.py:31
Platform independent operations on files (except I/O)
int main(int argc, char *argv[])
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:313
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)
Program exit functions and macros.
Tracer IO system.
TracerProxy Error
Definition: Tracer.hh:262
File name class supporting Windows and UN*X/Linux format names.
rule< Scanner, options_closure::context_t > options
Definition: Tag.cc:377
utility::options::OptionCollection option
OptionCollection global.
Definition: option.cc:45
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")
platform::Size Size
Definition: random.fwd.hh:30
TracerProxy Debug
Definition: Tracer.hh:262