1 #ifndef HITCONTAINER_H_
2 #define HITCONTAINER_H_
11 template<class HitType>
26 bool read(std::istream&); // each time a read
27 void write(std::ostream&); // write all reads' hit out
29 void push_back(const HitType& hit) {
34 //update read information vector etc
36 if (nhits > s.back()) { //Do not change if last read does not have hits
42 int getN() { return n; }
44 int getNHits() { return nhits; }
46 int calcNumGeneMultiReads(const GroupInfo&);
47 int calcNumIsoformMultiReads();
49 int getSAt(int pos) { assert(pos >= 0 && pos <= n); return s[pos]; }
51 HitType& getHitAt(int pos) { assert(pos >= 0 && pos < nhits); return hits[pos]; }
54 int n; // n reads in total
55 int nhits; // # of hits
57 std::vector<HitType> hits;
60 //Each time only read one read's hits. If you want to start over, must call clear() first!
61 template<class HitType>
62 bool HitContainer<HitType>::read(std::istream& in) {
65 if (!(in>>tot)) return false;
67 for (int i = 0; i < tot; i++) {
69 if (!hit.read(in)) return false;
80 template<class HitType>
81 void HitContainer<HitType>::write(std::ostream& out) {
83 for (int i = 0; i < n; i++) {
85 for (int j = s[i]; j < s[i + 1]; j++) {
92 template<class HitType>
93 int HitContainer<HitType>::calcNumGeneMultiReads(const GroupInfo& gi) {
97 for (int i = 0; i < n; i++) {
98 int num = s[i + 1] - s[i];
99 sortgids = new int[num];
100 for (int j = s[i]; j < s[i + 1]; j++) sortgids[j] = gi.gidAt(hits[j].getSid());
101 std::sort(sortgids, sortgids + num);
102 if (std::unique(sortgids, sortgids + num) - sortgids > 1) ++res;
109 template<class HitType>
110 int HitContainer<HitType>::calcNumIsoformMultiReads() {
112 for (int i = 0; i < n; i++)
113 if (s[i + 1] - s[i] > 1) ++res;
117 #endif /* HITCONTAINER_H_ */