File: AlignmentGroup.hpp

package info (click to toggle)
salmon 1.10.3%2Bds1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 35,148 kB
  • sloc: cpp: 200,707; ansic: 171,082; sh: 859; python: 792; makefile: 238
file content (79 lines) | stat: -rw-r--r-- 2,159 bytes parent folder | download | duplicates (3)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#ifndef ALIGNMENT_GROUP
#define ALIGNMENT_GROUP

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

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

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

struct EmptyCellInfo {};

template <typename FragT, typename BCType = EmptyCellInfo, typename UMIType = EmptyCellInfo> 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_; }

   void setBarcode(BCType b ) {barcode_ = b;}
   void setUMI(UMIType b) {umi_ = b;}
   BCType barcode() {return barcode_;}
   UMIType umi() {return umi_;}

  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() {
    auto vecLen = alignments_.size();
    alignments_.clear();
    if (vecLen > 10) {
      alignments_.shrink_to_fit();
    }
    isUniquelyMapped_ = true;
  }

  inline bool& isUniquelyMapped() { return isUniquelyMapped_; }
  inline size_t numAlignments() const { return alignments_.size(); }
  inline size_t size() const { 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_;
  BCType barcode_;
  UMIType umi_;
};

#endif // ALIGNMENT_GROUP