BammetricsReportPage.scala 8.95 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
package nl.lumc.sasc.biopet.pipelines.bammetrics

import nl.lumc.sasc.biopet.pipelines.bammetrics.BammetricsReport.mappingQualityPlotTables
import nl.lumc.sasc.biopet.utils.summary.db.Schema.{Library, Sample}
import nl.lumc.sasc.biopet.utils.summary.db.SummaryDb
import nl.lumc.sasc.biopet.utils.summary.db.SummaryDb.Implicts._
import nl.lumc.sasc.biopet.utils.summary.db.SummaryDb._

object BammetricsReportPage {
  def alignmentSummaryValues(summary: SummaryDb,
                             runId: Int,
                             allSamples: Seq[Sample],
                             allLibraries: Seq[Library],
                             sampleId: Option[Int] = None,
                             libId: Option[Int] = None,
                             sampleLevel: Boolean = false,
                             showPlot: Boolean = false,
                             showIntro: Boolean = true,
                             showTable: Boolean = true): Map[String, Any] = {

    val statsPaths = Map(
      "All" -> List("flagstats", "All"),
      "Mapped" -> List("flagstats", "Mapped"),
      "Duplicates" -> List("flagstats", "Duplicates"),
      "NotPrimaryAlignment" -> List("flagstats", "NotPrimaryAlignment")
    )
    val alignmentSummaryResults =
      summary.getStatsForLibraries(runId, "bammetrics", "bamstats", sampleId, statsPaths)
    val alignmentSummaryPlotLines: Option[Seq[String]] =
      if (showPlot)
        Some(BammetricsReport.alignmentSummaryPlotLines(summary, sampleId, !sampleLevel))
      else None
    Map(
      "alignmentSummaryResults" -> alignmentSummaryResults,
      "alignmentSummaryPlotLines" -> alignmentSummaryPlotLines,
      "sampleLevel" -> sampleLevel,
      "showPlot" -> showPlot,
      "showIntro" -> showIntro,
      "showTable" -> showTable,
      "sampleId" -> sampleId,
      "libId" -> libId
    )
  }

  def mappingQualityValues(summary: SummaryDb,
                           runId: Int,
                           allSamples: Seq[Sample],
                           allLibraries: Seq[Library],
                           sampleId: Option[Int],
                           libId: Option[Int],
                           fields: List[String] = List("min", "max", "mean", "median", "modal"),
                           sampleLevel: Boolean = false,
                           showPlot: Boolean = false,
                           showIntro: Boolean = true,
                           showTable: Boolean = true): Map[String, Any] = {

    val samples = sampleId match {
      case Some(id) => allSamples.filter(_.id == id).toList
      case _ => allSamples.toList
    }
61 62 63 64
    val mapQualityPlotTables: Option[Array[Map[String, Array[Any]]]] =
      if (showPlot)
        Some(mappingQualityPlotTables(summary, !sampleLevel, sampleId, libId))
      else None
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95

    val statsPaths = fields.map(x => x -> List("mapping_quality", "general", x)).toMap
    val mappingQualityTableResults: Map[(Int, Int), Map[String, Option[Any]]] =
      summary.getStatsForLibraries(runId, "bammetrics", "bamstats", sampleId, statsPaths)
    Map(
      "mappingQualityPlotTables" -> mapQualityPlotTables,
      "mappingQualityTableResults" -> mappingQualityTableResults,
      "showIntro" -> showIntro,
      "showTable" -> showTable,
      "showPlot" -> showPlot,
      "sampleId" -> sampleId,
      "libId" -> libId
    )
  }

  def clippingValues(summary: SummaryDb,
                     runId: Int,
                     allSamples: Seq[Sample],
                     allLibraries: Seq[Library],
                     sampleId: Option[Int],
                     libId: Option[Int],
                     fields: List[String] = List("min", "max", "mean", "median", "modal"),
                     sampleLevel: Boolean = false,
                     showPlot: Boolean = false,
                     showIntro: Boolean = true,
                     showTable: Boolean = true): Map[String, Any] = {

    val samples = sampleId match {
      case Some(id) => allSamples.filter(_.id == id).toList
      case _ => allSamples.toList
    }
96 97
    val clippingPlotTables: Option[Array[Map[String, Array[Any]]]] =
      if (showPlot)
Ruben Vorderman's avatar
Ruben Vorderman committed
98
        Some(BammetricsReport.clippingPlotTables(summary, !sampleLevel, sampleId, libId))
99 100
      else None

101
    val statsPaths = fields.map(x => x -> List("clipping", "general", x)).toMap
Ruben Vorderman's avatar
Ruben Vorderman committed
102
    val clippingTableResults = summary.getStatsForLibraries(runId, "bammetrics", "bamstats", sampleId, statsPaths)
103 104 105 106 107 108 109 110 111 112
    Map(
      "clippingPlotTables" -> clippingPlotTables,
      "clippingTableResults" -> clippingTableResults,
      "showIntro" -> showIntro,
      "showTable" -> showTable,
      "showPlot" -> showPlot,
      "sampleId" -> sampleId,
      "libId" -> libId
    )
  }
Ruben Vorderman's avatar
Ruben Vorderman committed
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146

