Commit a913c55e authored by bow's avatar bow
Browse files

Refactor syncIter logic

parent 922b3949
...@@ -128,25 +128,23 @@ object FastqSync extends ToolCommand { ...@@ -128,25 +128,23 @@ object FastqSync extends ToolCommand {
(pre.headOption, seqA.headOption, seqB.headOption) match { (pre.headOption, seqA.headOption, seqB.headOption) match {
// where the magic happens! // where the magic happens!
case (Some(r), Some(a), Some(b)) => case (Some(r), Some(a), Some(b)) =>
// value of A iterator in the next recursion val (nextA, nextB) = (a.fragId == r.fragId, b.fragId == r.fragId) match {
val nextA = // all IDs are equal to ref
// hold A if its head is not equal to reference case (true, true) =>
if (a.fragId != r.fragId) { numKept += 1
if (b.fragId == r.fragId) numDiscB += 1 seqOutA.write(a)
seqA seqOutB.write(b)
// otherwise, go to next item (seqA.tail, seqB.tail)
} else seqA.tail // B not equal to ref and A is equal, then we discard A and progress
// like A above case (true, false) =>
val nextB = numDiscA += 1
if (b.fragId != r.fragId) { (seqA.tail, seqB)
if (a.fragId == r.fragId) numDiscA += 1 // A not equal to ref and B is equal, then we discard B and progress
seqB case (false, true) =>
} else seqB.tail numDiscB += 1
// write only if all IDs are equal (seqA, seqB.tail)
if (a.fragId == r.fragId && b.fragId == r.fragId) { case (false, false) =>
numKept += 1 (seqA, seqB)
seqOutA.write(a)
seqOutB.write(b)
} }
syncIter(pre.tail, nextA, nextB) syncIter(pre.tail, nextA, nextB)
// recursion base case: both iterators have been exhausted // recursion base case: both iterators have been exhausted
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment