Commit 4f2a0f07 authored by Peter van 't Hof's avatar Peter van 't Hof

Added a skip option in merge otu maps tool

parent bace55eb
...@@ -31,9 +31,14 @@ class MergeOtuMaps(val root: Configurable) extends ToolCommandFunction { ...@@ -31,9 +31,14 @@ class MergeOtuMaps(val root: Configurable) extends ToolCommandFunction {
@Output(doc = "Output", shortName = "output", required = true) @Output(doc = "Output", shortName = "output", required = true)
var output: File = _ var output: File = _
var skipPrefix: List[String] = config("skip_prefix", default = Nil)
override def defaultCoreMemory = 6.0 override def defaultCoreMemory = 6.0
override def cmdLine = super.cmdLine + repeat("-I", input) + required("-o", output) override def cmdLine = super.cmdLine +
repeat("-I", input) +
required("-o", output) +
repeat("-p", skipPrefix)
} }
...@@ -24,7 +24,9 @@ import scala.io.Source ...@@ -24,7 +24,9 @@ import scala.io.Source
* Created by pjvan_thof on 12/18/15. * Created by pjvan_thof on 12/18/15.
*/ */
object MergeOtuMaps extends ToolCommand { object MergeOtuMaps extends ToolCommand {
case class Args(inputFiles: List[File] = Nil, outputFile: File = null) extends AbstractArgs case class Args(inputFiles: List[File] = Nil,
outputFile: File = null,
skipPrefix: List[String] = Nil) extends AbstractArgs
class OptParser extends AbstractOptParser { class OptParser extends AbstractOptParser {
opt[File]('I', "input") minOccurs 2 required () unbounded () valueName "<file>" action { (x, c) => opt[File]('I', "input") minOccurs 2 required () unbounded () valueName "<file>" action { (x, c) =>
...@@ -33,6 +35,9 @@ object MergeOtuMaps extends ToolCommand { ...@@ -33,6 +35,9 @@ object MergeOtuMaps extends ToolCommand {
opt[File]('o', "output") required () unbounded () maxOccurs 1 valueName "<file>" action { (x, c) => opt[File]('o', "output") required () unbounded () maxOccurs 1 valueName "<file>" action { (x, c) =>
c.copy(outputFile = x) c.copy(outputFile = x)
} }
opt[String]('p', "skipPrefix") unbounded () valueName "<text>" action { (x, c) =>
c.copy(skipPrefix = x :: c.skipPrefix)
}
} }
/** /**
...@@ -40,23 +45,24 @@ object MergeOtuMaps extends ToolCommand { ...@@ -40,23 +45,24 @@ object MergeOtuMaps extends ToolCommand {
*/ */
def main(args: Array[String]): Unit = { def main(args: Array[String]): Unit = {
val argsParser = new OptParser val argsParser = new OptParser
val commandArgs: Args = argsParser.parse(args, Args()) getOrElse (throw new IllegalArgumentException) val cmdArgs: Args = argsParser.parse(args, Args()) getOrElse (throw new IllegalArgumentException)
var map: Map[Long, String] = Map() var map: Map[String, String] = Map()
for (inputFile <- commandArgs.inputFiles) { for (inputFile <- cmdArgs.inputFiles) {
logger.info(s"Start reading $inputFile") logger.info(s"Start reading $inputFile")
val reader = Source.fromFile(inputFile) val reader = Source.fromFile(inputFile)
reader.getLines().foreach { line => reader.getLines().foreach { line =>
val values = line.split("\t", 2) val values = line.split("\t", 2)
val key = values.head.toLong val key = values.head
map += key -> (line.stripPrefix(s"$key") + map.getOrElse(key, "")) if (!cmdArgs.skipPrefix.exists(key.startsWith))
map += key -> (line.stripPrefix(s"$key") + map.getOrElse(key, ""))
} }
reader.close() reader.close()
} }
logger.info(s"Start writing to ${commandArgs.outputFile}") logger.info(s"Start writing to ${cmdArgs.outputFile}")
val writer = new PrintWriter(commandArgs.outputFile) val writer = new PrintWriter(cmdArgs.outputFile)
map.foreach { case (key, list) => writer.println(key + list) } map.foreach { case (key, list) => writer.println(key + list) }
writer.close() writer.close()
} }
......
...@@ -37,6 +37,8 @@ class Gears(val root: Configurable) extends QScript with MultiSampleQScript { qs ...@@ -37,6 +37,8 @@ class Gears(val root: Configurable) extends QScript with MultiSampleQScript { qs
Some(gearsReport) Some(gearsReport)
} }
override def defaults = Map("mergeotumaps" -> Map("skip_prefix" -> "New."))
override def fixedValues = Map("gearssingle" -> Map("skip_flexiprep" -> true)) override def fixedValues = Map("gearssingle" -> Map("skip_flexiprep" -> true))
/** Init for pipeline */ /** Init for pipeline */
......
...@@ -43,7 +43,6 @@ object GearsReport extends MultisampleReportBuilder { ...@@ -43,7 +43,6 @@ object GearsReport extends MultisampleReportBuilder {
val qiimeOpenOtuTable = summary.getValue("gears", "files", "pipeline", "qiime_open_otu_table", "path") val qiimeOpenOtuTable = summary.getValue("gears", "files", "pipeline", "qiime_open_otu_table", "path")
.map(x => new File(x.toString)) .map(x => new File(x.toString))
ReportPage( ReportPage(
(if (krakenExecuted) List("Kraken analysis" -> ReportPage(List(), List( (if (krakenExecuted) List("Kraken analysis" -> ReportPage(List(), List(
"Krona plot" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp" "Krona plot" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/krakenKrona.ssp"
......
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