LocARNA-2.0.0
alignment.hh
1 #ifndef LOCARNA_ALIGNMENT_HH
2 #define LOCARNA_ALIGNMENT_HH
3 
4 #ifdef HAVE_CONFIG_H
5 #include <config.h>
6 #endif
7 
8 #include <iosfwd>
9 #include <vector>
10 #include <memory>
11 #include "aux.hh"
12 #include "scoring_fwd.hh"
13 
14 namespace LocARNA {
15 
16  class AlignmentImpl;
17  class RnaData;
18  class Sequence;
19  class RnaStructure;
20  class string1;
21  class AnchorConstraints;
22 
23  // unnest definitions of alignment edges
24 
28  class EdgeEnd {
29  public:
31  EdgeEnd() : end_(0) {}
32 
35  EdgeEnd(pos_type end) : end_(int(end)) {}
36 
39  EdgeEnd(Gap end) : end_(-int(end) - 1) {}
40 
43  bool
44  is_gap() const {
45  return end_ < 0;
46  }
47 
50  bool
51  is_pos() const {
52  return end_ > 0;
53  }
54 
57  Gap
58  gap() const {
59  assert(end_ < 0);
60  return Gap(size_t(-(end_ + 1)));
61  }
62 
66  operator pos_type() const {
67  return pos_type(end_);
68  }
69  private:
70  int end_; //<! position or Gap
71  };
72 
73  class AlignmentEdges : public std::vector<std::pair<EdgeEnd,EdgeEnd>> {
74  public:
75  using edge_t = std::pair<EdgeEnd,EdgeEnd>;
76  };
77 
83  class Alignment {
84  public:
87 
89  using edge_ends_t = std::vector<EdgeEnd>;
90 
91  using edge_end_pair_t = std::pair<EdgeEnd,EdgeEnd>;
92  using pos_pair_t = std::pair<pos_type, pos_type>;
93 
96 
102  static edges_t
103  alistrs_to_edges(const std::string &alistrA,
104  const std::string &alistrB);
105 
111  Alignment(const Sequence &seqA, const Sequence &seqB);
112 
116  ~Alignment();
117 
125  Alignment(const Sequence &seqA,
126  const Sequence &seqB,
127  const edges_t &edges);
128 
134  Alignment(const Alignment &alignment);
135 
141  Alignment &
142  operator=(const Alignment &alignment);
143 
148  void
149  set_consensus_structure(const RnaStructure &structure);
150 
156  void
157  set_structures(const RnaStructure &structureA,
158  const RnaStructure &structureB);
159 
163  void
164  clear();
165 
172  void
174 
178  void
179  add_basepairA(int i, int j);
180 
184  void
185  add_basepairB(int i, int j);
186 
190  void
191  add_deleted_basepairA(int i, int j);
195  void
196  add_deleted_basepairB(int i, int j);
197 
216  const edges_t
217  alignment_edges(bool only_local) const;
218 
219  /* start/end of (locally) aligned subsequences
220  */
221 
225  pos_pair_t
226  start_positions() const;
227 
230  pos_pair_t
231  end_positions() const;
232 
239  std::string
240  dot_bracket_structureA(bool only_local) const;
241 
248  std::string
249  dot_bracket_structureB(bool only_local) const;
250 
251  /* access */
252 
257  const Sequence &
258  seqA() const;
259 
264  const Sequence &
265  seqB() const;
266 
270  bool
271  empty() const;
272 
273  private:
274  std::unique_ptr<AlignmentImpl> pimpl_;
275 
276  template <int i>
277  std::string
278  dot_bracket_structure(const std::string &, bool only_local) const;
279  };
280 }
281 #endif
Definition: alignment.hh:73
Represents a structure-annotated sequence alignment.
Definition: alignment.hh:83
const edges_t alignment_edges(bool only_local) const
All alignment edges.
Definition: alignment.cc:121
Alignment(const Sequence &seqA, const Sequence &seqB)
Definition: alignment.cc:23
Alignment & operator=(const Alignment &alignment)
assignment operator
Definition: alignment.cc:61
void add_basepairA(int i, int j)
Add a basepair to the structure of A.
Definition: alignment.cc:97
void add_deleted_basepairB(int i, int j)
Add a basepair to the structure of B.
Definition: alignment.cc:115
static edges_t alistrs_to_edges(const std::string &alistrA, const std::string &alistrB)
convert alignemnt string to edge end vector
Definition: alignment.cc:242
std::string dot_bracket_structureB(bool only_local) const
Structure B.
Definition: alignment.cc:237
const Sequence & seqB() const
read access seqB
Definition: alignment.cc:203
pos_pair_t end_positions() const
Definition: alignment.cc:184
std::string dot_bracket_structureA(bool only_local) const
Structure A.
Definition: alignment.cc:233
const Sequence & seqA() const
read access seqA
Definition: alignment.cc:198
EdgeEnd edge_end_t
edge end
Definition: alignment.hh:86
std::vector< EdgeEnd > edge_ends_t
edge ends
Definition: alignment.hh:89
void clear()
Definition: alignment.cc:82
bool empty() const
Definition: alignment.cc:208
void append(edge_end_t i, edge_end_t j)
Append an alignment edge.
Definition: alignment.cc:92
void add_deleted_basepairA(int i, int j)
Add a basepair to the structure of A.
Definition: alignment.cc:109
~Alignment()
Definition: alignment.cc:58
void set_consensus_structure(const RnaStructure &structure)
Set consensus structure of the alignment.
Definition: alignment.cc:77
void add_basepairB(int i, int j)
Add a basepair to the structure of B.
Definition: alignment.cc:103
void set_structures(const RnaStructure &structureA, const RnaStructure &structureB)
Set structures of the alignment.
Definition: alignment.cc:68
pos_pair_t start_positions() const
Definition: alignment.cc:170
end of an alignment edge
Definition: alignment.hh:28
EdgeEnd(Gap end)
construct as gap
Definition: alignment.hh:39
bool is_gap() const
gap test
Definition: alignment.hh:44
EdgeEnd()
construct as invalid end
Definition: alignment.hh:31
EdgeEnd(pos_type end)
construct as position
Definition: alignment.hh:35
Gap gap() const
Definition: alignment.hh:58
bool is_pos() const
is position test
Definition: alignment.hh:51
An RNA secondary structure.
Definition: rna_structure.hh:32
"Sequence View" of multiple alignment as array of column vectors
Definition: sequence.hh:17
Definition: aligner.cc:15
size_type pos_type
type of a sequence position
Definition: aux.hh:126
Gap
different types of gaps
Definition: aux.hh:132