From 9332161d6448ae0ae319d2cea2bf5a338000aa8c Mon Sep 17 00:00:00 2001 From: Peter van 't Hof <p.j.van_t_hof@lumc.nl> Date: Thu, 16 Apr 2015 13:19:18 +0200 Subject: [PATCH] Switch to multi metrics --- .../pipelines/bammetrics/BamMetrics.scala | 15 ++-- .../picard/CollectMultipleMetrics.scala | 73 +++++++++++++++++++ 2 files changed, 79 insertions(+), 9 deletions(-) create mode 100644 public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CollectMultipleMetrics.scala diff --git a/public/bammetrics/src/main/scala/nl/lumc/sasc/biopet/pipelines/bammetrics/BamMetrics.scala b/public/bammetrics/src/main/scala/nl/lumc/sasc/biopet/pipelines/bammetrics/BamMetrics.scala index 574adb382..8c94ac09c 100644 --- a/public/bammetrics/src/main/scala/nl/lumc/sasc/biopet/pipelines/bammetrics/BamMetrics.scala +++ b/public/bammetrics/src/main/scala/nl/lumc/sasc/biopet/pipelines/bammetrics/BamMetrics.scala @@ -63,15 +63,12 @@ class BamMetrics(val root: Configurable) extends QScript with SummaryQScript wit add(biopetFlagstat) addSummarizable(biopetFlagstat, "biopet_flagstat") - add(CollectGcBiasMetrics(this, inputBam, outputDir)) - - val collectInsertSizeMetrics = CollectInsertSizeMetrics(this, inputBam, outputDir) - add(collectInsertSizeMetrics) - addSummarizable(collectInsertSizeMetrics, "insert_size_metrics") + val multiMetrics = new CollectMultipleMetrics(this) + multiMetrics.input = inputBam + multiMetrics.outputName = new File(outputDir, inputBam.getName.stripSuffix(".bam")) + add(multiMetrics) - val collectAlignmentSummaryMetrics = CollectAlignmentSummaryMetrics(this, inputBam, outputDir) - add(collectAlignmentSummaryMetrics) - addSummarizable(collectAlignmentSummaryMetrics, "alignment_metrics") + add(CollectGcBiasMetrics(this, inputBam, outputDir)) case class Intervals(bed: File, intervals: File) @@ -135,7 +132,7 @@ class BamMetrics(val root: Configurable) extends QScript with SummaryQScript wit } object BamMetrics extends PipelineCommand { - /** Make default implementation of BamMetrics */ + /** Make default implementation of BamMetrics and runs script already */ def apply(root: Configurable, bamFile: File, outputDir: File): BamMetrics = { val bamMetrics = new BamMetrics(root) bamMetrics.inputBam = bamFile diff --git a/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CollectMultipleMetrics.scala b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CollectMultipleMetrics.scala new file mode 100644 index 000000000..e2e7cd49b --- /dev/null +++ b/public/biopet-framework/src/main/scala/nl/lumc/sasc/biopet/extensions/picard/CollectMultipleMetrics.scala @@ -0,0 +1,73 @@ +package nl.lumc.sasc.biopet.extensions.picard + +import java.io.File + +import nl.lumc.sasc.biopet.core.BiopetQScript +import nl.lumc.sasc.biopet.core.config.Configurable +import org.broadinstitute.gatk.utils.commandline.{ Output, Argument, Input } + +/** + * Created by pjvan_thof on 4/16/15. + */ +class CollectMultipleMetrics(val root: Configurable) extends Picard { + import CollectMultipleMetrics._ + + javaMainClass = new picard.analysis.CollectMultipleMetrics().getClass.getName + + @Input(doc = "The input SAM or BAM files to analyze", required = true) + var input: File = null + + @Output(doc = "Base name of output files", required = true) + var outputName: File = null + + @Argument(doc = "Base name of output files", required = true) + var program: List[String] = config("metrics_programs", + default = Programs.values.iterator.toList.map(_.toString)) + + @Argument(doc = "Assume alignment file is sorted by position", required = false) + var assumeSorted: Boolean = config("assume_sorted", default = false) + + @Argument(doc = "Stop after processing N reads", required = false) + var stopAfter: Option[Long] = config("stop_after") + + @Output + protected var outputFiles: List[File] = Nil + + override def beforeGraph: Unit = { + program.foreach(p => p match { + case _ if p == Programs.CollectAlignmentSummaryMetrics.toString => { + outputFiles :+= new File(outputName + ".alignment_summary_metrics") + } + case _ if p == Programs.CollectInsertSizeMetrics.toString => { + outputFiles :+= new File(outputName + ".insert_size_metrics") + outputFiles :+= new File(outputName + ".insert_size_Histogram.pdf") + } + case _ if p == Programs.QualityScoreDistribution.toString => { + outputFiles :+= new File(outputName + ".quality_distribution_metrics") + outputFiles :+= new File(outputName + ".test.quality_distribution.pdf") + } + case _ if p == Programs.MeanQualityByCycle.toString => { + outputFiles :+= new File(outputName + ".quality_by_cycle_metrics") + outputFiles :+= new File(outputName + ".quality_by_cycle.pdf") + } + case _ if p == Programs.CollectBaseDistributionByCycle.toString => { + outputFiles :+= new File(outputName + ".base_distribution_by_cycle_metrics") + outputFiles :+= new File(outputName + ".base_distribution_by_cycle.pdf") + } + case _ => BiopetQScript.addError("Program '" + p + "' does not exist for 'CollectMultipleMetrics'") + }) + } + + override def commandLine = super.commandLine + + required("INPUT=", input, spaceSeparated = false) + + required("OUTPUT=", outputName, spaceSeparated = false) + + required("ASSUME_SORTED=", assumeSorted, spaceSeparated = false) + + required("STOP_AFTER=", stopAfter, spaceSeparated = false) + + repeat("PROGRAM=", program, spaceSeparated = false) +} + +object CollectMultipleMetrics { + object Programs extends Enumeration { + val CollectAlignmentSummaryMetrics, CollectInsertSizeMetrics, QualityScoreDistribution, MeanQualityByCycle, CollectBaseDistributionByCycle = Value + } +} \ No newline at end of file -- GitLab