Fastqc.scala 3.76 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/**
 * 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 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.
 */
16
17
18
19
20
21
package nl.lumc.sasc.biopet.extensions

import java.io.File

import org.broadinstitute.gatk.utils.commandline.{ Input, Output }

Peter van 't Hof's avatar
Peter van 't Hof committed
22
23
import nl.lumc.sasc.biopet.core.BiopetCommandLineFunction
import nl.lumc.sasc.biopet.core.config.Configurable
24

Peter van 't Hof's avatar
Peter van 't Hof committed
25
26
27
28
/**
 * Extension for fastqc
 * Based on version 0.10.1 and 0.11.2
 */
29
30
31
class Fastqc(val root: Configurable) extends BiopetCommandLineFunction {

  @Input(doc = "Contaminants", required = false)
32
  var contaminants: Option[File] = None
Peter van 't Hof's avatar
Peter van 't Hof committed
33

34
  @Input(doc = "Adapters", required = false)
35
  var adapters: Option[File] = None
36
37

  @Input(doc = "Fastq file", shortName = "FQ")
bow's avatar
bow committed
38
  var fastqfile: File = null
39

Peter van 't Hof's avatar
Peter van 't Hof committed
40
  @Output(doc = "Output", shortName = "out", required = true)
bow's avatar
bow committed
41
  var output: File = null
42
43

  executable = config("exe", default = "fastqc")
44
  var java_exe: String = config("exe", default = "java", submodule = "java", freeVar = false)
45
  var kmers: Option[Int] = config("kmers")
Peter van 't Hof's avatar
Peter van 't Hof committed
46
47
48
  var quiet: Boolean = config("quiet", default = false)
  var noextract: Boolean = config("noextract", default = false)
  var nogroup: Boolean = config("nogroup", default = false)
49
50
51
52
53
54
  var extract: Boolean = config("extract", default = true)

  override val versionRegex = """FastQC (.*)""".r
  override def versionCommand = executable + " --version"
  override val defaultThreads = 4

Peter van 't Hof's avatar
Peter van 't Hof committed
55
  /** Sets contaminants and adapters when not yet set */
56
  override def beforeGraph {
Peter van 't Hof's avatar
Peter van 't Hof committed
57
    this.jobOutputFile = new File(output.getParentFile, ".fastqc.out")
58
    this.preProcesExecutable
bow's avatar
bow committed
59

60
    val fastqcDir = new File(executable).getParent
bow's avatar
bow committed
61

62
    contaminants = contaminants match {
bow's avatar
bow committed
63
64
65
      // user-defined contaminants file take precedence
      case userDefinedValue @ Some(_) => userDefinedValue
      // otherwise, use default contaminants file (depending on FastQC version)
66
67
      case None =>
        val defaultContams = getVersion match {
68
69
          case Some("v0.11.2") => new File(fastqcDir + "/Configuration/contaminant_list.txt")
          case _               => new File(fastqcDir + "/Contaminants/contaminant_list.txt")
70
        }
bow's avatar
bow committed
71
72
73
74
75
76
77
78
        config("contaminants", default = defaultContams)
    }

    adapters = adapters match {
      // user-defined contaminants file take precedence
      case userDefinedValue @ Some(_) => userDefinedValue
      // otherwise, check if adapters are already present (depending on FastQC version)
      case None =>
79
        val defaultAdapters = getVersion match {
80
81
          case Some("v0.11.2") => Option(new File(fastqcDir + "/Configuration/adapter_list.txt"))
          case _               => None
82
        }
bow's avatar
bow committed
83
        defaultAdapters.collect { case adp => config("adapters", default = adp) }
84
85
86
    }
  }

Peter van 't Hof's avatar
Peter van 't Hof committed
87
  /** return commandline to execute */
88
89
90
91
  def cmdLine = required(executable) +
    optional("--java", java_exe) +
    optional("--threads", threads) +
    optional("--contaminants", contaminants) +
92
    optional("--adapters", adapters) +
93
94
95
96
97
    optional("--kmers", kmers) +
    conditional(nogroup, "--nogroup") +
    conditional(noextract, "--noextract") +
    conditional(extract, "--extract") +
    conditional(quiet, "--quiet") +
98
    required("-o", output.getParent) +
99
100
    required(fastqfile)
}