Commit 08070144 authored by Peter van 't Hof's avatar Peter van 't Hof
Browse files

Switch to sample based analysis

parent c5669b7b
......@@ -52,10 +52,10 @@ object Zcat {
zcat
}
def apply(root: Configurable, input: List[File], output: File): Zcat = {
def apply(root: Configurable, input: List[File], output: File = null): Zcat = {
val zcat = new Zcat(root)
zcat.input = input
zcat.output = output
if (output != null) zcat.output = output
zcat
}
}
\ No newline at end of file
package nl.lumc.sasc.biopet.pipelines.gears
import nl.lumc.sasc.biopet.core.{ PipelineCommand, MultiSampleQScript }
import nl.lumc.sasc.biopet.extensions.Ln
import nl.lumc.sasc.biopet.extensions.qiime.{MergeOtuMaps, MergeOtuTables}
import nl.lumc.sasc.biopet.utils.Logging
import nl.lumc.sasc.biopet.extensions.{Gzip, Zcat, Ln}
import nl.lumc.sasc.biopet.extensions.qiime.{ MergeOtuMaps, MergeOtuTables }
import nl.lumc.sasc.biopet.pipelines.flexiprep.Flexiprep
import nl.lumc.sasc.biopet.utils.config.Configurable
import org.broadinstitute.gatk.queue.QScript
......@@ -20,6 +20,8 @@ class Gears(val root: Configurable) extends QScript with MultiSampleQScript { qs
Some(gearsReport)
}
override def fixedValues = Map("gearssingle" -> Map("skip_flexiprep" -> true))
/** Init for pipeline */
def init(): Unit = {
}
......@@ -37,8 +39,9 @@ class Gears(val root: Configurable) extends QScript with MultiSampleQScript { qs
* Method where the multisample jobs should be added, this will be executed only when running the -sample argument is not given.
*/
def addMultiSampleJobs(): Unit = {
val closedOtuTables = samples.values.flatMap(_.closedOtuTable).toList
val closedOtuMaps = samples.values.flatMap(_.closedOtuMap).toList
val gss = samples.values.flatMap(_.gs.qiimeClosed).toList
val closedOtuTables = gss.map(_.otuTable)
val closedOtuMaps = gss.map(_.otuMap)
require(closedOtuTables.size == closedOtuMaps.size)
if (closedOtuTables.nonEmpty) {
val closedDir = new File(outputDir, "qiime_closed_reference")
......@@ -82,22 +85,26 @@ class Gears(val root: Configurable) extends QScript with MultiSampleQScript { qs
def makeLibrary(id: String): Library = new Library(id)
class Library(libId: String) extends AbstractLibrary(libId) {
val flexiprep = new Flexiprep(qscript)
flexiprep.input_R1 = config("R1")
flexiprep.input_R2 = config("R2")
flexiprep.outputDir = new File(libDir, "flexiprep")
lazy val gs = new GearsSingle(qscript)
gs.sampleId = Some(sampleId)
gs.libId = Some(libId)
gs.outputDir = libDir
gs.fastqR1 = config("R1")
gs.fastqR2 = config("R2")
gs.bamFile = config("bam")
/** Function that add library jobs */
protected def addJobs(): Unit = {
add(flexiprep)
if (gs.fastqR1.isDefined || gs.bamFile.isDefined) {
gs.init()
gs.biopetScript()
addAll(gs.functions)
addSummaryQScript(gs)
} else Logging.addError(s"Sample: '$sampleId', library: '$libId', No input files found")
gs.fastqR1 = Some(flexiprep.fastqR1Qc)
gs.fastqR2 = flexiprep.fastqR2Qc
add(gs)
}
}
/** Must return files to store into summary */
......@@ -107,40 +114,30 @@ class Gears(val root: Configurable) extends QScript with MultiSampleQScript { qs
def summaryStats = Map()
}
private var _closedOtuTable: Option[File] = _
def closedOtuTable = _closedOtuTable
private var _closedOtuMap: Option[File] = _
def closedOtuMap = _closedOtuMap
lazy val gs = new GearsSingle(qscript)
gs.sampleId = Some(sampleId)
gs.outputDir = sampleDir
/** Function to add sample jobs */
protected def addJobs(): Unit = {
addPerLibJobs()
val qiimeClosed = libraries.values.flatMap(_.gs.qiimeClosed).toList
if (qiimeClosed.nonEmpty) {
_closedOtuTable = Some(new File(sampleDir, "closed.biom"))
_closedOtuMap = Some(new File(sampleDir, "closed.map.txt"))
if (qiimeClosed.size > 1) {
val mergeTables = new MergeOtuTables(qscript)
mergeTables.input = qiimeClosed.map(_.otuTable).toList
mergeTables.outputFile = _closedOtuTable.get
add(mergeTables)
val mergeMaps = new MergeOtuMaps(qscript)
mergeMaps.input = qiimeClosed.map(_.otuMap).toList
mergeMaps.outputFile = _closedOtuMap.get
add(mergeMaps)
} else {
add(Ln(qscript, qiimeClosed.head.otuMap, _closedOtuMap.get))
add(Ln(qscript, qiimeClosed.head.otuTable, _closedOtuTable.get))
}
//TODO: Plots
} else {
_closedOtuTable = None
_closedOtuMap = None
val flexipreps = libraries.values.map(_.flexiprep).toList
val mergeR1: File = new File(sampleDir, s"$sampleId.R1.fq.gz")
add(Zcat(qscript, flexipreps.map(_.fastqR1Qc)) | new Gzip(qscript) > mergeR1)
val mergeR2 = if (flexipreps.exists(_.paired)) {
Some(new File(sampleDir, s"$sampleId.R2.fq.gz"))
} else None
mergeR2.foreach { file =>
add(Zcat(qscript, flexipreps.flatMap(_.fastqR2Qc)) | new Gzip(qscript) > file)
}
gs.fastqR1 = Some(mergeR1)
gs.fastqR2 = mergeR2
add(gs)
}
/** Must return files to store into summary */
......
......@@ -73,45 +73,50 @@ class GearsSingle(val root: Configurable) extends QScript with SummaryQScript wi
Some(gears)
}
protected def executeFlexiprep(r1: File, r2: Option[File]): (File, Option[File]) = {
if (config("skip_flexiprep", default = false)) {
val flexiprep = new Flexiprep(this)
flexiprep.input_R1 = r1
flexiprep.input_R2 = r2
flexiprep.outputDir = new File(outputDir, "flexiprep")
add(flexiprep)
(flexiprep.fastqR1Qc, flexiprep.fastqR2Qc)
} else (r1, r2)
}
/** Method to add jobs */
def biopetScript(): Unit = {
val (r1, r2): (File, Option[File]) = (fastqR1, fastqR2, bamFile) match {
case (Some(r1), _, _) => (r1, fastqR2)
case (Some(r1), _, _) => executeFlexiprep(r1, fastqR2)
case (_, _, Some(bam)) =>
val extract = new ExtractUnmappedReads(this)
extract.outputDir = outputDir
extract.bamFile = bam
extract.outputName = outputName
add(extract)
(extract.fastqUnmappedR1, Some(extract.fastqUnmappedR2))
executeFlexiprep(extract.fastqUnmappedR1, Some(extract.fastqUnmappedR2))
case _ => throw new IllegalArgumentException("Missing input files")
}
val flexiprep = new Flexiprep(this)
flexiprep.input_R1 = r1
flexiprep.input_R2 = r2
flexiprep.outputDir = new File(outputDir, "flexiprep")
add(flexiprep)
krakenScript foreach { kraken =>
kraken.outputDir = new File(outputDir, "kraken")
kraken.fastqR1 = flexiprep.fastqR1Qc
kraken.fastqR2 = flexiprep.fastqR2Qc
kraken.fastqR1 = r1
kraken.fastqR2 = r2
kraken.outputName = outputName
add(kraken)
}
qiimeRatx foreach { qiimeRatx =>
qiimeRatx.outputDir = new File(outputDir, "qiime_rtax")
qiimeRatx.fastqR1 = flexiprep.fastqR1Qc
qiimeRatx.fastqR2 = flexiprep.fastqR2Qc
qiimeRatx.fastqR1 = r1
qiimeRatx.fastqR2 = r2
add(qiimeRatx)
}
qiimeClosed foreach { qiimeClosed =>
qiimeClosed.outputDir = new File(outputDir, "qiime_closed")
qiimeClosed.fastqR1 = flexiprep.fastqR1Qc
qiimeClosed.fastqR2 = flexiprep.fastqR2Qc
qiimeClosed.fastqR1 = r1
qiimeClosed.fastqR2 = r2
add(qiimeClosed)
//TODO: Plots
......
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