Skip to content

Commit

Permalink
support blank records
Browse files Browse the repository at this point in the history
  • Loading branch information
sfchen committed Feb 18, 2019
1 parent 90e5356 commit e01e940
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
19 changes: 13 additions & 6 deletions src/fastqreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ void FastqReader::clearLineBreaks(char* line) {
}

string FastqReader::getLine(){
static int c=0;
c++;
int copied = 0;

int start = mBufUsedLen;
Expand All @@ -112,7 +114,7 @@ string FastqReader::getLine(){
// skip \n or \r
end++;
// handle \r\n
if(end < mBufDataLen-1 && mBuf[end] == '\n')
if(end < mBufDataLen-1 && mBuf[end-1]=='\r' && mBuf[end] == '\n')
end++;

mBufUsedLen = end;
Expand Down Expand Up @@ -145,7 +147,6 @@ string FastqReader::getLine(){
end++;

mBufUsedLen = end;

return str;
}
// even this new buf is not enough, although impossible
Expand Down Expand Up @@ -179,21 +180,27 @@ Read* FastqReader::read(){
name = getLine();
}

if(name.empty())
return NULL;

string sequence = getLine();
string strand = getLine();

if(name.empty() || sequence.empty() || strand.empty())
return NULL;

// WAR for FQ with no quality
if (!mHasQuality){
string quality = string(sequence.length(), 'K');
return new Read(name, sequence, strand, quality, mPhred64);
}
else {
string quality = getLine();
if(quality.empty())
if(quality.length() != sequence.length()) {
cerr << "ERROR: sequence and quality have different length:" << endl;
cerr << name << endl;
cerr << sequence << endl;
cerr << strand << endl;
cerr << quality << endl;
return NULL;
}
return new Read(name, sequence, strand, quality, mPhred64);
}

Expand Down
4 changes: 2 additions & 2 deletions testdata/R1.fq
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@AS500713:64:HFKJJBGXY:1:11101:1675:1101 1:A:0:TATAGCCT+GACCCCCA
TAGGAGGCTTGGAGTACCAATAATAAAGTGAGCCCACCTTCCTGGTACCCAGACATTTCAGGAGGTCGGGAAATTTTTAAACCCAGGCAGCTTCCTGGCAGTGACATTTGGAGCATCAAAGTGGTAAATAAAATTTCATTTACATTAATAT

+
////AAEEEEE/E/EA/E/AEA6EE//AEE66/AAE//ZZZ////E/AA/EEE/A/AEE/EEA//EEEEEEEE6EEAAA/E/A/6E/6//6<EAAEEE/EEEA/EA/EEEEEE/<<EEEE//A/EE<AEEEEE/</AA</E<AAAE/E<E/

@AS500713:64:HFKJJBGXY:1:11101:17113:1101 1:A:0:TATAGCCT+GTTTCTTA
TACAAAATGCACATCGCTGAAAGGGGTAAAGGAGAGAAATCGCTTTATAAAACCTTGAAAAGGAATATTCAAATATAAGCTGGGAAGGTATAAAAAACTCTGTACATCACAAGTAAACAAATGGAACCTGCAAAATATTAAACAAAGGATT
+
Expand Down

0 comments on commit e01e940

Please sign in to comment.