Skip to content
Snippets Groups Projects
Commit 1b93ce1c authored by bow's avatar bow
Browse files

ExtractAlignedFastq fix for FASTQ records with descriptions

parent 9b5aa989
No related branches found
No related tags found
No related merge requests found
......@@ -21,6 +21,9 @@ object ExtractAlignedFastq extends ToolCommand {
type FastqInput = (FastqRecord, Option[FastqRecord])
/** function to get FastqRecord ID */
def fastqId(rec: FastqRecord) = rec.getReadHeader.split(" ")(0)
/**
* Function to create iterator over Interval given input interval string
*
......@@ -113,11 +116,12 @@ object ExtractAlignedFastq extends ToolCommand {
)
(pair: FastqInput) => pair._2 match {
case None => selected.contains(pair._1.getReadHeader)
case None => selected.contains(fastqId(pair._1))
case Some(x) =>
require(commonSuffixLength < pair._1.getReadHeader.length)
require(commonSuffixLength < x.getReadHeader.length)
selected.contains(pair._1.getReadHeader.dropRight(commonSuffixLength))
val rec1Id = fastqId(pair._1)
require(commonSuffixLength < rec1Id.length)
require(commonSuffixLength < fastqId(x).length)
selected.contains(rec1Id.dropRight(commonSuffixLength))
}
}
......@@ -224,6 +228,7 @@ object ExtractAlignedFastq extends ToolCommand {
minMapQ = commandArgs.minMapQ,
commonSuffixLength = commandArgs.commonSuffixLength)
logger.info("Writing to output file(s) ...")
(commandArgs.inputFastq2, commandArgs.outputFastq2) match {
case (None, None) => extractReads(memFunc,
......
@r01/1
@r01/1 hello
A
+
H
......
@r01/2
@r01/2 hello
T
+
I
......
......@@ -189,7 +189,7 @@ class ExtractAlignedFastqUnitTest extends TestNGSuite with MockitoSugar with Mat
}
@Test def testWriteSingleFastqDefault() = {
val memFunc = (recs: FastqInput) => Set("r01", "r03").contains(recs._1.getReadHeader)
val memFunc = (recs: FastqInput) => Set("r01", "r03").contains(fastqId(recs._1))
val in1 = new FastqReader(resourceFile("/single01.fq"))
val mo1 = mock[BasicFastqWriter]
val obs = inOrd(mo1)
......@@ -201,15 +201,15 @@ class ExtractAlignedFastqUnitTest extends TestNGSuite with MockitoSugar with Mat
@Test def testWritePairFastqDefault() = {
val mockSet = Set("r01/1", "r01/2", "r03/1", "r03/2")
val memFunc = (recs: FastqInput) => mockSet.contains(recs._1.getReadHeader) || mockSet.contains(recs._2.get.getReadHeader)
val memFunc = (recs: FastqInput) => mockSet.contains(fastqId(recs._1)) || mockSet.contains(fastqId(recs._2.get))
val in1 = new FastqReader(resourceFile("/paired01a.fq"))
val in2 = new FastqReader(resourceFile("/paired01b.fq"))
val mo1 = mock[BasicFastqWriter]
val mo2 = mock[BasicFastqWriter]
val obs = inOrd(mo1, mo2)
extractReads(memFunc, in1, mo1, in2, mo2)
obs.verify(mo1).write(new FastqRecord("r01/1", "A", "", "H"))
obs.verify(mo2).write(new FastqRecord("r01/2", "T", "", "I"))
obs.verify(mo1).write(new FastqRecord("r01/1 hello", "A", "", "H"))
obs.verify(mo2).write(new FastqRecord("r01/2 hello", "T", "", "I"))
obs.verify(mo1).write(new FastqRecord("r03/1", "G", "", "H"))
obs.verify(mo2).write(new FastqRecord("r03/2", "C", "", "I"))
verify(mo1, times(2)).write(anyObject.asInstanceOf[FastqRecord])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment