alignmentSummary.ssp 6.94 KB
Newer Older
1
#import(nl.lumc.sasc.biopet.utils.summary.db.Schema._)
Peter van 't Hof's avatar
Peter van 't Hof committed
2
#import(nl.lumc.sasc.biopet.utils.summary.db.SummaryDb)
Peter van 't Hof's avatar
Peter van 't Hof committed
3 4
#import(nl.lumc.sasc.biopet.utils.summary.db.SummaryDb._)
#import(nl.lumc.sasc.biopet.utils.summary.db.SummaryDb.Implicts._)
5
#import(nl.lumc.sasc.biopet.core.report.ReportPage)
Peter van 't Hof's avatar
Peter van 't Hof committed
6 7
#import(scala.concurrent.Await)
#import(scala.concurrent.duration.Duration)
8 9
#import(nl.lumc.sasc.biopet.pipelines.bammetrics.BammetricsReport)
#import(java.io.File)
Peter van 't Hof's avatar
Peter van 't Hof committed
10 11 12
<%@ var summary: SummaryDb %>
<%@ var sampleId: Option[Int] = None %>
<%@ var libId: Option[Int] = None %>
13 14
<%@ var sampleLevel: Boolean = false %>
<%@ var rootPath: String %>
15 16 17
<%@ var outputDir: File %>
<%@ var showPlot: Boolean = false %>
<%@ var showTable: Boolean = true %>
18
<%@ var showIntro: Boolean = true%>
Peter van 't Hof's avatar
Peter van 't Hof committed
19
<%@ var runId: Int %>
20 21
<%@ var allSamples: Seq[Sample] %>
<%@ var allLibraries: Seq[Library] %>
22
#{
23 24 25 26
    val samples = sampleId match {
    case Some(id) => allSamples.filter(_.id == id).toList
    case _ => allSamples.toList
    }
27
}#
28 29 30 31 32 33
#if (showIntro)
    <br/>
    <div class="row">
    <div class="col-md-1"></div>
    <div class="col-md-6">
        <p>
34 35
        #if (sampleId.isDefined && libId.isDefined)
            Here we show basic <a href="https://en.wikibooks.org/wiki/Next_Generation_Sequencing_%28NGS%29/Alignment">alignment</a> statistics for this run for sample ${sampleId} with library ${libId}. Total number of reads, number of alignments reads and number of duplicate reads are given, and the percentages thereof as a percentage of total.
Sander Bollen's avatar
Sander Bollen committed
36
        #elseif(sampleId.isDefined && showPlot)
37
            The following plot shows basic <a href="https://en.wikibooks.org/wiki/Next_Generation_Sequencing_%28NGS%29/Alignment">alignment</a> statistics for this run for sample ${sampleId}. Every library is represented by a multi-color bar. Red represents the total number of properly mapped reads for this sample. Green represents the total number of duplicates reads, which is usually caused by <a href="http://www.cureffi.org/2012/12/11/how-pcr-duplicates-arise-in-next-generation-sequencing/">PCR duplicates</a>. Blue denotes the number of unmapped reads, and purple denotes reads flagged <em>secondary</em> (this depends on the aligner used). A table showing similar statistics, including values represented as percent of total, can be downloaded as a tab-delimited file.
Sander Bollen's avatar
Sander Bollen committed
38 39
        #elseif(sampleId.isDefined && !showPlot)
            Here we show basic <a href="https://en.wikibooks.org/wiki/Next_Generation_Sequencing_%28NGS%29/Alignment">alignment</a> statistics for this run for every library of sample ${sampleId}. Total number of reads, number of alignments reads and number of duplicate reads are given, and the percentages thereof as a percentage of total.
40 41 42
        #else
            The following plot shows basic <a href="https://en.wikibooks.org/wiki/Next_Generation_Sequencing_%28NGS%29/Alignment">alignment</a> statistics for this run. Every sample is represented by a multi-color bar. Red represents the total number of properly mapped reads for this sample. Green represents the total number of duplicates reads, which is usually caused by <a href="http://www.cureffi.org/2012/12/11/how-pcr-duplicates-arise-in-next-generation-sequencing/">PCR duplicates</a>. Blue denotes the number of unmapped reads, and purple denotes reads flagged <em>secondary</em> (this is dependent on the aligner used). A table showing similar statistics, including values represented as percent of total, can be downloaded as a tab-delimited file.
        #end
43 44 45 46
        </p>
    </div>
    </div>
#end
47 48
#if (showPlot)
#{ BammetricsReport.alignmentSummaryPlot(outputDir, "alignmentSummary", summary, !sampleLevel, sampleId = sampleId) }#
49 50 51 52 53

    <div class="panel-body">
        <img src="alignmentSummary.png" class="img-responsive" />
    </div>
        <div class="panel-footer">
