CombineReads.scala 4 KB
Newer Older
Peter van 't Hof's avatar
Peter van 't Hof committed
1 2 3 4 5 6 7 8 9 10
/**
 * 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 2014 Sequencing Analysis Support Core - Leiden University Medical Center
 *
 * Contact us at: sasc@lumc.nl
 *
11
 * A dual licensing mode is applied. The source code within this project is freely available for non-commercial use under an AGPL
Peter van 't Hof's avatar
Peter van 't Hof committed
12 13 14
 * license; For commercial users or users who do not want to follow the AGPL
 * license, please contact us to obtain a separate license.
 */
15 16 17 18
package nl.lumc.sasc.biopet.pipelines.gears

import nl.lumc.sasc.biopet.core.SampleLibraryTag
import nl.lumc.sasc.biopet.core.summary.SummaryQScript
Peter van 't Hof's avatar
Peter van 't Hof committed
19
import nl.lumc.sasc.biopet.extensions.{ Cutadapt, Flash }
20
import nl.lumc.sasc.biopet.pipelines.flexiprep.Fastqc
21 22 23 24
import nl.lumc.sasc.biopet.utils.config.Configurable
import org.broadinstitute.gatk.queue.QScript

/**
Peter van 't Hof's avatar
Peter van 't Hof committed
25 26
 * Created by pjvanthof on 29/12/15.
 */
27 28 29 30 31 32
class CombineReads(val root: Configurable) extends QScript with SummaryQScript with SampleLibraryTag {
  @Input(doc = "R1 reads in FastQ format", shortName = "R1", required = false)
  var fastqR1: File = _

  @Input(doc = "R2 reads in FastQ format", shortName = "R2", required = false)
  var fastqR2: File = _
Peter van 't Hof's avatar
Peter van 't Hof committed
33

34
  override def fixedValues = Map("flash" -> Map("compress" -> true))
Peter van 't Hof's avatar
Peter van 't Hof committed
35

36 37 38 39
  /** Init for pipeline */
  def init(): Unit = {
  }

40 41
  private lazy val flash = new Flash(this)

Peter van 't Hof's avatar
Peter van 't Hof committed
42 43
  private lazy val forwardPrimers: List[String] = config("forward_primers", default = Nil)
  private lazy val reversePrimers: List[String] = config("reverse_primers", default = Nil)
Peter van 't Hof's avatar
Peter van 't Hof committed
44

Peter van 't Hof's avatar
Peter van 't Hof committed
45
  def combinedFastq: File = if ((forwardPrimers ::: reversePrimers).nonEmpty)
46 47 48
    swapExt(outputDir, flash.combinedFastq, ".fastq.gz", ".clip.fastq.gz")
  else flash.combinedFastq

Peter van 't Hof's avatar
Peter van 't Hof committed
49
  def notCombinedR1Fastq: File = if ((forwardPrimers ::: reversePrimers).nonEmpty)
50 51 52
    swapExt(outputDir, flash.notCombinedR1, ".fastq.gz", ".clip.fastq.gz")
  else flash.notCombinedR1

Peter van 't Hof's avatar
Peter van 't Hof committed
53
  def notCombinedR2Fastq: File = if ((forwardPrimers ::: reversePrimers).nonEmpty)
54 55 56
    swapExt(outputDir, flash.notCombinedR2, ".fastq.gz", ".clip.fastq.gz")
  else flash.notCombinedR2

Peter van 't Hof's avatar
Peter van 't Hof committed
57 58
  val keepFastaqFiles: Boolean = config("keep_fastq_files", default = false)

59 60 61 62 63
  /** Pipeline itself */
  def biopetScript(): Unit = {
    flash.outputDirectory = new File(outputDir, "flash")
    flash.fastqR1 = fastqR1
    flash.fastqR2 = fastqR2
Peter van 't Hof's avatar
Peter van 't Hof committed
64
    flash.isIntermediate = !keepFastaqFiles || (forwardPrimers ::: reversePrimers).nonEmpty
65
    add(flash)
66 67 68

    if ((forwardPrimers ::: reversePrimers).nonEmpty) {
      val cutadapt = new Cutadapt(this)
Peter van 't Hof's avatar
Peter van 't Hof committed
69 70 71
      cutadapt.fastqInput = flash.combinedFastq
      cutadapt.fastqOutput = this.combinedFastq
      cutadapt.statsOutput = swapExt(outputDir, cutadapt.fastqOutput, ".fastq.gz", ".stats")
Peter van 't Hof's avatar
Peter van 't Hof committed
72
      cutadapt.isIntermediate = !keepFastaqFiles
Peter van 't Hof's avatar
Peter van 't Hof committed
73
      (forwardPrimers ::: reversePrimers).foreach(cutadapt.anywhere += _)
74 75 76
      add(cutadapt)
      addSummarizable(cutadapt, "cutadapt")
    }
Peter van 't Hof's avatar
Peter van 't Hof committed
77

78 79 80 81 82 83 84 85 86 87 88
    val combinedFastqc = Fastqc(this, this.combinedFastq, new File(outputDir, "combined_fastqc"))
    add(combinedFastqc)
    addSummarizable(combinedFastqc, "fastqc_combined")

    val notCombinedR1Fastqc = Fastqc(this, this.combinedFastq, new File(outputDir, "not_combined_R1_fastqc"))
    add(notCombinedR1Fastqc)
    addSummarizable(notCombinedR1Fastqc, "fastqc_not_combined_R1")

    val notCombinedR2Fastqc = Fastqc(this, this.combinedFastq, new File(outputDir, "not_combined_R2_fastqc"))
    add(notCombinedR2Fastqc)
    addSummarizable(notCombinedR2Fastqc, "fastqc_not_combined_R2")
Peter van 't Hof's avatar
Peter van 't Hof committed
89 90

    addSummaryJobs()
91 92 93 94 95 96 97 98 99 100 101
  }

  /** Must return a map with used settings for this pipeline */
  def summarySettings: Map[String, Any] = Map()

  /** File to put in the summary for thie pipeline */
  def summaryFiles: Map[String, File] = Map()

  /** Name of summary output file */
  def summaryFile: File = new File(outputDir, "combine_reads.summary.json")
}