14 class SingleReadQ : public Read {
16 SingleReadQ() { readseq = qscore = ""; len = 0; }
17 SingleReadQ(const std::string& name, const std::string& readseq, const std::string& qscore) {
19 this->readseq = readseq;
20 this->qscore = qscore;
21 this->len = readseq.length();
26 bool read(int argc, std::istream* argv[], int flags = 7);
27 void write(int argc, std::ostream* argv[]);
29 int getReadLength() const { return len; }
30 const std::string& getReadSeq() const { return readseq; }
31 const std::string& getQScore() const { return qscore; }
34 int len; // read length
35 std::string readseq, qscore; // qscore : quality scores
40 bool SingleReadQ::read(int argc, std::istream* argv[], int flags) {
44 if (!getline((*argv[0]), line)) return false;
45 if (line[0] != '@') { fprintf(stderr, "Read file does not look like a FASTQ file!\n"); exit(-1); }
47 if (flags & 4) { name = line.substr(1); }
48 if (!getline((*argv[0]), readseq)) return false;
49 len = readseq.length();
50 if (!(flags & 1)) { readseq = ""; }
51 if (!getline((*argv[0]), line)) return false;
52 if (line[0] != '+') { fprintf(stderr, "Read file does not look like a FASTQ file!\n"); exit(-1); }
53 if (!getline((*argv[0]), qscore)) return false;
54 if (!(flags & 2)) { qscore = ""; }
56 if (flags & 1) calc_lq();
61 void SingleReadQ::write(int argc, std::ostream* argv[]) {
63 (*argv[0])<<"@"<<name<<std::endl<<readseq<<std::endl<<"+\n"<<qscore<<std::endl;
66 void SingleReadQ::calc_lq() {
67 int numA = 0, numT = 0, numAO = 0, numTO = 0; // numAO : number of A in overlap seed region
68 int threshold_1, threshold_2;
70 threshold_1 = int(0.9 * len - 1.5 * sqrt(len * 1.0) + 0.5);
71 threshold_2 = (OLEN - 1) / 2 + 1;
72 for (int i = 0; i < len; i++) {
73 if (readseq[i] == 'A') {
75 if (i < OLEN) ++numAO;
77 if (readseq[i] == 'T') {
79 if (i >= len - OLEN) ++numTO;
83 if (numA >= threshold_1) {
84 low_quality = (numAO >= threshold_2);
86 else if (numT >= threshold_1) {
87 low_quality = (numTO >= threshold_2);
89 else low_quality = false;