GearsQiimeOpen.scala 2.89 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
/**
 * 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
 *
 * A dual licensing mode is applied. The source code within this project 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.pipelines.gears

import nl.lumc.sasc.biopet.core.SampleLibraryTag
import nl.lumc.sasc.biopet.core.summary.SummaryQScript
import nl.lumc.sasc.biopet.extensions.qiime._
import nl.lumc.sasc.biopet.extensions.seqtk.SeqtkSample
import nl.lumc.sasc.biopet.utils.config.Configurable
import org.broadinstitute.gatk.queue.QScript

/**
 * Created by pjvan_thof on 12/4/15.
 */
class GearsQiimeOpen(val root: Configurable) extends QScript with SummaryQScript with SampleLibraryTag {

  var fastqInput: File = _

  override def defaults = Map(
    "splitlibrariesfastq" -> Map(
      "barcode_type" -> "not-barcoded"
    )
  )

  def init() = {
    require(fastqInput != null)
    require(sampleId.isDefined)
  }

  private var _otuMap: File = _
  def otuMap = _otuMap

  private var _otuTable: File = _
  def otuTable = _otuTable

  def biopetScript() = {

    val splitLib = new SplitLibrariesFastq(this)
    splitLib.input :+= fastqInput
    splitLib.outputDir = new File(outputDir, "split_libraries_fastq")
    sampleId.foreach(splitLib.sampleIds :+= _.replaceAll("_", "-"))
Peter van 't Hof's avatar
Peter van 't Hof committed
54
    splitLib.isIntermediate = true
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
    add(splitLib)

    val openReference = new PickOpenReferenceOtus(this)
    openReference.inputFasta = addDownsample(splitLib.outputSeqs, new File(splitLib.outputDir, s"${sampleId.get}.downsample.fna"))
    openReference.outputDir = new File(outputDir, "pick_open_reference_otus")
    add(openReference)
    _otuMap = openReference.otuMap
    _otuTable = openReference.otuTable

    addSummaryJobs()
  }

  /** 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("otu_table" -> otuTable, "otu_map" -> otuMap)

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

  val downSample: Option[Double] = config("downsample")

  def addDownsample(input: File, output: File): File = {
    downSample match {
      case Some(x) =>
        val seqtk = new SeqtkSample(this)
        seqtk.input = input
        seqtk.sample = x
        seqtk.output = output
        add(seqtk)
        output
      case _ => input
    }
  }
}