Commit 2ac35f9a authored by Wai Yi Leung's avatar Wai Yi Leung
Browse files

Changes to conform to Scala syntax

parent b6fac4e1
/**
* Biopet is built on top of GATK Queue for building bioinformatic
* pipelines. It is mainly intended to support LUMC SHARK cluster which is running
* SGE. But other types of HPC that are supported by GATK Queue (such as PBS)
* should also be able to execute Biopet tools and pipelines.
*
* Copyright 2015 Sequencing Analysis Support Core - Leiden University Medical Center
*
* Contact us at: sasc@lumc.nl
*
* A dual licensing mode is applied. The source code within this project that are
* not part of GATK Queue is freely available for non-commercial use under an AGPL
* license; For commercial users or users who do not want to follow the AGPL
* license, please contact us to obtain a separate license.
*/
package nl.lumc.sasc.biopet.extensions
import java.io.File
import org.broadinstitute.gatk.utils.commandline.{ Input, Output }
import nl.lumc.sasc.biopet.core.{BiopetJavaCommandLineFunction, BiopetCommandLineFunction}
import nl.lumc.sasc.biopet.core.config.Configurable
/**
* Wrapper for the Cnmops command line tool.
* Written based on Cnmops version v2.2.1.
*/
class Cnmops(val root: Configurable) extends BiopetJavaCommandLineFunction {
javaMainClass = getClass.getName
/** input file */
@Input(doc = "Input file BAM", required = true)
var input: List[File] = List()
/** output files, computed automatically from output directory */
@Output(doc = "Output CNV file")
lazy val output_cnv: File = {
if (output_dir == null)
throw new RuntimeException("Unexpected error when trying to set cn.MOPS CNV output")
new File(output_dir, "cnv.txt")
}
@Output(doc = "Output CNR file")
lazy val output_cnr: File = {
if (output_dir == null)
throw new RuntimeException("Unexpected error when trying to set cn.MOPS CNR output")
new File(output_dir, "cnr.txt")
}
/** write all output files to this directory [./] */
var output_dir: String = _
override def beforeGraph = {
super.beforeGraph
require(!output_dir.isEmpty, "Outputdir for cn.MOPS should not be empty")
require(input.length > 1, "Please supply at least 2 BAM files for cn.MOPS")
}
override val versionRegex = """Cnmops v(.*)""".r
override def versionCommand = executable
def cmdLine = {
required(executable) +
required("--output-dir", output_dir) +
required(input)
}
}
package nl.lumc.sasc.biopet.extensions
import java.io.File
import nl.lumc.sasc.biopet.core.BiopetCommandLineFunction
import org.broadinstitute.gatk.utils.commandline.Input
/**
* Created by wyleung on 17-2-15.
*/
trait RscriptCommandLineFunction extends BiopetCommandLineFunction{
@Input(doc = "R script", required = false)
var script: File = _
protected var scriptName: String = _
executable = config("exe", default = "Rscript", submodule = "R")
/**
* Set the Rscript to run
*
* @param filename RScript file location
*/
def setScript(filename: File) = {
}
def setScript(filename: File, subpackage: String) = {
}
}
......@@ -10,7 +10,7 @@ import org.broadinstitute.gatk.utils.commandline.{ Output, Input }
import scala.collection.JavaConverters._
import scala.collection.mutable
import scala.collection.immutable.{ Map }
import scala.collection.immutable.Map
import scala.io.Source
import scala.language.postfixOps
......@@ -32,20 +32,20 @@ class Seqstat(val root: Configurable) extends BiopetJavaCommandLineFunction {
javaMainClass = getClass.getName
@Input(doc = "Input FASTQ", shortName = "input", required = true)
var input: File = _
var input: File = null
@Output(doc = "Output JSON", shortName = "output", required = true)
var output: File = _
var output: File = null
override val defaultVmem = "4G"
memoryLimit = Option(3.0)
override def commandLine = super.commandLine + required("-i", input) + " > " + required(output)
def getSummary: Json = {
def summary: Json = {
val json = Parse.parseOption(Source.fromFile(output).mkString)
if (json.isEmpty) return jNull
else return json.get.fieldOrEmptyObject("stats")
if (json.isEmpty) jNull
else json.get.fieldOrEmptyObject("stats")
}
}
......@@ -61,7 +61,7 @@ object Seqstat extends ToolCommand {
val seqstat = new Seqstat(root)
seqstat.input = input
seqstat.output = output
return seqstat
seqstat
}
def apply(root: Configurable, fastqfile: File, outDir: String): Seqstat = {
......@@ -69,7 +69,7 @@ object Seqstat extends ToolCommand {
val ext = fastqfile.getName.substring(fastqfile.getName.lastIndexOf("."))
seqstat.input = fastqfile
seqstat.output = new File(outDir + fastqfile.getName.substring(0, fastqfile.getName.lastIndexOf(".")) + ".seqstats.json")
return seqstat
seqstat
}
def mergeSummaries(jsons: List[Json]): Json = {
......@@ -101,7 +101,7 @@ object Seqstat extends ToolCommand {
val reads = json.fieldOrEmptyObject("reads")
addJson(reads, readsTotal)
}
return ("bases" := (
("bases" := (
("num_n" := basesTotal("num_n")) ->:
("num_total" := basesTotal("num_total")) ->:
("num_qual_gte" := (
......@@ -254,7 +254,7 @@ object Seqstat extends ToolCommand {
}
// implicit conversion to Int using foldLeft(0)
val avgQual: Int = (readQual.foldLeft(0)(_ + _) / readQual.length)
val avgQual: Int = (readQual.sum / readQual.length)
if (readStats.qual.length <= avgQual) {
readStats.qual ++= mutable.ArrayBuffer.fill(avgQual - readStats.qual.length + 1)(0)
}
......
......@@ -149,25 +149,25 @@ class FlexiprepSummary(val root: Configurable) extends InProcessFunction with Co
}
def seqstatSummary(): Option[Json] = {
val R1_chunks = for ((key, value) <- chunks) yield value.seqstatR1.getSummary
val R1_chunks = for ((key, value) <- chunks) yield value.seqstatR1.summary
val R1: Json = Seqstat.mergeSummaries(R1_chunks.toList)
val R2: Option[Json] = if (!flexiprep.paired) None
else if (chunks.size == 1) Option(chunks.head._2.seqstatR2.getSummary)
else if (chunks.size == 1) Option(chunks.head._2.seqstatR2.summary)
else {
val s = for ((key, value) <- chunks) yield value.seqstatR2.getSummary
val s = for ((key, value) <- chunks) yield value.seqstatR2.summary
Option(Seqstat.mergeSummaries(s.toList))
}
val R1_proc: Option[Json] = if (flexiprep.skipClip && flexiprep.skipTrim) None
else if (chunks.size == 1) Option(chunks.head._2.seqstatR1after.getSummary)
else if (chunks.size == 1) Option(chunks.head._2.seqstatR1after.summary)
else {
val s = for ((key, value) <- chunks) yield value.seqstatR1after.getSummary
val s = for ((key, value) <- chunks) yield value.seqstatR1after.summary
Option(Seqstat.mergeSummaries(s.toList))
}
val R2_proc: Option[Json] = if (!flexiprep.paired || (flexiprep.skipClip && flexiprep.skipTrim)) None
else if (chunks.size == 1) Option(chunks.head._2.seqstatR2after.getSummary)
else if (chunks.size == 1) Option(chunks.head._2.seqstatR2after.summary)
else {
val s = for ((key, value) <- chunks) yield value.seqstatR2after.getSummary
val s = for ((key, value) <- chunks) yield value.seqstatR2after.summary
Option(Seqstat.mergeSummaries(s.toList))
}
return Option(("R1_raw" := R1) ->:
......
Supports Markdown
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