Fastqc.scala 3.77 KB
Newer Older
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
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.extensions

import java.io.File

19
import nl.lumc.sasc.biopet.core.{ Version, BiopetCommandLineFunction }
Peter van 't Hof's avatar
Peter van 't Hof committed
20
import nl.lumc.sasc.biopet.utils.config.Configurable
Peter van 't Hof's avatar
Peter van 't Hof committed
21
import org.broadinstitute.gatk.utils.commandline.{ Input, Output }
22

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

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

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

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

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

  executable = config("exe", default = "fastqc")
Sander Bollen's avatar
Sander Bollen committed
42
  var javaExe: String = config("exe", default = "java", namespace = "java", freeVar = false)
43
  var kmers: Option[Int] = config("kmers")
Peter van 't Hof's avatar
Peter van 't Hof committed
44
45
46
  var quiet: Boolean = config("quiet", default = false)
  var noextract: Boolean = config("noextract", default = false)
  var nogroup: Boolean = config("nogroup", default = false)
47
48
  var extract: Boolean = config("extract", default = true)

49
50
  def versionRegex = """FastQC (.*)""".r
  def versionCommand = executable + " --version"
Peter van 't Hof's avatar
Peter van 't Hof committed
51
  override def defaultThreads = 4
52

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

58
    val fastqcDir = new File(executable).getParent
bow's avatar
bow committed
59

60
    contaminants = contaminants match {
bow's avatar
bow committed
61
62
63
      // user-defined contaminants file take precedence
      case userDefinedValue @ Some(_) => userDefinedValue
      // otherwise, use default contaminants file (depending on FastQC version)
64
65
      case None =>
        val defaultContams = getVersion match {
66
67
          case Some("v0.11.2") => new File(fastqcDir + "/Configuration/contaminant_list.txt")
          case _               => new File(fastqcDir + "/Contaminants/contaminant_list.txt")
68
        }
bow's avatar
bow committed
69
70
71
72
73
74
75
76
        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 =>
77
        val defaultAdapters = getVersion match {
78
79
          case Some(v) if v.contains("v0.11") => Option(new File(fastqcDir + "/Configuration/adapter_list.txt"))
          case _                              => None
80
        }
bow's avatar
bow committed
81
        defaultAdapters.collect { case adp => config("adapters", default = adp) }
82
83
84
    }
  }

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