Peter van 't Hof's avatar
Peter van 't Hof committed
54
            #if (showTable)
55 56
                <button type="button" class="btn btn-info" data-toggle="collapse" data-target="#alignmentSummaryTable">
                <i class="glyphicon glyphicon-eye-close"></i> Hide table</button>
Peter van 't Hof's avatar
Peter van 't Hof committed
57
            #else
58 59
                <button type="button" class="btn btn-info" data-toggle="collapse" data-target="#alignmentSummaryTable">
                <i class="glyphicon glyphicon-eye-open"></i> Show table</button>
Peter van 't Hof's avatar
Peter van 't Hof committed
60
            #end
61
            <a href="alignmentSummary.tsv"><button type="button" class="btn btn-info"><i class="glyphicon glyphicon-cloud-download"></i> TSV file</button></a>
62
        </div>
63
#end
Peter van 't Hof's avatar
Peter van 't Hof committed
64 65
<div class="panel-body collapse #if (showTable)in#end" id="alignmentSummaryTable">
<!-- Table -->
66
<table class="table">
Peter van 't Hof's avatar
Peter van 't Hof committed
67 68 69 70 71
    <thead><tr>
        <th data-sorted="true" data-sorted-direction="ascending">Sample</th>
        #if (!sampleLevel) <th>Library</th> #end
        <th>Total</th>
        <th>Mapped</th>
72
        <th>Secondary</th>
Peter van 't Hof's avatar
Peter van 't Hof committed
73 74 75 76 77
        <th>(%)</th>
        <th>Duplicates</th>
        <th>(%)</th>
    </tr></thead>
    <tbody>
Peter van 't Hof's avatar
Peter van 't Hof committed
78
        #for (sample <- samples.sortBy(_.name))
Peter van 't Hof's avatar
Peter van 't Hof committed
79
            #{
Peter van 't Hof's avatar
Peter van 't Hof committed
80 81 82
                val libs: List[Option[Int]] = (libId, sampleLevel) match {
                case (_, true) => List(None)
                case (Some(_), _) => List(libId)
83
                case _ => allLibraries.filter(_.sampleId == sample.id).map(x => Some(x.id)).toList
Peter van 't Hof's avatar
Peter van 't Hof committed
84 85
                }
            }#
86
            <tr><td rowspan="${libs.size}"><a href="${rootPath}Samples/${sample.name}/index.html">${sample.name}</a></td>
Peter van 't Hof's avatar
Peter van 't Hof committed
87
            #for (libId <- libs)
88
                #{ val libName = libId.map(l => allLibraries.find(_.id == l).get.name) }#
Peter van 't Hof's avatar
Peter van 't Hof committed
89
                #if (libs.head != libId) <tr> #end
90
                    #if (!sampleLevel) <td><a href="${rootPath}Samples/${sample.name}/Libraries/${libName}/index.html">${libName}</a></td> #end
Peter van 't Hof's avatar
Peter van 't Hof committed
91
                    #{
Peter van 't Hof's avatar
Peter van 't Hof committed
92 93 94 95 96 97
                        val statsPaths = Map(
                        "All" -> List("flagstats", "All"),
                        "Mapped" -> List("flagstats", "Mapped"),
                        "Duplicates" -> List("flagstats", "Duplicates"),
                        "NotPrimaryAlignment" -> List("flagstats", "NotPrimaryAlignment")
                        )
Peter van 't Hof's avatar
Peter van 't Hof committed
98
                        val results = summary.getStatKeys(runId, "bammetrics", "bamstats", sample = sample.id, library = libId.map(LibraryId).getOrElse(NoLibrary), keyValues = statsPaths)
Peter van 't Hof's avatar
Peter van 't Hof committed
99 100 101 102
                        val total = results("All").getOrElse(0L).asInstanceOf[Long]
                        val mapped = results("Mapped").getOrElse(0L).asInstanceOf[Long]
                        val duplicates = results("Duplicates").getOrElse(0L).asInstanceOf[Long]
                        val secondary = results("NotPrimaryAlignment").getOrElse(0L).asInstanceOf[Long]
Peter van 't Hof's avatar
Peter van 't Hof committed
103 104 105
                    }#
                    <td>${total}</td>
                    <td>${mapped}</td>
106 107
                    <td>${secondary}</td>
                    <td>${(mapped - secondary).toDouble / (total - secondary) * 100}%</td>
Peter van 't Hof's avatar
Peter van 't Hof committed
108
                    <td>${duplicates}</td>
109
                    <td>${duplicates.toDouble / (total - secondary) * 100}%</td>
Peter van 't Hof's avatar
Peter van 't Hof committed
110
                </tr>
111
            #end
Peter van 't Hof's avatar
Peter van 't Hof committed
112 113 114
        #end
    </tbody>
</table>
115

Peter van 't Hof's avatar
Peter van 't Hof committed
116
</div>