LinePlot.scala 2.69 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.
 */
26
class LinePlot(val root: 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 removeZero: Boolean = config("removeZero", default = false)
Peter van 't Hof's avatar
Peter van 't Hof committed
40

akaljuvee's avatar
akaljuvee committed
41 42 43 44
  // whether to use log scale for x and y axis
  var xLog10: Boolean = false
  var yLog10: Boolean = false

45 46 47 48 49 50 51 52 53
  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()) ++
akaljuvee's avatar
akaljuvee committed
54 55 56 57
    (if (removeZero) Seq("--removeZero", "true") else Seq()) ++
    (if (xLog10) Seq("--xLog10", "true") else Seq()) ++
    (if (yLog10) Seq("--yLog10", "true") else Seq())

Peter van 't Hof's avatar
Peter van 't Hof committed
58
}
Peter van 't Hof's avatar
Peter van 't Hof committed
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79

object LinePlot {
  def apply(inputTsv: File,
            outputFile: File,
            root: Configurable = null,
            xlabel: Option[String] = None,
            ylabel: Option[String] = None,
            width: Int = 1200,
            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)
    plot.removeZero = removeZero
    plot.title = title
    plot
  }
}