  def insertSizeValues(summary: SummaryDb,
                       runId: Int,
                       allSamples: Seq[Sample],
                       allLibraries: Seq[Library],
                       sampleId: Option[Int],
                       libId: Option[Int],
                       fields: List[String] = List("mean_insert_size", "standard_deviation", "median_insert_size"),
                       sampleLevel: Boolean = false,
                       showPlot: Boolean = false,
                       showIntro: Boolean = true,
                       showTable: Boolean = true): Map[String, Any] = {

    val samples = sampleId match {
      case Some(id) => allSamples.filter(_.id == id).toList
      case _ => allSamples.toList
    }
    val insertSizePlotTables: Option[Array[Map[String, Array[Any]]]] =
      if (showPlot)
        Some(BammetricsReport.clippingPlotTables(summary, !sampleLevel, sampleId, libId))
      else None

    val statsPaths = fields.map(x => x -> List("metrics", x.toUpperCase)).toMap
    val insertSizeTableResults = summary.getStatsForLibraries(runId, "bammetrics", "CollectInsertSizeMetrics", sampleId, statsPaths)
    Map(
      "insertSizePlotTables" -> insertSizePlotTables,
      "insertSizeTableResults" -> insertSizeTableResults,
      "showIntro" -> showIntro,
      "showTable" -> showTable,
      "showPlot" -> showPlot,
      "sampleId" -> sampleId,
      "libId" -> libId
    )
  }
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
  def rnaHistogramValues(summary: SummaryDb,
                       runId: Int,
                       allSamples: Seq[Sample],
                       allLibraries: Seq[Library],
                       sampleId: Option[Int],
                       libId: Option[Int],
                       fields: List[String] = List("PF_ALIGNED_BASES", "MEDIAN_5PRIME_BIAS", "MEDIAN_3PRIME_BIAS", "MEDIAN_5PRIME_TO_3PRIME_BIAS"),
                       sampleLevel: Boolean = false,
                       showPlot: Boolean = false,
                       showIntro: Boolean = true,
                       showTable: Boolean = true): Map[String, Any] = {

    val samples = sampleId match {
      case Some(id) => allSamples.filter(_.id == id).toList
      case _ => allSamples.toList
    }
    val rnaHistogramPlotTables: Option[Array[Map[String, Array[Any]]]] =
      if (showPlot)
        Some(BammetricsReport.rnaHistogramPlotTables(summary, !sampleLevel, sampleId, libId))
      else None

    val statsPaths = fields.map(x => x -> List("metrics", x.toUpperCase)).toMap
    val rnaHistogramTableResults = summary.getStatsForLibraries(runId, "bammetrics", "rna", sampleId, statsPaths)
    Map(
      "rnaHistogramPlotTables" -> rnaHistogramPlotTables,
      "rnaHistogramTableResults" -> rnaHistogramTableResults,
      "showIntro" -> showIntro,
      "showTable" -> showTable,
      "showPlot" -> showPlot,
      "sampleId" -> sampleId,
      "libId" -> libId
    )
  }
  def wgsHistogramValues(summary: SummaryDb,
                         runId: Int,
                         allSamples: Seq[Sample],
                         allLibraries: Seq[Library],
                         sampleId: Option[Int],
                         libId: Option[Int],
                         fields: List[String] = List("mean_coverage", "pct_5x", "pct_10x", "pct_15x", "pct_20x", "pct_25x", "pct_30x", "pct_40x", "pct_50x", "pct_60x", "pct_70x", "pct_80x", "pct_90x", "pct_100x"),
                         sampleLevel: Boolean = false,
                         showPlot: Boolean = false,
                         showIntro: Boolean = true,
                         showTable: Boolean = true): Map[String, Any] = {

    val samples = sampleId match {
      case Some(id) => allSamples.filter(_.id == id).toList
      case _ => allSamples.toList
    }
    val wgsHistogramPlotTables: Option[Array[Map[String, Array[Any]]]] =
      if (showPlot)
        Some(BammetricsReport.wgsHistogramPlotTables(summary, !sampleLevel, sampleId, libId))
      else None

    val statsPaths = fields.map(x => x -> List("metrics", x.toUpperCase)).toMap
    val wgsHistogramTableResults = summary.getStatsForLibraries(runId, "bammetrics", "wgs", sampleId, statsPaths)
    Map(
      "wgsHistogramPlotTables" -> wgsHistogramPlotTables,
      "wgsHistogramTableResults" -> wgsHistogramTableResults,
      "showIntro" -> showIntro,
      "showTable" -> showTable,
      "showPlot" -> showPlot,
      "sampleId" -> sampleId,
      "libId" -> libId
    )
  }
213
}
Ruben Vorderman's avatar
Ruben Vorderman committed
214