From e01e9402c3d5afded49b21c8303be51d7cbb2d27 Mon Sep 17 00:00:00 2001 From: Shifu Chen Date: Mon, 18 Feb 2019 14:21:06 +0800 Subject: [PATCH] support blank records https://github.com/OpenGene/fastp/issues/133 --- src/fastqreader.cpp | 19 +++++++++++++------ testdata/R1.fq | 4 ++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/fastqreader.cpp b/src/fastqreader.cpp index 2d0005b..fb9babd 100644 --- a/src/fastqreader.cpp +++ b/src/fastqreader.cpp @@ -92,6 +92,8 @@ void FastqReader::clearLineBreaks(char* line) { } string FastqReader::getLine(){ + static int c=0; + c++; int copied = 0; int start = mBufUsedLen; @@ -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; @@ -145,7 +147,6 @@ string FastqReader::getLine(){ end++; mBufUsedLen = end; - return str; } // even this new buf is not enough, although impossible @@ -179,12 +180,12 @@ 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'); @@ -192,8 +193,14 @@ Read* FastqReader::read(){ } 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); } diff --git a/testdata/R1.fq b/testdata/R1.fq index a5a50f5..d7ca908 100644 --- a/testdata/R1.fq +++ b/testdata/R1.fq @@ -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