Skip to content
Snippets Groups Projects
Commit 73033e0d authored by Wai Yi Leung's avatar Wai Yi Leung
Browse files

Fix markup in code

Reorganize output json, including unclassified readcount
parent 36f70f66
No related branches found
No related tags found
No related merge requests found
......@@ -21,13 +21,13 @@ class KrakenReportToJson(val root: Configurable) extends ToolCommandFuntion with
def toolObject = nl.lumc.sasc.biopet.tools.KrakenReportToJson
@Input(doc = "Input Kraken Full report", shortName = "inputReport", required = true)
var inputReport: File = null
var inputReport: File = _
@Argument(required = false)
var skipNames: Boolean = false
@Output(doc = "Output JSON", shortName = "output", required = true)
var output: File = null
var output: File = _
override def defaultCoreMemory = 1.0
......@@ -37,9 +37,7 @@ class KrakenReportToJson(val root: Configurable) extends ToolCommandFuntion with
conditional(skipNames, "--skipnames")
def summaryStats: Map[String, Any] = {
val map = ConfigUtils.fileToConfigMap(output)
ConfigUtils.any2map(map.getOrElse("stats", Map()))
ConfigUtils.fileToConfigMap(output)
}
def summaryFiles: Map[String, File] = Map()
......
......@@ -24,7 +24,7 @@ import java.io.{ PrintWriter, File }
import nl.lumc.sasc.biopet.utils.ConfigUtils._
import nl.lumc.sasc.biopet.utils.ToolCommand
import scala.collection.mutable.ListBuffer
import scala.collection.{ immutable, mutable }
import scala.collection.mutable
import scala.io.Source
......@@ -36,8 +36,8 @@ case class KrakenHit(taxonomyID: Long,
cladeLevel: Int,
parentTaxonomyID: Long,
children: ListBuffer[KrakenHit]) {
def toJSON(): Map[String, Any] = {
val childJSON = children.toList.map(entry => entry.toJSON())
def toJSON(withChildren: Boolean = false): Map[String, Any] = {
val childJSON = if (withChildren) children.toList.map(entry => entry.toJSON(withChildren)) else List()
Map(
"name" -> taxonomyName,
"taxid" -> taxonomyID,
......@@ -55,6 +55,7 @@ object KrakenReportToJson extends ToolCommand {
var cladeIDs: mutable.ArrayBuffer[Long] = mutable.ArrayBuffer.fill(32)(0)
val spacePattern = "^( +)".r
private var lines: Map[Long, KrakenHit] = Map.empty
case class Args(krakenreport: File = null, outputJson: Option[File] = None, skipNames: Boolean = false) extends AbstractArgs
......@@ -132,7 +133,7 @@ object KrakenReportToJson extends ToolCommand {
* 6. indented scientific name
* */
val lines = reader.getLines()
lines = reader.getLines()
.map(line => parseLine(line, skipNames))
.filter(p => p.head._2.cladeSize > 0)
.foldLeft(Map.empty[Long, KrakenHit])((a, b) => {
......@@ -141,11 +142,22 @@ object KrakenReportToJson extends ToolCommand {
lines.keys.foreach(k => {
// append itself to the children attribute of the parent
lines(lines(k).parentTaxonomyID).children += lines(k)
if (lines(k).parentTaxonomyID > 0L) {
// avoid the root and unclassified appending to the unclassified node
lines(lines(k).parentTaxonomyID).children += lines(k)
}
})
mapToJson(lines(1).toJSON()).spaces2
val result = Map("unclasified" -> lines(0).toJSON(withChildren = false),
"classified" -> lines(1).toJSON(withChildren = true))
mapToJson(result).spaces2
}
def summary: String = {
val result = Map("unclasified" -> lines(0).toJSON(withChildren = false),
"classified" -> lines(1).toJSON(withChildren = true))
mapToJson(result).spaces2
}
def main(args: Array[String]): Unit = {
......@@ -153,11 +165,10 @@ object KrakenReportToJson extends ToolCommand {
val jsonString: String = reportToJson(commandArgs.krakenreport, skipNames = commandArgs.skipNames)
commandArgs.outputJson match {
case Some(file) => {
case Some(file) =>
val writer = new PrintWriter(file)
writer.println(jsonString)
writer.close()
}
case _ => println(jsonString)
}
......
#import(nl.lumc.sasc.biopet.utils.summary.Summary)
#import(nl.lumc.sasc.biopet.utils.ConfigUtils)
#import(java.io.File)
<%@ var summary: Summary %>
<%@ var sampleId: Option[String] = None %>
......@@ -32,27 +33,34 @@
#if (showPlot)
<div class="row">
<!--
Javascript required for showing the sunburst plot
//-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js" charset="utf-8"></script>
<!-- Gears specific javascript -->
<script src="${rootPath}ext/js/gears.js"></script>
<h3 id='currentlevel'>Root</h3>
<div>
<span id="selection_name"></span> -
<span id="selection_size"></span> -
<span id="selection_value"></span>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js" charset="utf-8"></script>
<script src="${rootPath}ext/js/gears.js"></script>
<h3 id='currentlevel'>Root</h3>
<div>
<span id="selection_name"></span> -
<span id="selection_size"></span> -
<span id="selection_value"></span>
</div>
<form>
<label><input type="radio" name="mode" value="size"> Size</label>
<label><input type="radio" name="mode" value="count" checked> Count</label>
</form>
<div id="sequence"></div>
<form>
<label><input type="radio" name="mode" value="size"> Size</label>
<label><input type="radio" name="mode" value="count" checked> Count</label>
</form>
<div id="sequence"></div>
<div id="datatable">
<script type="application/ecmascript">
<div id="datatable"></div>
#{
val rawreport = Map("kraken" -> summary.getValue("gears", "stats", "krakenreport"))
val bla = ConfigUtils.mapToJson(rawreport)
}#
var krakenresult = JSON.parse('<%= unescape(bla) %>');
</script>
</div>
</div>
#end
......@@ -28,7 +28,6 @@ import org.broadinstitute.gatk.queue.QScript
* Created by wyleung
*/
class Gears(val root: Configurable) extends QScript with SummaryQScript {
qscript =>
def this() = this(null)
@Input(shortName = "R1", required = false)
......@@ -72,7 +71,7 @@ class Gears(val root: Configurable) extends QScript with SummaryQScript {
val fastqFiles: List[File] = bamFile.map { bamfile =>
// sambamba view -f bam -F "unmapped or mate_is_unmapped" <alnFile> > <extracted.bam>
val samFilterUnmapped = new SambambaView(qscript)
val samFilterUnmapped = new SambambaView(this)
samFilterUnmapped.input = bamfile
samFilterUnmapped.filter = Some("(unmapped or mate_is_unmapped) and not (secondary_alignment) and [XH] == null")
samFilterUnmapped.output = new File(outputDir, s"$outputName.unmapped.bam")
......@@ -80,7 +79,7 @@ class Gears(val root: Configurable) extends QScript with SummaryQScript {
add(samFilterUnmapped)
// start bam to fastq (only on unaligned reads) also extract the matesam
val samToFastq = new SamToFastq(qscript)
val samToFastq = new SamToFastq(this)
samToFastq.input = samFilterUnmapped.output
samToFastq.stringency = Some("LENIENT")
samToFastq.fastqR1 = new File(outputDir, s"$outputName.unmapped.R1.fq.gz")
......@@ -90,7 +89,7 @@ class Gears(val root: Configurable) extends QScript with SummaryQScript {
add(samToFastq)
// sync the fastq records
val fastqSync = new FastqSync(qscript)
val fastqSync = new FastqSync(this)
fastqSync.refFastq = samToFastq.fastqR1
fastqSync.inputFastq1 = samToFastq.fastqR1
fastqSync.inputFastq2 = samToFastq.fastqR2
......@@ -109,7 +108,7 @@ class Gears(val root: Configurable) extends QScript with SummaryQScript {
}.getOrElse(List(fastqFileR1, fastqFileR2).flatten)
// start kraken
val krakenAnalysis = new Kraken(qscript)
val krakenAnalysis = new Kraken(this)
krakenAnalysis.input = fastqFiles
krakenAnalysis.output = new File(outputDir, s"$outputName.krkn.raw")
......@@ -125,7 +124,7 @@ class Gears(val root: Configurable) extends QScript with SummaryQScript {
// create kraken summary file
val krakenReport = new KrakenReport(qscript)
val krakenReport = new KrakenReport(this)
krakenReport.input = krakenAnalysis.output
krakenReport.show_zeros = true
krakenReport.output = new File(outputDir, s"$outputName.krkn.full")
......@@ -134,11 +133,12 @@ class Gears(val root: Configurable) extends QScript with SummaryQScript {
GearsOutputFiles += ("kraken_report_input" -> krakenReport.input)
GearsOutputFiles += ("kraken_report_output" -> krakenReport.output)
val krakenReportJSON = new KrakenReportToJson(qscript)
val krakenReportJSON = new KrakenReportToJson(this)
krakenReportJSON.inputReport = krakenReport.output
krakenReportJSON.output = new File(outputDir, s"$outputName.krkn.json")
krakenReportJSON.skipNames = config("skipNames", default = false)
add(krakenReportJSON)
addSummarizable(krakenReportJSON, "krakenreport")
GearsOutputFiles += ("kraken_report_json_input" -> krakenReportJSON.inputReport)
GearsOutputFiles += ("kraken_report_json_output" -> krakenReportJSON.output)
......
......@@ -39,16 +39,13 @@ object GearsReport extends MultisampleReportBuilder {
}
def samplePage(sampleId: String, args: Map[String, Any]) = {
ReportPage(List(
), List(
ReportPage(List(), List(
"Sunburst analysis" -> ReportSection("/nl/lumc/sasc/biopet/pipelines/gears/gearsSunburst.ssp")
), args)
}
def libraryPage(sampleId: String, libId: String, args: Map[String, Any]) = {
ReportPage(List(
), List(
), args)
ReportPage(List(), List(), args)
}
def reportName = "Gears :: Metagenomics Report"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment