SummaryValue.scala 3.48 KB
Newer Older
Peter van 't Hof's avatar
Peter van 't Hof committed
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.
 */
Peter van 't Hof's avatar
Peter van 't Hof committed
16
17
18
package nl.lumc.sasc.biopet.core.summary

/**
19
20
 * This case class is used for easy access and calculations on those values
 *
Peter van 't Hof's avatar
Peter van 't Hof committed
21
22
 * Created by pjvan_thof on 4/23/15.
 */
23
case class SummaryValue(value: Option[Any]) {
Peter van 't Hof's avatar
Peter van 't Hof committed
24
25
26
27
28
29
30
31
32
33
34
35

  def this(path: List[String],
           summary: Summary,
           sampleId: Option[String] = None,
           libId: Option[String] = None) = {
    this((sampleId, libId) match {
      case (Some(sample), Some(lib)) => summary.getLibraryValue(sample, lib, path: _*)
      case (Some(sample), _)         => summary.getSampleValue(sample, path: _*)
      case _                         => summary.getValue(path: _*)
    })
  }

36
  //TODO: Calculations are not yet used somewhere, needs more testing
Peter van 't Hof's avatar
Peter van 't Hof committed
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
  def +(that: SummaryValue): SummaryValue = {
    (this.value, that.value) match {
      case (Some(a: Double), Some(b)) => SummaryValue(Some(a + b.toString.toDouble))
      case (Some(a: Int), Some(b))    => SummaryValue(Some(a + b.toString.toInt))
      case (Some(a), Some(b))         => SummaryValue(Some(a.toString.toDouble + b.toString.toDouble))
      case _                          => SummaryValue(None)
    }
  }

  def -(that: SummaryValue): SummaryValue = {
    (this.value, that.value) match {
      case (Some(a: Double), Some(b)) => SummaryValue(Some(a - b.toString.toDouble))
      case (Some(a: Int), Some(b))    => SummaryValue(Some(a - b.toString.toInt))
      case (Some(a), Some(b))         => SummaryValue(Some(a.toString.toDouble - b.toString.toDouble))
      case _                          => SummaryValue(None)
    }
  }

  def /(that: SummaryValue): SummaryValue = {
    (this.value, that.value) match {
      case (Some(a: Double), Some(b)) => SummaryValue(Some(a / b.toString.toDouble))
      case (Some(a: Int), Some(b))    => SummaryValue(Some(a / b.toString.toInt))
      case (Some(a), Some(b))         => SummaryValue(Some(a.toString.toDouble / b.toString.toDouble))
      case _                          => SummaryValue(None)
    }
  }

  def *(that: SummaryValue): SummaryValue = {
    (this.value, that.value) match {
      case (Some(a: Double), Some(b)) => SummaryValue(Some(a * b.toString.toDouble))
      case (Some(a: Int), Some(b))    => SummaryValue(Some(a * b.toString.toInt))
      case (Some(a), Some(b))         => SummaryValue(Some(a.toString.toDouble * b.toString.toDouble))
      case _                          => SummaryValue(None)
    }
  }

  def %(that: SummaryValue): SummaryValue = {
    (this.value, that.value) match {
      case (Some(a: Double), Some(b)) => SummaryValue(Some(a % b.toString.toDouble))
      case (Some(a: Int), Some(b))    => SummaryValue(Some(a % b.toString.toInt))
      case (Some(a), Some(b))         => SummaryValue(Some(a.toString.toDouble % b.toString.toDouble))
      case _                          => SummaryValue(None)
    }
  }
}