RNAMake
chain.h
1 //
2 // chain.h
3 // RNAMake
4 //
5 // Created by Joseph Yesselman on 1/25/15.
6 // Copyright (c) 2015 Joseph Yesselman. All rights reserved.
7 //
8 
9 #ifndef __RNAMake__chain__
10 #define __RNAMake__chain__
11 
12 #include <stdio.h>
13 #include <algorithm>
14 
15 //RNAMake Headers
16 #include "base/types.h"
17 #include "structure/chain.fwd.h"
18 #include "structure/residue.h"
19 #include "structure/residue_type_set.h"
20 
21 class Chain {
22 public:
23  Chain() {}
24  Chain(
25  ResidueOPs const & residues):
26  residues_ ( residues )
27  {}
28 
29  Chain(
30  Chain const & c) {
31 
32  residues_ = ResidueOPs(c.residues_.size());
33  int i = 0;
34  for (auto const & r : c.residues_) {
35  residues_[i] = std::make_shared<Residue>(*r);
36  i++;
37  }
38  }
39 
40  Chain(
41  String const & s,
42  ResidueTypeSet const & rts) {
43 
44  residues_ = ResidueOPs();
45  Strings spl = split_str_by_delimiter(s, ";");
46  for(auto const & r_str : spl) {
47  auto r = std::make_shared<Residue>(r_str, rts);
48  residues_.push_back(r);
49  }
50  }
51 
52 
53  ~Chain() {}
54 
55 public:
56 
57  inline
58  int
59  length() const {
60  return (int)residues_.size();
61  }
62 
63  inline
64  ResidueOP const &
65  first() { return residues_[0]; }
66 
67  inline
68  ResidueOP const &
69  last() { return residues_.back(); }
70 
71  inline
72  ChainOP
73  subchain(int start, int end) {
74  if(start < 0) { throw "start cannot be less then 0"; }
75  if(start == end) { throw "start and end cannot be the same value"; }
76  if(end > residues().size()) { throw "end is greater then chain length"; }
77  if(start > end) { throw "start is greater then end"; }
78  return ChainOP(new Chain(ResidueOPs(residues_.begin() + start, residues_.begin() + end)));
79  }
80 
81  inline
82  ChainOP
83  subchain(
84  ResidueOP const & r1,
85  ResidueOP const & r2) {
86 
87  if(std::find(residues_.begin(), residues_.end(), r1) == residues_.end()) { return nullptr; }
88  if(std::find(residues_.begin(), residues_.end(), r2) == residues_.end()) { return nullptr; }
89 
90  int start = (int)(std::find(residues_.begin(), residues_.end(), r1) - residues_.begin());
91  int end = (int)(std::find(residues_.begin(), residues_.end(), r2) - residues_.begin());
92 
93  if( start > end) {
94  int temp = start;
95  start = end;
96  end = temp;
97  }
98  return subchain(start, end);
99  }
100 
101  String
102  to_str() const;
103 
104 
105  String
106  to_pdb_str(
107  int &,
108  int,
109  String const &) const;
110 
111  inline
112  String
113  to_pdb_str(int & acount) const {
114  return to_pdb_str(acount, -1, "");
115  }
116 
117  void
118  to_pdb(
119  String const,
120  int,
121  String const &) const;
122 
123  inline
124  void
125  to_pdb(String const & fname) {
126  return to_pdb(fname, -1, "");
127  }
128 
129 public: //getters
130 
131  inline
132  ResidueOPs &
133  residues() { return residues_; }
134 
135 private:
136  ResidueOPs residues_;
137 };
138 
139 void
140 connect_residues_into_chains(
141  ResidueOPs & residues,
142  ChainOPs & chains);
143 
144 
145 #endif /* defined(__RNAMake__chain__) */
Definition: residue_type_set.h:15
Definition: chain.h:21