LocARNA-1.8.11
anchor_constraints.hh
1 #ifndef LOCARNA_ANCHOR_CONSTRAINTS_HH
2 #define LOCARNA_ANCHOR_CONSTRAINTS_HH
3 
4 #ifdef HAVE_CONFIG_H
5 # include <config.h>
6 #endif
7 
8 #include <string>
9 #include <vector>
10 #include <map>
11 
12 #include <exception>
13 
14 #include <iosfwd>
15 
16 //#include "aux.hh"
17 
18 namespace LocARNA {
19 
20 
27  public:
28  typedef size_t size_type;
29  typedef std::pair<size_type,size_type> size_pair_t;
30 
31  typedef size_pair_t range_t;
32  typedef std::vector<range_t> range_seq_t;
33 
34  private:
35  typedef std::map<std::string,size_type> name_tab_t;
36 
37  typedef std::vector<int> seq_t;
38 
39  typedef std::vector<std::string> name_seq_t;
40 
45  seq_t a;
46 
49  seq_t b;
50 
54  range_seq_t ar;
55 
57  name_seq_t names_a;
59  name_seq_t names_b;
60 
62  size_type name_size_;
63 
64  public:
65  // ------------------------------------------------------------
66  // constructors
67 
100  AnchorConstraints(size_type lenA,
101  const std::vector<std::string> &seqCA,
102  size_type lenB,
103  const std::vector<std::string> &seqCB);
104 
114  AnchorConstraints(size_type lenA,
115  const std::string &seqCA,
116  size_type lenB,
117  const std::string &seqCB);
118 
119  // -----------------------------------------------------------
120  // asking for constraint information
121 
124  bool
125  allowed_edge(size_type i, size_type j) const {
126  return
127  ar[i].first <= j
128  && j <= ar[i].second;
129  }
130 
137  int
138  match_to_a(size_type i) const {
139  return a[i];
140  }
141 
147  int
148  match_to_b(size_type i) const {
149  return b[i];
150  }
151 
153  bool
154  aligned_in_a(size_type i) const {
155  return match_to_a(i)>0;
156  }
157 
159  bool
160  aligned_in_b(size_type j) const {
161  return match_to_b(j)>0;
162  }
163 
165  std::string
166  get_name_a(size_type i) const {return names_a[i];}
167 
169  std::string
170  get_name_b(size_type j) const {return names_b[j];}
171 
173  size_type
174  name_size() const {return name_size_;};
175 
177  bool
178  empty() const {return name_size()==0;}
179 
181  size_pair_t rightmost_anchor() const {
182  for (size_type i=a.size(); i>1; ) { // for i=lenA downto 1
183  --i;
184  if (a[i]>0) return size_pair_t(i,a[i]);
185  }
186  return size_pair_t(0,0);
187  }
188 
190  size_pair_t leftmost_anchor() const {
191  for (size_type i=0; i<a.size(); i++) {
192  if (a[i]>0) return size_pair_t(i,a[i]);
193  }
194  return size_pair_t(a.size()+1,b.size()+1);
195  }
196 
197  private:
198  // ------------------------------------------------------------
199  // construction helper
200 
201 
205  static
206  void
207  transform_input(name_tab_t &nameTab,
208  size_type len,
209  const std::vector<std::string> &seq);
210 
213  void
214  init_tables(const name_tab_t &nameTabA,
215  const name_tab_t &nameTabB);
216 
217  static
218  void
219  init_seq_table(seq_t & seq_tab,
220  name_seq_t & name_seq_tab,
221  const name_tab_t &nameTabA,
222  const name_tab_t &nameTabB);
223 
226  static
227  bool
228  only_dont_care(const std::string &s);
229  };
230 
231 }
232 
233 #endif // LOCARNA_ANCHOR_CONSTRAINTS_HH
Represents anchor constraints between two sequences.
Definition: anchor_constraints.hh:26
AnchorConstraints(size_type lenA, const std::vector< std::string > &seqCA, size_type lenB, const std::vector< std::string > &seqCB)
Construct from sequence lengths and anchor names.
Definition: anchor_constraints.cc:11
bool aligned_in_a(size_type i) const
is position i in sequence A aligned to any position in B
Definition: anchor_constraints.hh:154
std::pair< size_type, size_type > size_pair_t
size pair
Definition: anchor_constraints.hh:29
std::vector< range_t > range_seq_t
type for sequence of ranges
Definition: anchor_constraints.hh:32
Definition: aligner.cc:17
int match_to_b(size_type i) const
Definition: anchor_constraints.hh:148
int match_to_a(size_type i) const
Definition: anchor_constraints.hh:138
size_pair_t rightmost_anchor() const
return the positions (i,j) of the rightmost anchor constraint
Definition: anchor_constraints.hh:181
size_type name_size() const
returns length/size of the names
Definition: anchor_constraints.hh:174
size_pair_t leftmost_anchor() const
return the positions (i,j) of the leftmost anchor constraint
Definition: anchor_constraints.hh:190
bool allowed_edge(size_type i, size_type j) const
Definition: anchor_constraints.hh:125
size_pair_t range_t
type of range
Definition: anchor_constraints.hh:31
bool aligned_in_b(size_type j) const
is position j in sequence B aligned to any position in A
Definition: anchor_constraints.hh:160
size_t size_type
size type
Definition: anchor_constraints.hh:28
std::string get_name_b(size_type j) const
get the name of position j in B
Definition: anchor_constraints.hh:170
bool empty() const
is the constraint declaration empty
Definition: anchor_constraints.hh:178
std::string get_name_a(size_type i) const
get the name of position i in A
Definition: anchor_constraints.hh:166