]> git.donarmstrong.com Git - rsem.git/blob - PairedEndRead.h
rsem v1.1.13, speed up EM by only updating model parameters for first 10 iterations...
[rsem.git] / PairedEndRead.h
1 #ifndef PAIREDENDREAD
2 #define PAIREDENDREAD
3
4 #include<cassert>
5 #include<iostream>
6 #include<string>
7
8 #include "Read.h"
9 #include "SingleRead.h"
10
11 class PairedEndRead : public Read {
12  public:
13   PairedEndRead() : mate1(), mate2() {}
14   PairedEndRead(const SingleRead& mate1, const SingleRead& mate2) {
15           this->mate1 = mate1;
16           this->mate2 = mate2;
17           this->name = mate1.getName();
18
19           calc_lq();
20   }
21
22   bool read(int argc, std::istream* argv[], int flags = 7);
23   void write(int argc, std::ostream* argv[]);
24
25   const SingleRead& getMate1() const { return mate1; }
26   const SingleRead& getMate2() const { return mate2; }
27   const SingleRead& getMate(int i) const {
28           if (i == 1) return mate1;
29           else return mate2;
30   }
31
32  private:
33   SingleRead mate1, mate2;
34
35   void calc_lq();
36 };
37
38 bool PairedEndRead::read(int argc, std::istream* argv[], int flags) {
39         bool success;
40     std::istream *inpMate1[1], *inpMate2[1];
41
42         assert(argc == 2);
43         inpMate1[0] = argv[0]; inpMate2[0] = argv[1];
44         success = mate1.read(1, inpMate1, flags) && mate2.read(1, inpMate2, flags);
45         name = "";
46         if (flags & 4) { name = mate1.getName(); } //May chop 1 char later if we want
47
48         if (flags & 1) calc_lq();
49
50         return success;
51 }
52
53 void PairedEndRead::write(int argc, std::ostream *argv[]) {
54         std::ostream *outMate1[1], *outMate2[1];
55
56         assert(argc == 2);
57         outMate1[0] = argv[0]; outMate2[0] = argv[1];
58         mate1.write(1, outMate1);
59         mate2.write(1, outMate2);
60 }
61
62 void PairedEndRead::calc_lq() {
63         low_quality = mate1.isLowQuality() && mate2.isLowQuality();
64         if (mate1.getReadLength() < OLEN || mate2.getReadLength() < OLEN) low_quality = true;
65 }
66
67 #endif