alignmentSummary.ssp 6.75 KB
Newer Older
Peter van 't Hof's avatar
Peter van 't Hof committed
1
#import(nl.lumc.sasc.biopet.utils.summary.db.SummaryDb)
2
#import(nl.lumc.sasc.biopet.core.report.ReportPage)
Peter van 't Hof's avatar
Peter van 't Hof committed
3
4
#import(scala.concurrent.Await)
#import(scala.concurrent.duration.Duration)
5
6
#import(nl.lumc.sasc.biopet.pipelines.bammetrics.BammetricsReport)
#import(java.io.File)
Peter van 't Hof's avatar
Peter van 't Hof committed
7
8
#import(scalaz._)
#import(Scalaz._)
Peter van 't Hof's avatar
Peter van 't Hof committed
9
10
11
<%@ var summary: SummaryDb %>
<%@ var sampleId: Option[Int] = None %>
<%@ var libId: Option[Int] = None %>
12
13
<%@ var sampleLevel: Boolean = false %>
<%@ var rootPath: String %>
14
15
16
<%@ var outputDir: File %>
<%@ var showPlot: Boolean = false %>
<%@ var showTable: Boolean = true %>
Peter van 't Hof's avatar
Peter van 't Hof committed
17
<%@ var showIntro: Boolean = true%>
Peter van 't Hof's avatar
Peter van 't Hof committed
18
<%@ var runId: Int %>
19
#{
Peter van 't Hof's avatar
Peter van 't Hof committed
20
    val samples = Await.result(summary.getSamples(runId = Some(runId)), Duration.Inf)
21
}#
Peter van 't Hof's avatar
Peter van 't Hof committed
22
23
24
25
26
27
#if (showIntro)
    <br/>
    <div class="row">
    <div class="col-md-1"></div>
    <div class="col-md-6">
        <p>
Sander Bollen's avatar
Sander Bollen committed
28
29
        #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
30
        #elseif(sampleId.isDefined && showPlot)
31
            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
32
33
        #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.
Sander Bollen's avatar
Sander Bollen committed
34
35
36
        #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
Peter van 't Hof's avatar
Peter van 't Hof committed
37
38
39
40
        </p>
    </div>
    </div>
#end
41
42
#if (showPlot)
#{ BammetricsReport.alignmentSummaryPlot(outputDir, "alignmentSummary", summary, !sampleLevel, sampleId = sampleId) }#
43
44
45
46
47

    <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
48
            #if (showTable)
49
50
                <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
51
            #else
52
53
                <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
54
            #end
55
            <a href="alignmentSummary.tsv"><button type="button" class="btn btn-info"><i class="glyphicon glyphicon-cloud-download"></i> TSV file</button></a>
56
        </div>
57
#end
Peter van 't Hof's avatar
Peter van 't Hof committed
58
59
<div class="panel-body collapse #if (showTable)in#end" id="alignmentSummaryTable">
<!-- Table -->
60
<table class="table">
Peter van 't Hof's avatar
Peter van 't Hof committed
61
62
63
64
65
    <thead><tr>
        <th data-sorted="true" data-sorted-direction="ascending">Sample</th>
        #if (!sampleLevel) <th>Library</th> #end
        <th>Total</th>
        <th>Mapped</th>
66
        <th>Secondary</th>
Peter van 't Hof's avatar
Peter van 't Hof committed
67
68
69
70
71
        <th>(%)</th>
        <th>Duplicates</th>
        <th>(%)</th>
    </tr></thead>
    <tbody>
Peter van 't Hof's avatar
Peter van 't Hof committed
72
        #for (sample <- samples.sortBy(_.name))
Peter van 't Hof's avatar
Peter van 't Hof committed
73
            #{
Peter van 't Hof's avatar
Peter van 't Hof committed
74
75
76
77
                val libs: List[Option[Int]] = (libId, sampleLevel) match {
                case (_, true) => List(None)
                case (Some(_), _) => List(libId)
                case _ => Await.result(summary.getLibraries(sampleId = Some(sample.id), runId = Some(runId)), Duration.Inf).map(x => Some(x.id)).toList
Peter van 't Hof's avatar
Peter van 't Hof committed
78
79
                }
            }#
80
            <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
81
            #for (libId <- libs)
82
                #{ val libName = libId.map(l => Await.result(summary.getLibraryName(l), Duration.Inf)) }#
Peter van 't Hof's avatar
Peter van 't Hof committed
83
                #if (libs.head != libId) <tr> #end
84
                    #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
85
                    #{
Peter van 't Hof's avatar
Peter van 't Hof committed
86
87
88
89
90
91
                        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
92
                        val results = summary.getStatKeys(runId, "bammetrics".right, Some("bamstats".right), sample = Some(sample.id.left), library = libId.map(_.left), keyValues = statsPaths)
Peter van 't Hof's avatar
Peter van 't Hof committed
93
94
95
96
                        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
97
98
99
                    }#
                    <td>${total}</td>
                    <td>${mapped}</td>
100
101
                    <td>${secondary}</td>
                    <td>${(mapped - secondary).toDouble / (total - secondary) * 100}%</td>
Peter van 't Hof's avatar
Peter van 't Hof committed
102
                    <td>${duplicates}</td>
103
                    <td>${duplicates.toDouble / (total - secondary) * 100}%</td>
Peter van 't Hof's avatar
Peter van 't Hof committed
104
                </tr>
105
            #end
Peter van 't Hof's avatar
Peter van 't Hof committed
106
107
108
        #end
    </tbody>
</table>
109

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