5 #include <seqan/sequence.h>
6 #include <seqan/file.h>
12 using namespace seqan;
15 * Parse a single quality string from fb and store qualities in r.
16 * Assume the next character obtained via fb.get() is the first
17 * character of the quality string. When returning, the next
18 * character returned by fb.peek() or fb.get() should be the first
19 * character of the following line.
21 int parseQuals(ReadBuf& r,
32 assert(fb.peek() != '\n' && fb.peek() != '\r');
33 _setBegin (r.qual, (char*)r.qualBuf);
34 _setLength(r.qual, 0);
36 while (c != '\r' && c != '\n' && c != -1) {
39 while(!isspace(c = fb.peek()) && !fb.eof()) {
46 cerr << "Warning: could not parse quality line:" << endl;
48 cerr << fb.copyLastN(buf);
60 // Phred-33 ASCII encode it and add it to the back of the
62 r.qualBuf[qualsRead++] = ('!' + num);
63 // Skip over next stretch of whitespace
65 while(c != '\r' && c != '\n' && isspace(c) && !fb.eof()) {
71 while (c != '\r' && c != '\n' && c != -1) {
73 r.qualBuf[qualsRead++] = charToPhred33(c, solexa64, phred64);
75 while(c != '\r' && c != '\n' && isspace(c) && !fb.eof()) {
81 if (qualsRead < readLen-1 ||
82 (qualsRead < readLen && !r.color))
84 tooFewQualities(r.name);
87 if(qualsRead <= 0) return 0;
88 int trimmedReadLen = readLen-trim3-trim5;
89 if(trimmedReadLen < 0) trimmedReadLen = 0;
90 if(qualsRead > trimmedReadLen) {
91 // Shift everybody left
92 for(int i = 0; i < readLen; i++) {
93 r.qualBuf[i] = r.qualBuf[i+qualsRead-trimmedReadLen];
96 _setLength(r.qual, trimmedReadLen);
97 while(fb.peek() == '\n' || fb.peek() == '\r') fb.get();
101 void wrongQualityFormat(const String<char>& read_name) {
102 cerr << "Encountered a space parsing the quality string for read " << read_name << endl
103 << "If this is a FASTQ file with integer (non-ASCII-encoded) qualities, please" << endl
104 << "re-run Bowtie with the --integer-quals option. If this is a FASTQ file with" << endl
105 << "alternate basecall information, please re-run Bowtie with the --fuzzy option." << endl;
109 void tooFewQualities(const String<char>& read_name) {
110 cerr << "Too few quality values for read: " << read_name << endl
111 << "\tare you sure this is a FASTQ-int file?" << endl;
115 void tooManyQualities(const String<char>& read_name) {
116 cerr << "Reads file contained a pattern with more than 1024 quality values." << endl
117 << "Please truncate reads and quality values and and re-run Bowtie" << endl;
121 void tooManySeqChars(const String<char>& read_name) {
122 cerr << "Reads file contained a pattern with more than 1024 sequence characters." << endl
123 << "Please truncate reads and quality values and and re-run Bowtie." << endl
124 << "Offending read: " << read_name << endl;
129 * C++ version char* style "itoa":
131 char* itoa10(int value, char* result) {
132 // Check that base is valid
134 int quotient = value;
136 *out = "0123456789"[ std::abs( quotient % 10 ) ];
139 } while ( quotient );
141 // Only apply negative sign for base 10
142 if (value < 0) *out++ = '-';
143 std::reverse( result, out );
145 *out = 0; // terminator