Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RNA_JumpLibrary.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 Library of RNA base pair jumps
11 /// @brief protocols that are specific to RNA_JumpLibrary
12 /// @detailed
13 /// @author Rhiju Das
14 
15 
16 // Rosetta Headers
18 
19 #include <utility/io/izstream.hh>
20 #include <utility/exit.hh>
21 
22 #include <numeric/random/random.hh>
23 
24 #include <core/types.hh>
25 #include <basic/Tracer.hh>
26 
27 // C++ headers
28 #include <fstream>
29 #include <iostream>
30 
31 #include <utility/vector1.hh>
32 
33 
34 
35 namespace protocols {
36 namespace rna {
37 
38 /// @details Auto-generated virtual destructor
40 
41 /// @details Auto-generated virtual destructor
43 
44 static numeric::random::RandomGenerator RG(144621); // <- Magic number, do not change it!
45 
46 static basic::Tracer tr( "protocols.rna.rna_jump_library" ) ;
47 
48 //@brief constructor
50  core::kinematics::Jump const j,
51  std::string const atom_name1,
52  std::string const atom_name2 ):
53  jump_forward_ ( j ),
54  jump_backward_( j ),
55  atom_name1_( atom_name1 ),
56  atom_name2_( atom_name2 )
57 {}
58 
59 //@brief constructor
61  core::kinematics::Jump const j1,
62  core::kinematics::Jump const j2,
63  std::string const atom_name1,
64  std::string const atom_name2 ):
65  jump_forward_ ( j1 ),
66  jump_backward_( j2 ),
67  atom_name1_( atom_name1 ),
68  atom_name2_( atom_name2 )
69 {}
70 
71 /////////////////////////////////////////////////////////////////////////////////////
72 void
73 RNA_JumpLibrary::read_jumps_from_file( std::string const & jump_library_filename )
74 {
75 
76  utility::io::izstream data( jump_library_filename );
77  tr << "Reading RNA jump library: " << jump_library_filename << std::endl;
78 
79  if ( data.fail() ) {
80  utility_exit_with_message( "Bad jumpdata file? " + jump_library_filename );
81  }
82 
83  std::string line;
85  Size pos1,pos2;
86  char reschar1,reschar2,edgechar1,edgechar2,orientation;
87  core::kinematics::Jump jump1, jump2;
88 
89  char tmpbuf[ 4 ];
90 
91  while ( getline( data,line ) ) {
92  std::istringstream is( line );
93 
94  is >> tag >>
95  pos1 >> edgechar1 >> pos2 >> edgechar2 >>
96  orientation >> reschar1 >> reschar2;
97 
98  // std::cout << "READ IN: " << reschar1 << " " << reschar2 << std::endl;
99 
100  is.read( tmpbuf, 1 );
101  is.read( tmpbuf, 4 );
102  std::string atom_name1 = "";
103  for (int n=0; n <4;n++) atom_name1 += tmpbuf[n];
104 
105  is.read( tmpbuf, 1 );
106  is.read( tmpbuf, 4 );
107  std::string atom_name2 = "";
108  for (int n=0; n <4;n++) atom_name2 += tmpbuf[n];
109 
110  // std::cout << "READ IN ATOM NAMES? " << atom_name1 << " " << atom_name2 << std::endl;
111 
112  if ( is.fail() || tag != "PAIR" ) continue;
113 
114  is >> jump1;
115 
116  if ( edgechar1 == 'P' || edgechar2 == 'P' ) {
117  is >> jump2;
118  } else {
119  jump2 = jump1;
120  }
121 
122  save_in_jump_library( reschar1, reschar2,
123  edgechar1, edgechar2,
124  orientation,
125  atom_name1, atom_name2,
126  jump1, jump2 );
127 
128  jump1.reverse();
129  jump2.reverse();
130 
131  save_in_jump_library( reschar2, reschar1,
132  edgechar2, edgechar1,
133  orientation,
134  atom_name2, atom_name1,
135  jump1, jump2 );
136 
137  }
138 
139 }
140 
141 /////////////////////////////////////////////////////////////////////////////////////
142 // This is a lot of work just to get base-phosphate jumps...
143 void
145  std::string & atom_name,
146  bool const forward,
149 {
150  if (atom_name == " ? " ) {
151  if ( forward ) {
152  atom_name = " O5*";
153  } else {
154  atom_name = " O3*";
155  j = t->jump_backward();
156  }
157  }
158 }
159 
160 
161 /////////////////////////////////////////////////////////////////////////////////////
164  char const aa1,
165  char const aa2,
166  char const edge1,
167  char const edge2,
168  char const orientation,
169  std::string & atom_name1,
170  std::string & atom_name2,
171  bool & success,
172  bool const forward1 /*= true*/,
173  bool const forward2 /*= true*/ ) const
174 {
175  // key for looking up the template geometry:
176  BasePairType key( aa1, aa2, edge1, edge2, orientation);
177  Size ntemplates = 0;
178 
179 
180  if( rna_pairing_template_map_.find( key ) == rna_pairing_template_map_.end() ){
181 
182  std::cout << "Can't seem to find a pairing inside database with aa1: " << aa1 << " aa2: " << aa2 << " edge1: " << edge1 << " edge2: " << edge2 << " orientation: " << orientation << std::endl;
183 
184  std::cerr << "Can't seem to find a pairing inside database with aa1: " << aa1 << " aa2: " << aa2 << " edge1: " << edge1 << " edge2: " << edge2 << " orientation: " << orientation << std::endl;
185 
186  // utility::exit( EXIT_FAILURE, __FILE__, __LINE__);
187  success = false;
188  atom_name1 = "XXXX";
189  atom_name2 = "XXXX";
190  return core::kinematics::Jump(); //default garbage jump.
191 
192  }
193 
194  RNA_PairingTemplateList const & templates( rna_pairing_template_map_.find( key )->second );
195 
196  ntemplates = templates.size();
197 
198  if( ntemplates < 1 ){
199 
200  std::cout << "Can't seem to find a pairing inside database with aa1: " << aa1 << " aa2: " << aa2 << " edge1: " << edge1 << " edge2: " << edge2 << " orientation: " << orientation << std::endl;
201 
202  std::cerr << "Can't seem to find a pairing inside database with aa1: " << aa1 << " aa2: " << aa2 << " edge1: " << edge1 << " edge2: " << edge2 << " orientation: " << orientation << std::endl;
203 
204  // utility::exit( EXIT_FAILURE, __FILE__, __LINE__);
205  success = false;
206  atom_name1 = "XXXX";
207  atom_name2 = "XXXX";
208  return core::kinematics::Jump(); //default garbage jump.
209 
210  }
211 
212  Size const index( static_cast<Size>( RG.uniform() * ntemplates ) + 1 );
213 
214  core::kinematics::Jump j ( templates[ index ]->jump() );
215  atom_name1 = templates[ index ]->atom_name1();
216  atom_name2 = templates[ index ]->atom_name2();
217 
218  //Currently if we connect to a main chain atom -- e.g., phosphate,
219  // the jump transformation depends on whether we're going forward or backward.
220  // This is encoded as an atom name of "?"
221  // Following seems a little inelegant right now.
222  // Also, currently only allows only one of the partners to
223  // be on the RNA backbone. Again, inelegant.
224  // runtime_assert( atom_name1 != " ? " || atom_name2 != " ? " );
225  // check_forward_backward( atom_name1, forward1, j, templates[ index ] );
226  // check_forward_backward( atom_name2, forward2, j, templates[ index ] );
227  runtime_assert( edge1 != 'P' || edge2 != 'P' );
228  if ( edge1 == 'P' && !forward1 ) j = templates[ index ]->jump_backward();
229  if ( edge2 == 'P' && !forward2 ) j = templates[ index ]->jump_backward();
230 
231  success = true;
232 
233  return j;
234 }
235 
236 /////////////////////////////////////////////////////////////////////////////////////
237 void
239  Size const reschar1, Size const reschar2,
240  char const edgechar1, char const edgechar2,
241  char const orientation,
242  std::string const & atom_name1,
243  std::string const & atom_name2,
244  core::kinematics::Jump const & jump1,
245  core::kinematics::Jump const & jump2
246  )
247 {
248 
249  RNA_PairingTemplateOP p( new RNA_PairingTemplate( jump1, jump2, atom_name1, atom_name2) );
250 
251  // std::cout << "JUMPY! " << reschar1 << " " << reschar2 << " " << edgechar1 << " " << edgechar2 << " " << orientation << " " << jump << std::endl;
252 
253  // fill in a new base-pairing template
254  // Pairing_template_RNA t( Epos1, Epos2);
255 
256  // Base_pair_type base_pair_type( reschar1, reschar2, edgechar1, edgechar2, orientation);
257  // pairing_template_map_RNA[ base_pair_type ].push_back( t );
258 
259  // Save to template lists with wildcards ('X') too.
260  for ( Size i = 0; i <= 1; i++ ) {
261 
262  char const edgechar1_temp = i ? edgechar1:'X';
263 
264  for ( Size j = 0; j <= 1; j++ ) {
265 
266  char const edgechar2_temp = j ? edgechar2:'X';
267 
268  for ( Size k = 0; k <= 1; k++ ) {
269 
270  char const orientation_temp = k ? orientation:'X';
271 
272  BasePairType base_pair_type( reschar1, reschar2, edgechar1_temp, edgechar2_temp, orientation_temp);
273  rna_pairing_template_map_[ base_pair_type ].push_back( p );
274 
275  }
276  }
277  }
278 }
279 
280 
281 }
282 }