Skip to content
Snippets Groups Projects
Commit a14358bf authored by Peter van 't Hof's avatar Peter van 't Hof
Browse files

Fix count fastq

parent b611f85e
No related branches found
No related tags found
No related merge requests found
......@@ -15,10 +15,12 @@
*/
package nl.lumc.sasc.biopet.tools
import java.io.{ File, FileReader, PrintWriter }
import java.io.{ File, PrintWriter }
import htsjdk.samtools.fastq.FastqReader
import nl.lumc.sasc.biopet.utils.ToolCommand
import org.biojava3.sequencing.io.fastq.{ Fastq, StreamListener, SangerFastqReader }
import scala.collection.JavaConversions._
import scala.collection.{ SortedMap, mutable }
......@@ -44,19 +46,18 @@ object SageCountFastq extends ToolCommand {
if (!commandArgs.input.exists) throw new IllegalStateException("Input file not found, file: " + commandArgs.input)
val counts: mutable.Map[String, Long] = mutable.Map()
val reader = new SangerFastqReader
val reader: FastqReader = new FastqReader(commandArgs.input)
var count = 0
logger.info("Reading fastq file: " + commandArgs.input)
val fileReader = new FileReader(commandArgs.input)
reader.stream(fileReader, new StreamListener {
def fastq(fastq: Fastq) {
val seq = fastq.getSequence
if (counts.contains(seq)) counts(seq) += 1
else counts += (seq -> 1)
count += 1
if (count % 1000000 == 0) logger.info(count + " sequences done")
}
})
for (read <- reader.iterator()) {
val seq = read.getReadString
if (counts.contains(seq)) counts(seq) += 1
else counts += (seq -> 1)
count += 1
}
reader.close()
logger.info(count + " sequences done")
logger.info("Sorting")
......
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