File: AlignmentGroup.hpp

package info (click to toggle)
salmon 0.7.2%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,352 kB
  • ctags: 5,243
  • sloc: cpp: 42,341; ansic: 6,252; python: 228; makefile: 207; sh: 190
file content (65 lines) | stat: -rw-r--r-- 1,942 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#ifndef ALIGNMENT_GROUP
#define ALIGNMENT_GROUP

extern "C" {
#include "io_lib/scram.h"
#include "io_lib/os.h"
#undef max
#undef min
}


// Cereal includes
#include "cereal/types/vector.hpp"
#include "cereal/archives/binary.hpp"

#include <vector>
#include "SalmonMath.hpp"
#include "ReadPair.hpp"

template <typename FragT>
class AlignmentGroup {
    public:
        AlignmentGroup() : read_(nullptr), isUniquelyMapped_(true) { alignments_.reserve(10); }
        AlignmentGroup(AlignmentGroup& other) = delete;
        AlignmentGroup(AlignmentGroup&& other) = default;
        AlignmentGroup& operator=(AlignmentGroup& other) = delete;
        AlignmentGroup& operator=(AlignmentGroup&& other) = delete;

        void setRead(std::string* r) { read_ = r; }
        std::string* read() { return read_; }

        inline std::vector<FragT>& alignments() { return alignments_; }
        void emplaceAlignment(FragT&& p) { alignments_.emplace_back(p); }
        void addAlignment(FragT& p) { alignments_.push_back(p); }

        void clearAlignments() {
            alignments_.clear();
            isUniquelyMapped_ = true;
        }

        inline bool& isUniquelyMapped() { return isUniquelyMapped_; }
        inline size_t numAlignments() { return alignments_.size(); }
        inline size_t size() { return numAlignments(); }

        template <typename Archive>
        void serialize(Archive& archive) {
            archive(alignments_);
        }

        /**
         *  Sort the alignments by their transcript ids
         */
        inline void sortHits() {
            std::sort(alignments_.begin(), alignments_.end(),
                    [](const FragT& x, const FragT& y) -> bool {
                        return x->transcriptID() < y->transcriptID();
                     });
        }

    private:
        std::vector<FragT> alignments_;
        std::string* read_;
        bool isUniquelyMapped_;
};
#endif // ALIGNMENT_GROUP