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

Start on basecounter

parent dc31e3e8
No related branches found
No related tags found
Loading
package nl.lumc.sasc.biopet.tools
import java.io.File
import htsjdk.samtools.{SAMRecord, SamReaderFactory}
import nl.lumc.sasc.biopet.utils.ToolCommand
import nl.lumc.sasc.biopet.utils.intervals.{BedRecord, BedRecordList}
import scala.collection.JavaConversions._
import scala.collection.mutable
/**
* Created by pjvanthof on 22/01/16.
*/
object BaseCounter extends ToolCommand {
case class Args(bedFile: File = null,
outputDir: File = null,
bamFile: File = null) extends AbstractArgs
class OptParser extends AbstractOptParser {
opt[File]("bedFile") required () valueName "<file>" action { (x, c) =>
c.copy(bedFile = x)
}
opt[File]('o', "outputDir") required () valueName "<file>" action { (x, c) =>
c.copy(outputDir = x)
}
opt[File]('b', "bam") required () valueName "<file>" action { (x, c) =>
c.copy(bamFile = x)
}
}
def main(args: Array[String]): Unit = {
val argsParser = new OptParser
val cmdArgs: Args = argsParser.parse(args, Args()) getOrElse(throw new IllegalArgumentException(""))
val bedrecords = BedRecordList.fromFile(cmdArgs.bedFile).combineOverlap
val counts = for (region <- bedrecords.allRecords) yield {
val bamReader = SamReaderFactory.makeDefault.open(cmdArgs.bamFile)
val interval = region.toSamInterval
val samIterator = bamReader.queryOverlapping(interval.getContig, interval.getStart, interval.getEnd)
for (samRecord <- samIterator) samRecordToCounts(samRecord, region.originals())
}
}
def samRecordToCounts(samRecord: SAMRecord, bedRecords: List[BedRecord]): Unit = {
samRecord.getAlignmentBlocks.foreach { x =>
val bedStart = x.getReferenceStart - 1
val bedEnd = bedStart + x.getLength
}
}
}
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