Commit 5badc583 authored by Peter van 't Hof's avatar Peter van 't Hof

Added output file

parent 4ec46159
package nl.lumc.sasc.biopet.tools
import java.io.File
import java.io.{File, PrintStream, PrintWriter}
import nl.lumc.sasc.biopet.utils.ToolCommand
......@@ -12,16 +12,20 @@ import scala.io.Source
*/
object FindOverlapMatch extends ToolCommand {
case class Args(inputVcf: File = null,
case class Args(inputMetrics: File = null,
outputFile: Option[File] = None,
cutoff: Double = 0.0) extends AbstractArgs
class OptParser extends AbstractOptParser {
opt[File]('i', "input") required () unbounded () valueName "<file>" action { (x, c) =>
c.copy(inputVcf = x)
}
c.copy(inputMetrics = x)
} text "Input should be a table where the first row and column have the ID's, those can be different"
opt[File]('o', "output") unbounded () valueName "<file>" action { (x, c) =>
c.copy(outputFile = Some(x))
} text "default to stdout"
opt[Double]('c', "cutoff") required () unbounded () valueName "<value>" action { (x, c) =>
c.copy(cutoff = x)
}
} text "minimum value to report it as pair"
}
/**
......@@ -29,23 +33,29 @@ object FindOverlapMatch extends ToolCommand {
*/
def main(args: Array[String]): Unit = {
val argsParser = new OptParser
val cmdargs: Args = argsParser.parse(args, Args()) getOrElse (throw new IllegalArgumentException)
val cmdArgs: Args = argsParser.parse(args, Args()) getOrElse (throw new IllegalArgumentException)
val reader = Source.fromFile(cmdargs.inputVcf)
val reader = Source.fromFile(cmdArgs.inputMetrics)
val data = reader.getLines().map(_.split("\t")).toArray
val samples = data.head.zipWithIndex.tail
val samplesColumnHeader = data.head.zipWithIndex.tail
val samplesRowHeader = data.map(_.head).zipWithIndex.tail
var overlap = 0
var multiOverlap = 0
var noOverlap = 0
for (i1 <- samples) {
val writer = cmdArgs.outputFile match {
case Some(file) => new PrintStream(file)
case _ => sys.process.stdout
}
for (i1 <- samplesColumnHeader) {
val buffer = ListBuffer[(String, Double)]()
for (i2 <- samples) {
for (i2 <- samplesRowHeader) {
val value = data(i1._2)(i2._2).toDouble
if (value >= cmdargs.cutoff && i1._2 != i2._2) {
if (value >= cmdArgs.cutoff && i1._2 != i2._2) {
buffer.+=((i2._1, value))
}
}
......@@ -53,10 +63,11 @@ object FindOverlapMatch extends ToolCommand {
else noOverlap += 1
if (buffer.size > 1) multiOverlap += 1
println(s"${i1._1}\t${buffer.mkString("\t")}")
writer.println(s"${i1._1}\t${buffer.mkString("\t")}")
}
logger.info(s"$overlap found")
logger.info(s"no $noOverlap found")
logger.info(s"multi $multiOverlap found")
writer.close()
}
}
Markdown is supported
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