LocARNA-1.9.2
src/LocARNA/alignment.hh
00001 #ifndef LOCARNA_ALIGNMENT_HH
00002 #define LOCARNA_ALIGNMENT_HH
00003 
00004 #ifdef HAVE_CONFIG_H
00005 #include <config.h>
00006 #endif
00007 
00008 #include <iosfwd>
00009 #include <vector>
00010 #include "aux.hh"
00011 #include "scoring_fwd.hh"
00012 
00013 namespace LocARNA {
00014 
00015     class AlignmentImpl;
00016     class RnaData;
00017     class Sequence;
00018     class RnaStructure;
00019     class string1;
00020     class AnchorConstraints;
00021 
00022     // unnest definitions of alignment edges
00023 
00027     class EdgeEnd {
00028         int end_; //<! position or Gap
00029     public:
00031         EdgeEnd() : end_(0) {}
00032 
00035         EdgeEnd(pos_type end) : end_(int(end)) {}
00036 
00039         EdgeEnd(Gap end) : end_(-int(end.idx()) - 1) {}
00040 
00043         bool
00044         is_gap() const {
00045             return end_ < 0;
00046         }
00047 
00050         bool
00051         is_pos() const {
00052             return end_ > 0;
00053         }
00054 
00057         Gap
00058         gap() const {
00059             assert(end_ < 0);
00060             return Gap(size_t(-(end_ + 1)));
00061         }
00062 
00065         operator pos_type() const {
00066             assert(end_ > 0);
00067             return pos_type(end_);
00068         }
00069     };
00070 
00072     typedef std::vector<EdgeEnd> Alignment__edge_ends_t;
00073 
00075     class AlignmentEdges
00076         : public std::pair<Alignment__edge_ends_t, Alignment__edge_ends_t> {
00077         typedef Alignment__edge_ends_t edge_ends_t;
00078         typedef std::pair<edge_ends_t, edge_ends_t> parent_t;
00079 
00080     public:
00082         AlignmentEdges(const edge_ends_t &x, const edge_ends_t &y)
00083             : parent_t(x, y) {
00084             assert(x.size() == y.size());
00085         };
00086 
00088         size_t
00089         size() const {
00090             return first.size();
00091         }
00092     };
00093 
00099     class Alignment {
00100         AlignmentImpl *pimpl_; 
00101 
00102     public:
00104         typedef EdgeEnd edge_end_t;
00105 
00107         typedef Alignment__edge_ends_t edge_ends_t;
00108 
00110         typedef AlignmentEdges edges_t;
00111 
00117         static edge_ends_t
00118         alistr_to_edge_ends(const std::string &alistr);
00119 
00125         Alignment(const Sequence &seqA, const Sequence &seqB);
00126 
00130         ~Alignment();
00131 
00139         Alignment(const Sequence &seqA,
00140                   const Sequence &seqB,
00141                   const edges_t &edges);
00142 
00148         Alignment(const Alignment &alignment);
00149 
00155         Alignment &
00156         operator=(const Alignment &alignment);
00157 
00164         void
00165         swap(Alignment &a1, Alignment &a2);
00166 
00171         void
00172         set_consensus_structure(const RnaStructure &structure);
00173 
00179         void
00180         set_structures(const RnaStructure &structureA,
00181                        const RnaStructure &structureB);
00182 
00186         void
00187         clear();
00188 
00195         void
00196         append(edge_end_t i, edge_end_t j);
00197 
00201         void
00202         add_basepairA(int i, int j);
00203 
00207         void
00208         add_basepairB(int i, int j);
00209 
00213         void
00214         add_deleted_basepairA(int i, int j);
00218         void
00219         add_deleted_basepairB(int i, int j);
00220 
00239         const edges_t
00240         alignment_edges(bool only_local) const;
00241 
00242         /* start/end of (locally) aligned subsequences
00243            (this is used when finding k-best alignments in Aligner)
00244          */
00245 
00247         size_type
00248         local_startA() const;
00249 
00251         size_type
00252         local_endA() const;
00253 
00255         size_type
00256         local_startB() const;
00257 
00259         size_type
00260         local_endB() const;
00261 
00268         std::string
00269         dot_bracket_structureA(bool only_local) const;
00270 
00277         std::string
00278         dot_bracket_structureB(bool only_local) const;
00279 
00280         /* access */
00281 
00286         const Sequence &
00287         seqA() const;
00288 
00293         const Sequence &
00294         seqB() const;
00295     };
00296 }
00297 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends