PrintReads.scala 6.04 KB
Newer Older
1
2
3
4
5
/**
 * Due to the license issue with GATK, this part of Biopet can only be used inside the
 * LUMC. Please refer to https://git.lumc.nl/biopet/biopet/wikis/home for instructions
 * on how to use this protected part of biopet or contact us at sasc@lumc.nl
 */
Peter van 't Hof's avatar
Peter van 't Hof committed
6
package nl.lumc.sasc.biopet.extensions.gatk.broad
7
8

import java.io.File
Peter van 't Hof's avatar
Peter van 't Hof committed
9

Peter van 't Hof's avatar
Peter van 't Hof committed
10
import nl.lumc.sasc.biopet.utils.config.Configurable
Peter van 't Hof's avatar
Peter van 't Hof committed
11
import org.broadinstitute.gatk.queue.extensions.gatk.{ BamGatherFunction, GATKScatterFunction, ReadScatterFunction }
Peter van 't Hof's avatar
Peter van 't Hof committed
12
import nl.lumc.sasc.biopet.core.ScatterGatherableFunction
Peter van 't Hof's avatar
Peter van 't Hof committed
13
import org.broadinstitute.gatk.utils.commandline._
14

Peter van 't Hof's avatar
Peter van 't Hof committed
15
class PrintReads(val root: Configurable) extends CommandLineGATK with ScatterGatherableFunction {
16
  def analysis_type = "PrintReads"
Peter van 't Hof's avatar
Peter van 't Hof committed
17
18
19
20
21
22
23
24
25
26
  scatterClass = classOf[ReadScatterFunction]
  setupScatterFunction = { case scatter: GATKScatterFunction => scatter.includeUnmapped = true }

  /** Write output to this BAM filename instead of STDOUT */
  @Output(fullName = "out", shortName = "o", doc = "Write output to this BAM filename instead of STDOUT", required = false, exclusiveOf = "", validation = "")
  @Gather(classOf[BamGatherFunction])
  var out: File = _

  /** Exclude all reads with this read group from the output */
  @Argument(fullName = "readGroup", shortName = "readGroup", doc = "Exclude all reads with this read group from the output", required = false, exclusiveOf = "", validation = "")
27
  var readGroup: Option[String] = config("readGroup", default = false)
Peter van 't Hof's avatar
Peter van 't Hof committed
28
29
30

  /** Exclude all reads with this platform from the output */
  @Argument(fullName = "platform", shortName = "platform", doc = "Exclude all reads with this platform from the output", required = false, exclusiveOf = "", validation = "")
31
  var platform: Option[String] = config("platform")
Peter van 't Hof's avatar
Peter van 't Hof committed
32
33
34

  /** Print the first n reads from the file, discarding the rest */
  @Argument(fullName = "number", shortName = "n", doc = "Print the first n reads from the file, discarding the rest", required = false, exclusiveOf = "", validation = "")
35
  var number: Option[Int] = config("number")
Peter van 't Hof's avatar
Peter van 't Hof committed
36
37
38

  /** File containing a list of samples (one per line). Can be specified multiple times */
  @Argument(fullName = "sample_file", shortName = "sf", doc = "File containing a list of samples (one per line). Can be specified multiple times", required = false, exclusiveOf = "", validation = "")
39
  var sample_file: List[File] = config("sample_file", default = Nil)
Peter van 't Hof's avatar
Peter van 't Hof committed
40
41
42

  /** Sample name to be included in the analysis. Can be specified multiple times. */
  @Argument(fullName = "sample_name", shortName = "sn", doc = "Sample name to be included in the analysis. Can be specified multiple times.", required = false, exclusiveOf = "", validation = "")
43
  var sample_name: List[String] = config("sample_name", default = Nil)
Peter van 't Hof's avatar
Peter van 't Hof committed
44
45
46

  /** Simplify all reads */
  @Argument(fullName = "simplify", shortName = "s", doc = "Simplify all reads", required = false, exclusiveOf = "", validation = "")
47
  var simplify: Boolean = config("simplify", default = false)
Peter van 't Hof's avatar
Peter van 't Hof committed
48
49
50

