LinePlot.scala 2.68 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
package nl.lumc.sasc.biopet.utils.rscript
Peter van 't Hof's avatar
Peter van 't Hof committed
16
17
18

import java.io.File

Peter van 't Hof's avatar
Peter van 't Hof committed
19
import nl.lumc.sasc.biopet.utils.config.Configurable
Peter van 't Hof's avatar
Peter van 't Hof committed
20
21

/**
Peter van 't Hof's avatar
Peter van 't Hof committed
22
23
 * Extension for en general line plot with R
 *
Peter van 't Hof's avatar
Peter van 't Hof committed
24
25
 * Created by pjvan_thof on 4/29/15.
 */
Peter van 't Hof's avatar
Peter van 't Hof committed
26
class LinePlot(val parent: Configurable) extends Rscript {
Peter van 't Hof's avatar
Peter van 't Hof committed
27
28
29
30
31
32
33
34
35
36
37
38
  protected var script: File = config("script", default = "plotXY.R")

  var input: File = _

  var output: File = _

  var width: Option[Int] = config("width")
  var height: Option[Int] = config("height")
  var xlabel: Option[String] = config("xlabel")
  var ylabel: Option[String] = config("ylabel")
  var llabel: Option[String] = config("llabel")
  var title: Option[String] = config("title")
39
  var hideLegend: Boolean = config("hide_legend", default = false)
40
  var removeZero: Boolean = config("removeZero", default = false)
Peter van 't Hof's avatar
Peter van 't Hof committed
41

42
43
44
45
46
47
48
49
50
  override def cmd = super.cmd ++
    Seq("--input", input.getAbsolutePath) ++
    Seq("--output", output.getAbsolutePath) ++
    width.map(x => Seq("--width", x.toString)).getOrElse(Seq()) ++
    height.map(x => Seq("--height", x.toString)).getOrElse(Seq()) ++
    xlabel.map(Seq("--xlabel", _)).getOrElse(Seq()) ++
    ylabel.map(Seq("--ylabel", _)).getOrElse(Seq()) ++
    llabel.map(Seq("--llabel", _)).getOrElse(Seq()) ++
    title.map(Seq("--title", _)).getOrElse(Seq()) ++
51
    (if (hideLegend) Seq("--hideLegend", "true") else Seq()) ++
Peter van 't Hof's avatar
Peter van 't Hof committed
52
    (if (removeZero) Seq("--removeZero", "true") else Seq())
Peter van 't Hof's avatar
Peter van 't Hof committed
53
}
Peter van 't Hof's avatar
Peter van 't Hof committed
54
55
56
57
58
59
60
61

object LinePlot {
  def apply(inputTsv: File,
            outputFile: File,
            root: Configurable = null,
            xlabel: Option[String] = None,
            ylabel: Option[String] = None,
            width: Int = 1200,
62
            hideLegend: Boolean = false,
Peter van 't Hof's avatar
Peter van 't Hof committed
63
64
65
66
67
68
69
70
            removeZero: Boolean = false,
            title: Option[String] = None): LinePlot = {
    val plot = new LinePlot(root)
    plot.input = inputTsv
    plot.output = outputFile
    plot.xlabel = xlabel
    plot.ylabel = ylabel
    plot.width = Some(width)
71
    plot.hideLegend = hideLegend
Peter van 't Hof's avatar
Peter van 't Hof committed
72
73
74
75
76
    plot.removeZero = removeZero
    plot.title = title
    plot
  }
}