RNAMake
basepair.h
1 //
2 // basepair.h
3 // RNAMake
4 //
5 // Created by Joseph Yesselman on 1/28/15.
6 // Copyright (c) 2015 Joseph Yesselman. All rights reserved.
7 //
8 
9 #ifndef __RNAMake__basepair__
10 #define __RNAMake__basepair__
11 
12 #include <stdio.h>
13 
14 //RNAMake Headers
15 #include "base/types.h"
16 #include "util/uuid.h"
17 #include "math/xyz_matrix.h"
18 #include "structure/atom.h"
19 #include "structure/residue.h"
20 #include "structure/basepair_state.h"
21 
22 class Basepair {
23 public:
24  Basepair()
25  {}
26 
27  Basepair(
28  ResidueOP & res1,
29  ResidueOP & res2,
30  Matrix const & r,
31  String const & bp_type):
32  bp_type_(bp_type),
33  uuid_( Uuid() ),
34  res1_( res1 ),
35  res2_( res2 ),
36  flipped_ ( 0 )
37  {
38 
39  atoms_ = AtomOPs();
40  for( auto const & a : res1->atoms() ) {
41  if(a != nullptr) { atoms_.push_back(a); }
42  }
43  for( auto const & a : res2->atoms() ) {
44  if(a != nullptr) { atoms_.push_back(a); }
45  }
46 
47  Point d = center(atoms_);
48  Points sugars(2);
49  sugars[0] = res1_->get_atom("C1'")->coords();
50  sugars[1] = res2_->get_atom("C1'")->coords();
51  bp_state_ = std::make_shared<BasepairState>(d, r, sugars);
52 
53  }
54 
55  ~Basepair() {
56  res1_.reset();
57  res2_.reset();
58  }
59 
60  Basepair
61  copy();
62 
63  inline
64  bool
65  operator == (Basepair const & bp ) const { return uuid_ == bp.uuid_; }
66 
67 public: // getters
68 
69  inline
70  BasepairStateOP const &
71  state() {
72  bp_state_->d(center(atoms_));
73  bp_state_->sugars(Points{ res1_->get_atom("C1'")->coords(), res2_->get_atom("C1'")->coords() });
74  return bp_state_;
75  }
76 
77  inline
78  ResidueOPs const
79  residues() const {
80  ResidueOPs res(2);
81  res[0] = res1_;
82  res[1] = res2_;
83  return res;
84  }
85 
86  inline
87  ResidueOP const &
88  partner(ResidueOP const & res) {
89  if ( res->uuid() == res1_->uuid()) { return res2_; }
90  else if( res->uuid() == res2_->uuid()) { return res1_; }
91  else { throw "called partner with resiude not in this basepair"; }
92  }
93 
94  inline
95  String const
96  name() const {
97  std::stringstream ss;
98  ss << res1_->chain_id() << res1_->num() << res1_->i_code();
99  String str1 = ss.str();
100  ss.str("");
101  ss << res2_->chain_id() << res2_->num() << res2_->i_code();
102  String str2 = ss.str();
103  if(str1 < str2) { return str1+"-"+str2; }
104  else { return str2+"-"+str1; }
105  }
106 
107  inline
108  void
109  flip() { bp_state_->flip(); }
110 
111  inline
112  Matrix const &
113  r() const { return bp_state_->r(); }
114 
115  inline
116  Point const
117  d() const { return center(atoms_); }
118 
119  inline
120  Uuid const &
121  uuid() const { return uuid_; }
122 
123  inline
124  ResidueOP
125  res1() const { return res1_; }
126 
127  inline
128  ResidueOP
129  res2() const { return res2_; }
130 
131  inline
132  String const &
133  bp_type() const { return bp_type_; }
134 
135  inline
136  int const
137  flipped() const { return flipped_; }
138 
139  inline
140  AtomOPs const &
141  atoms() const { return atoms_; }
142 
143 public: // setters
144 
145  inline
146  void
147  r(Matrix const & nr) { bp_state_->r(nr); }
148 
149  inline
150  void
151  uuid(Uuid const & nuuid) { uuid_ = nuuid; }
152 
153  inline
154  void
155  flipped(int const & nflipped) { flipped_ = nflipped; }
156 
157  inline
158  void
159  res1(ResidueOP const & nres1) { res1_ = nres1;}
160 
161  inline
162  void
163  res2(ResidueOP const & nres2) { res2_ = nres2;}
164 
165 public:
166 
167  String const
168  to_str() const;
169 
170  String const
171  to_pdb_str() const;
172 
173  void
174  to_pdb(String const) const;
175 
176 
177 private:
178  ResidueOP res1_, res2_;
179  AtomOPs atoms_;
180  BasepairStateOP bp_state_;
181  String bp_type_;
182  int flipped_;
183  Uuid uuid_;
184 
185 };
186 
187 typedef std::shared_ptr<Basepair> BasepairOP;
188 typedef std::vector<BasepairOP> BasepairOPs;
189 
190 bool
191 wc_bp(BasepairOP const &);
192 
193 bool
194 gu_bp(BasepairOP const &);
195 
196 
197 #endif /* defined(__RNAMake__basepair__) */
Definition: basepair.h:22