Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StepWiseRNA_ResidueInfo.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 StepWise_ResidueInfo.cc
11 /// @brief Function used by the residue_info data structure
12 /// @detailed
13 /// @author Parin Sripakdeevong
14 
15 
16 //////////////////////////////////
19 //////////////////////////////////
20 #include <ObjexxFCL/format.hh>
21 #include <ObjexxFCL/string.functions.hh>
22 #include <core/pose/Pose.fwd.hh>
23 #include <core/pose/Pose.hh>
25 #include <string>
26 //#include <core/conformation/ResidueFactory.hh>
28 //#include <core/conformation/ResidueMatcher.hh>
30 
31 #include <iostream>
32 #include <fstream>
33 #include <sstream>
34 #include <utility/vector1.hh>
35 #include <map>
36 
37 
38 using namespace core;
39 using namespace ObjexxFCL;
40 
41 namespace protocols {
42 namespace swa {
43 namespace rna {
44 
45  void
46  Print_torsion_info(core::pose::Pose const & pose, core::Size const seq_num, core::Size const rna_torsion_number, std::string const type){
47 
48  using namespace core::id;
49  using namespace core::chemical;
50  using namespace core::conformation;
51 // using namespace protocols::rna;
52 
53  id::TorsionID torsion_id;
54  Real torsion_angle;
55  if(type=="back_bone"){
56  torsion_id = id::TorsionID( seq_num, id::BB, rna_torsion_number);
57  torsion_angle=pose.residue(seq_num).mainchain_torsion(rna_torsion_number);
58  }else if(type=="side_chain"){
59  torsion_id = id::TorsionID( seq_num, id::CHI, rna_torsion_number);
60  torsion_angle=pose.residue(seq_num).chi(rna_torsion_number);
61  }else{
62  std::cout << "In Print_torsion_info, invalid torsion_type: " << type << std::endl;
63  exit(1);
64  }
65 
66  std::cout << "Torsion angle= " << torsion_angle << std::endl;
67 
68  id::AtomID id1,id2,id3,id4;
69  bool fail = pose.conformation().get_torsion_angle_atom_ids( torsion_id, id1, id2, id3, id4 );
70  if(fail){
71  std::cout << "In Print_torsion_info, would not get torsion angle atom ids: " << std::endl;
72  exit(1);
73  }
74 
75  conformation::Residue const & rsd_1=pose.residue(id1.rsd());
76  conformation::Residue const & rsd_2=pose.residue(id2.rsd());
77  conformation::Residue const & rsd_3=pose.residue(id3.rsd());
78  conformation::Residue const & rsd_4=pose.residue(id4.rsd());
79 
80  std::cout << "atom " << id1.atomno() << " " << "name= " << rsd_1.type().atom_name(id1.atomno()) << " type= " << rsd_1.atom_type(id1.atomno()).name() << " " << rsd_1.atom_type_index(id1.atomno()) << " " << rsd_1.atomic_charge(id1.atomno()) << std::endl;
81  std::cout << "atom " << id2.atomno() << " " << "name= " << rsd_2.type().atom_name(id2.atomno()) << " type= " << rsd_2.atom_type(id2.atomno()).name() << " " << rsd_2.atom_type_index(id2.atomno()) << " " << rsd_2.atomic_charge(id2.atomno()) << std::endl;
82  std::cout << "atom " << id3.atomno() << " " << "name= " << rsd_3.type().atom_name(id3.atomno()) << " type= " << rsd_3.atom_type(id3.atomno()).name() << " " << rsd_3.atom_type_index(id3.atomno()) << " " << rsd_3.atomic_charge(id3.atomno()) << std::endl;
83  std::cout << "atom " << id4.atomno() << " " << "name= " << rsd_4.type().atom_name(id4.atomno()) << " type= " << rsd_4.atom_type(id4.atomno()).name() << " " << rsd_4.atom_type_index(id4.atomno()) << " " << rsd_4.atomic_charge(id4.atomno()) << std::endl;
84 
85  }
86 
87 
89  Convert_rebuild_residue_string_to_list(std::string const& rebuild_residue_string){
90 
91  utility::vector1 <Residue_info> rebuild_residue_list;
92 
93 // if(rebuild_residue_string=="none"){
94 // return rebuild_residue_list;
95 // }
96 
97  utility::vector1<std::string> nucleotides_token=Tokenize(rebuild_residue_string, "-");
98 
99  for(Size i=1; i<=nucleotides_token.size(); i++){
100 // std::cout<< nucleotides_token[i] << " ";
101 
102  Residue_info res_info;
103  res_info.name=Get_three_letter_name(nucleotides_token[i].substr(0,1));
104  //std::string seq_num_string=nucleotides_token[i].substr(1,2);
105  std::string seq_num_string=nucleotides_token[i].substr(1,nucleotides_token[i].length()-1);
106  res_info.seq_num= string_to_int(seq_num_string);
107  rebuild_residue_list.push_back( res_info);
108 
109  }
110 // std::cout << std::endl;
111 
112  return rebuild_residue_list;
113  }
114 
115 
116  void
118 
119  using namespace ObjexxFCL;
120  using namespace ObjexxFCL::fmt;
121 
122  std::cout << Get_one_letter_name(residue.name);
123  std::cout << lead_zero_string_of(residue.seq_num, 2);
124  std::cout << A(1," ");
125  }
126 
127 
129  Get_one_letter_name(std::string const & three_letter_name){
130  if(three_letter_name=="RAD") return "A";
131  if(three_letter_name=="RCY") return "C";
132  if(three_letter_name=="URA") return "U";
133  if(three_letter_name=="RGU") return "G";
134  std::cout << "In get_one_letter_name_function, an invalid three_letter_name was passed into the function: " << three_letter_name << std::endl;
135  exit (1);
136  }
137 
139  Get_three_letter_name(std::string const & one_letter_name){
140  if(one_letter_name=="A") return "RAD";
141  if(one_letter_name=="C") return "RCY";
142  if(one_letter_name=="U") return "URA";
143  if(one_letter_name=="G") return "RGU";
144  std::cout << "In get_three_letter_name_function, an invalid one_letter_name was passed into the function: " << one_letter_name <<std::endl;
145  exit (1);
146  }
147 
148 
149 
150 
151  Size
152  get_max_seq_num_from_res_map(std::map< core::Size, core::Size > const & my_map){
153 
154  Size max_seq_num=0;
155  for (std::map< Size, Size>::const_iterator it=my_map.begin(); it!=my_map.end(); it++ ){
156  std::cout << it->first << " => " << it->second << std::endl;
157  if(it->first>=max_seq_num) max_seq_num=it->first;
158  }
159  return max_seq_num;
160  }
161 
162  void
163  output_res_map(std::map< core::Size, core::Size > const & my_map, Size const max_seq_num){
164 
165  using namespace ObjexxFCL;
166  using namespace ObjexxFCL::fmt;
167  using namespace std;
168  Size spacing=4;
169  std::cout << std::setw(30) << "full_pose_seq_num:";
170  for(Size seq_num=1; seq_num<=max_seq_num; seq_num++){
171  std::cout << std::setw(spacing) << seq_num;
172  }
173  std::cout << std::endl;
174 
175  std::cout << std::setw(30) << "partial_pose_seq_num:";
176  for(Size seq_num=1; seq_num<=max_seq_num; seq_num++){
177  if(my_map.find(seq_num)!=my_map.end()){
178  std::cout << std::setw(spacing) << my_map.find(seq_num)->second;
179  }else{
180  std::cout << A(spacing,"-");
181  }
182 
183  }
184  std::cout << std::endl;
185 
186  }
187 
188 
189  void
191  using namespace ObjexxFCL;
192  using namespace ObjexxFCL::fmt;
193 
194 
195  sort_residue_list(residue_list); //maybe sure the list is sorted
196 
197  Size seq_num=1;
198  for(Size n=1; n<=residue_list.size(); n++){
199  Residue_info residue=residue_list[n];
200 
201  while(seq_num<residue.seq_num){
202  std::cout << A(4," ");
203  seq_num++;
204  }
205 
206  Output_residue_struct(residue);
207  seq_num++;
208  }
209 
210  std::cout << std::endl;
211 
212  }
213 
215  Get_residue_list_from_fasta(std::string const full_fasta_sequence){
216 
217  utility::vector1< Residue_info > full_residue_list;
218 
219  for(Size n=0; n<=full_fasta_sequence.size()-1; n++){
220  std::string one_letter_name=string_of(full_fasta_sequence[n]);
221  Residue_info residue;
222  residue.seq_num=n+1;
223  if(one_letter_name=="A" || one_letter_name=="a") residue.name="RAD";
224  if(one_letter_name=="C" || one_letter_name=="c") residue.name="RCY";
225  if(one_letter_name=="U" || one_letter_name=="u") residue.name="URA";
226  if(one_letter_name=="G" || one_letter_name=="g") residue.name="RGU";
227 
228  full_residue_list.push_back(residue);
229  }
230 
231  return full_residue_list;
232  }
233 
234 
235  Residue_info
236  Get_residue_from_seq_num(Size const & seq_num, utility::vector1 <Residue_info> const & residue_list){
237 
238  for(Size i=1; i<=residue_list.size(); i++){
239  if(seq_num==residue_list[i].seq_num){
240  return residue_list[i];
241  }
242  }
243  std::cout << "Error, in Get_residue_from_seq_num function. The seq_num " << seq_num << " does not exist in the residue_list" << std::endl;
244  exit (1);
245  }
246 
247 
248  bool
250 
251  for(Size j=1; j<=residue_list.size(); j++){
252  if(seq_num==residue_list[j].seq_num) {
253  return true;
254  }
255  }
256  return false;
257  }
258 
261 
263 
264  utility::vector1 <Residue_info> Sorted_residue_list = residue_list;
265  //Sort by seq_number, lowest sequence number at the top of the vector list.
266  sort_residue_list(Sorted_residue_list);
267 
268  Size j=1;
269  while(j<=Sorted_residue_list.size()){
270 
271  Size first_element=j;
272 
273  //Test if Sorted_residue_list[j] contain an adjacent residue at the three_prime_end
274  while((j<Sorted_residue_list.size()) && ((Sorted_residue_list[j].seq_num+1)==Sorted_residue_list[j+1].seq_num)){
275  j++;
276  }
277  Size last_element=j;
278 
279  utility::vector1 <Residue_info> residue_group;
280 
281  for(Size element=first_element; element<=last_element; element++){
282  residue_group.push_back(Sorted_residue_list[element]);
283  }
284  residue_group_list.push_back(residue_group);
285 
286  j++;
287  }
288 
289  return residue_group_list;
290  }
291 
292 
294  Set_Difference(utility::vector1 <Residue_info> const & residue_list_1, utility::vector1 <Residue_info> const & residue_list_2){
295 
296  utility::vector1 <Residue_info> set_difference_residue_list;
297 
298  for(Size i=1; i<= residue_list_1.size(); i++){
299  if(Contain_residue_at_seq_num(residue_list_1[i].seq_num, residue_list_2)) continue;
300  set_difference_residue_list.push_back(residue_list_1[i]);
301  }
302 
303  return set_difference_residue_list;
304 
305  }
306 
308  Set_Union(utility::vector1 <Residue_info> const & residue_list_1, utility::vector1 <Residue_info> const & residue_list_2){
309 
310  utility::vector1 <Residue_info> union_residue_list= residue_list_1;
311 
312  for(Size i=1; i<=residue_list_2.size(); i++){
313  if(Contain_residue_at_seq_num(residue_list_2[i].seq_num, union_residue_list)==false){
314  union_residue_list.push_back(residue_list_2[i]);
315  }
316  }
317 
318  return union_residue_list;
319 
320  }
321 
322  bool
323  residue_list_sort_citeria(Residue_info residue_info_1, Residue_info residue_info_2){
324  //Sort by seq_number, lowest sequence number at the top of the vector list.
325  return (residue_info_1.seq_num < residue_info_2.seq_num);
326  }
327 
328  void
330  //Need to check if this work with vector1, if not switch to std::vector
331  sort(residue_list.begin(), residue_list.end(), residue_list_sort_citeria);
332  }
333 
334 }
335 }
336 }