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 <basic/options/option.hh>
24 #include <core/io/pdb/pose_io.hh>
25 #include <utility/io/ozstream.hh>
26 
27 #include <core/sequence/util.hh>
28 #include <core/sequence/Sequence.hh>
29 #include <core/sequence/SequenceAlignment.hh>
31 
32 
33 #include <core/pose/Pose.hh>
34 #include <core/pose/Pose.fwd.hh>
35 #include <core/pose/annotated_sequence.hh>
36 
37 #include <protocols/comparative_modeling/PartialThreadingMover.hh>
38 
39 #include <utility/exit.hh>
40 #include <utility/vector1.hh>
41 #include <utility/string_util.hh>
42 #include <utility/file/FileName.hh>
44 
47 
48 // C++ headers
49 #include <map>
50 #include <iostream>
51 #include <string>
52 
53 #include <basic/options/keys/in.OptionKeys.gen.hh>
54 #include <basic/options/keys/cm.OptionKeys.gen.hh>
55 
56 #include <core/import_pose/import_pose.hh>
57 
58 //Auto Headers
59 #include <core/conformation/Residue.hh>
60 #include <core/kinematics/Jump.hh>
61 
62 
63 std::map< std::string, core::pose::Pose >
65  utility::vector1< std::string > const & fn_list
66 ) {
67  using std::map;
68  using std::string;
69  using core::pose::Pose;
71  using utility::vector1;
72  using core::import_pose::pose_from_pdb;
73  using namespace core::chemical;
74 
75  ResidueTypeSetCOP rsd_set( rsd_set_from_cmd_line() );
76  map< string, Pose > poses;
77 
79  for ( iter it = fn_list.begin(), end = fn_list.end(); it != end; ++it ) {
80  if ( file_exists(*it) ) {
81  Pose pose;
82  core::import_pose::pose_from_pdb( pose, *rsd_set, *it );
83  string name = utility::file_basename( *it );
84  name = name.substr( 0, 5 );
85  poses[name] = pose;
86  }
87  }
88 
89  return poses;
90 }
91 
92 int
93 main( int argc, char* argv [] ) {
94  try{
95  // options, random initialization
96  devel::init( argc, argv );
97 
98  using std::map;
99  using std::string;
100  using core::Real;
101  using core::Size;
102  using core::pose::Pose;
103  using core::pose::PoseOP;
104  using utility::vector1;
105  using core::import_pose::pose_from_pdb;
106  using core::pose::make_pose_from_sequence;
107  using protocols::comparative_modeling::PartialThreadingMover;
108 
109  using namespace basic::options;
110  using namespace basic::options::OptionKeys;
111  using namespace core::chemical;
112  using namespace core::sequence;
113 
114  basic::Tracer tr( "partial_thread" );
115 
116  SequenceOP fasta_seq = core::sequence::read_fasta_file(
117  option[ in::file::fasta ]()[1]
118  )[1];
119 
120 
121  vector1< string > align_fns = option[ in::file::alignment ]();
122 
123  map< string, Pose > poses = poses_from_cmd_line(
124  option[ in::file::template_pdb ]()
125  );
126 
127  typedef vector1< string >::const_iterator aln_iter;
128  // in this block, when compiler sees aln_iter, it converts to
129  // vector1< string >::const_iterator. We could have used this:
130  // vector1< string >::iterator. We do not, because we don't want
131  // to change the vector1< string >. This is called "const-correctness"
132  // in C++, and is a very important topic.
133  //
134  // equivalent to:
135  //for ( vector1< string >::const_iterator aln_fn = aln_fns.begin(),
136  // aln_end = aln_fns.end();
137  // aln_fn != aln_end; ++aln_fn )
138  for ( aln_iter aln_fn = align_fns.begin(), aln_end = align_fns.end();
139  aln_fn != aln_end; ++aln_fn
140  ) {
141  vector1< SequenceAlignment > alns = core::sequence::read_aln(
142  option[ cm::aln_format ](), *aln_fn
143  );
144 
145  for ( vector1< SequenceAlignment >::iterator it = alns.begin(),
146  end = alns.end();
147  it != end; ++it
148  ) {
149  string const template_id( it->sequence(2)->id().substr(0,5) );
150  tr << *it << std::endl;
151  tr << "id " << it->sequence(2)->id() << " => " << template_id
152  << std::endl;
153  string const ungapped_query( it->sequence(1)->ungapped_sequence() );
154 
155  // calc rmsd/gdt stats
156  map< string, Pose >::iterator pose_it = poses.find( template_id );
157  if ( pose_it == poses.end() ) {
158  string msg( "Error: can't find pose (id = "
159  + template_id + ")"
160  );
161  //utility_exit_with_message(msg);
162  tr.Error << msg << std::endl;
163  } else {
164  Pose query_pose, template_pose;
165  make_pose_from_sequence(
166  query_pose,
167  //ungapped_query,
168  fasta_seq->sequence(),
169  *(rsd_set_from_cmd_line().lock())
170  );
171  template_pose = pose_it->second;
172  PartialThreadingMover mover(*it,template_pose);
173  mover.apply(query_pose);
174  // line below is equivalent to this:
175  //(*(*it).sequence(2)).id();
176  // so the object->method() is syntax for saying (*object).method()
177  string const id_out( it->sequence(2)->id() );
178  //query_pose.dump_pdb(id_out + ".pdb");
179 
180  // print out query-anchored alignment
181  utility::io::ozstream output( id_out + ".pdb" );
182  core::id::SequenceMapping map( it->sequence_mapping(1,2) );
183  output << "REMARK query_anchored_aln ";
184  for ( core::Size ii = 1; ii <= fasta_seq->sequence().size(); ++ii ) {
185  if ( map[ii] ) output << fasta_seq->at(ii);
186  else output << "-";
187  }
188  output << std::endl;
189  core::io::pdb::dump_pdb( query_pose, output );
190  output.close();
191 
192  } // template pdb check
193  } // alns
194  } // for ( it in aligns )
195 
196  tr.Debug << "finished building partial models." << std::endl;
197  tr.flush_all_channels();
198  } catch ( utility::excn::EXCN_Base const & e ) {
199  std::cout << "caught exception " << e.msg() << std::endl;
200  return -1;
201  }
202 } // 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:369
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