  /** Don't output a program tag */
  @Argument(fullName = "no_pg_tag", shortName = "npt", doc = "Don't output a program tag", required = false, exclusiveOf = "", validation = "")
51
  var no_pg_tag: Boolean = config("no_pg_tag", default = false)
Peter van 't Hof's avatar
Peter van 't Hof committed
52
53
54

  /** Filter out reads with CIGAR containing the N operator, instead of failing with an error */
  @Argument(fullName = "filter_reads_with_N_cigar", shortName = "filterRNC", doc = "Filter out reads with CIGAR containing the N operator, instead of failing with an error", required = false, exclusiveOf = "", validation = "")
55
  var filter_reads_with_N_cigar: Boolean = config("filter_reads_with_N_cigar", default = false)
Peter van 't Hof's avatar
Peter van 't Hof committed
56
57
58

  /** Filter out reads with mismatching numbers of bases and base qualities, instead of failing with an error */
  @Argument(fullName = "filter_mismatching_base_and_quals", shortName = "filterMBQ", doc = "Filter out reads with mismatching numbers of bases and base qualities, instead of failing with an error", required = false, exclusiveOf = "", validation = "")
59
  var filter_mismatching_base_and_quals: Boolean = config("filter_mismatching_base_and_quals", default = false)
Peter van 't Hof's avatar
Peter van 't Hof committed
60
61
62

  /** Filter out reads with no stored bases (i.e. '*' where the sequence should be), instead of failing with an error */
  @Argument(fullName = "filter_bases_not_stored", shortName = "filterNoBases", doc = "Filter out reads with no stored bases (i.e. '*' where the sequence should be), instead of failing with an error", required = false, exclusiveOf = "", validation = "")
63
  var filter_bases_not_stored: Boolean = config("filter_bases_not_stored", default = false)
Peter van 't Hof's avatar
Peter van 't Hof committed
64
65
66
67
68

  override def freezeFieldValues() {
    super.freezeFieldValues()
    if (out != null && !org.broadinstitute.gatk.utils.io.IOUtils.isSpecialFile(out))
      if (!disable_bam_indexing)
69
        outputFiles :+= new File(out.getPath.stripSuffix(".bam") + ".bai")
Peter van 't Hof's avatar
Peter van 't Hof committed
70
71
    if (out != null && !org.broadinstitute.gatk.utils.io.IOUtils.isSpecialFile(out))
      if (generate_md5)
72
        outputFiles :+= new File(out.getPath + ".md5")
73
  }
Peter van 't Hof's avatar
Peter van 't Hof committed
74
75
76
77
78
79
80
81
82
83
84
85
86
87

  override def cmdLine = super.cmdLine +
    optional("-o", out, spaceSeparated = true, escape = true, format = "%s") +
    optional("-readGroup", readGroup, spaceSeparated = true, escape = true, format = "%s") +
    optional("-platform", platform, spaceSeparated = true, escape = true, format = "%s") +
    optional("-n", number, spaceSeparated = true, escape = true, format = "%s") +
    repeat("-sf", sample_file, spaceSeparated = true, escape = true, format = "%s") +
    repeat("-sn", sample_name, spaceSeparated = true, escape = true, format = "%s") +
    conditional(simplify, "-s", escape = true, format = "%s") +
    conditional(no_pg_tag, "-npt", escape = true, format = "%s") +
    conditional(filter_reads_with_N_cigar, "-filterRNC", escape = true, format = "%s") +
    conditional(filter_mismatching_base_and_quals, "-filterMBQ", escape = true, format = "%s") +
    conditional(filter_bases_not_stored, "-filterNoBases", escape = true, format = "%s")
}
Peter van 't Hof's avatar
Peter van 't Hof committed
88
89
90
91
92
93
94
95
96

object PrintReads {
  def apply(root: Configurable, input: File, output: File): PrintReads = {
    val br = new PrintReads(root)
    br.input_file :+= input
    br.out = output
    br
  }
}