Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Scala Create an iterator using a Stream over 2 "aligned" files
test("Detect barcodes in forward and reverse reads in Fastq format") {
val readerR1 = new FastqReader(new java.io.File(getClass.getResource("/R1.fastq.gz").getPath))
val readerR2 = new FastqReader(new java.io.File(getClass.getResource("/R2.fastq.gz").getPath))
var list = List[String]()
case class Reads( r1: FastqRecord, r2: FastqRecord)
val stream: Stream[Reads]= {
def reads(readerR1: FastqReader, readerR2: FastqReader): Stream[Reads] = {
readerR1.hasNext() && readerR2.hasNext() match {
case true => Reads(readerR1.next(), readerR2.next()) #:: reads(readerR1, readerR2)
case _ => Stream.empty
}
}
reads(readerR1, readerR2)
}
for ( read <- stream) {
println(read.r1.getReadHeader)
println(read.r2.getReadHeader)
//list = list:+ TcrIndex.detect(barcode, read.r1, read.r2)
}
assert(list == List("1A1","1B4","" ,"" ,"" ,"" ,"" ,"" ,"" ,"" ,""))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment