1 #ifndef HITCONTAINER_H_
2 #define HITCONTAINER_H_
10 #include "GroupInfo.h"
12 template<class HitType>
27 bool read(std::istream&); // each time a read
28 void write(std::ostream&); // write all reads' hit out
30 void push_back(const HitType& hit) {
35 //update read information vector etc
37 if (nhits > s.back()) { //Do not change if last read does not have hits
43 READ_INT_TYPE getN() { return n; }
45 HIT_INT_TYPE getNHits() { return nhits; }
47 READ_INT_TYPE calcNumGeneMultiReads(const GroupInfo&);
48 READ_INT_TYPE calcNumIsoformMultiReads();
50 HIT_INT_TYPE getSAt(READ_INT_TYPE pos) { assert(pos >= 0 && pos <= n); return s[pos]; }
52 HitType& getHitAt(HIT_INT_TYPE pos) { assert(pos >= 0 && pos < nhits); return hits[pos]; }
55 READ_INT_TYPE n; // n reads in total
56 HIT_INT_TYPE nhits; // # of hits
57 std::vector<HIT_INT_TYPE> s;
58 std::vector<HitType> hits;
61 //Each time only read one read's hits. If you want to start over, must call clear() first!
62 template<class HitType>
63 bool HitContainer<HitType>::read(std::istream& in) {
66 if (!(in>>tot)) return false;
68 for (HIT_INT_TYPE i = 0; i < tot; i++) {
70 if (!hit.read(in)) return false;
81 template<class HitType>
82 void HitContainer<HitType>::write(std::ostream& out) {
84 for (READ_INT_TYPE i = 0; i < n; i++) {
86 for (HIT_INT_TYPE j = s[i]; j < s[i + 1]; j++) {
93 template<class HitType>
94 READ_INT_TYPE HitContainer<HitType>::calcNumGeneMultiReads(const GroupInfo& gi) {
95 READ_INT_TYPE res = 0;
98 for (READ_INT_TYPE i = 0; i < n; i++) {
99 HIT_INT_TYPE num = s[i + 1] - s[i];
100 sortgids = new int[num];
101 for (HIT_INT_TYPE j = s[i]; j < s[i + 1]; j++) sortgids[j] = gi.gidAt(hits[j].getSid());
102 std::sort(sortgids, sortgids + num);
103 if (std::unique(sortgids, sortgids + num) - sortgids > 1) ++res;
110 template<class HitType>
111 READ_INT_TYPE HitContainer<HitType>::calcNumIsoformMultiReads() {
112 READ_INT_TYPE res = 0;
113 for (READ_INT_TYPE i = 0; i < n; i++)
114 if (s[i + 1] - s[i] > 1) ++res;
118 #endif /* HITCONTAINER_H_ */