Skip to content
Snippets Groups Projects
Commit 7dabaeca authored by bow's avatar bow
Browse files

Update Picard metrics parsing to better handle nonexistent files

parent 24d23ba1
No related branches found
No related tags found
No related merge requests found
......@@ -63,18 +63,18 @@ class CollectAlignmentSummaryMetrics(val root: Configurable) extends Picard with
def summaryFiles: Map[String, File] = Map()
def summaryStats: Map[String, Any] = {
val (header, content) = Picard.getMetrics(output)
(for (category <- 0 until content.size) yield {
content(category)(0) -> (
for (
i <- 1 until header.size if i < content(category).size
) yield {
header(i).toLowerCase -> content(category)(i)
}).toMap
}
).toMap
def summaryStats: Map[String, Any] = Picard.getMetrics(output) match {
case None => Map()
case Some((header, content)) =>
(for (category <- 0 until content.size) yield {
content(category)(0) -> (
for (
i <- 1 until header.size if i < content(category).size
) yield {
header(i).toLowerCase -> content(category)(i)
}).toMap
}
).toMap
}
}
......
......@@ -74,11 +74,13 @@ class CollectInsertSizeMetrics(val root: Configurable) extends Picard with Summa
def summaryFiles: Map[String, File] = Map("output_histogram" -> outputHistogram)
def summaryStats: Map[String, Any] = {
val (header, content) = Picard.getMetrics(output)
(for (i <- 0 to header.size if i < content.head.size)
yield (header(i).toLowerCase -> content.head(i))).toMap
def summaryStats: Map[String, Any] = Picard.getMetrics(output) match {
case None => Map()
case Some((header, content)) =>
(for (i <- 0 to header.size if i < content.head.size)
yield header(i).toLowerCase -> content.head(i)).toMap
}
}
object CollectInsertSizeMetrics {
......
......@@ -77,13 +77,13 @@ class CollectRnaSeqMetrics(val root: Configurable) extends Picard with Summariza
//"output_chart" -> chartOutput
).collect { case (key, Some(value)) => key -> value }
def summaryStats: Map[String, Any] = {
val (header, content) = Picard.getMetrics(output)
header
.zip(content)
.map { case (h, c) => h.toLowerCase -> c.head }
.toMap
def summaryStats: Map[String, Any] = Picard.getMetrics(output) match {
case None => Map()
case Some((header, content)) =>
header
.zip(content)
.map { case (h, c) => h.toLowerCase -> c.head }
.toMap
}
override def commandLine = super.commandLine +
......
......@@ -95,18 +95,18 @@ class MarkDuplicates(val root: Configurable) extends Picard with Summarizable {
def summaryFiles: Map[String, File] = Map()
def summaryStats: Map[String, Any] = {
val (header, content) = Picard.getMetrics(outputMetrics)
(for (category <- 0 until content.size) yield {
content(category)(0) -> (
for (
i <- 1 until header.size if i < content(category).size
) yield {
header(i).toLowerCase -> content(category)(i)
}).toMap
}
).toMap
def summaryStats: Map[String, Any] = Picard.getMetrics(outputMetrics) match {
case None => Map()
case Some((header, content)) =>
(for (category <- 0 until content.size) yield {
content(category)(0) -> (
for (
i <- 1 until header.size if i < content(category).size
) yield {
header(i).toLowerCase -> content(category)(i)
}).toMap
}
).toMap
}
}
object MarkDuplicates {
......
......@@ -66,15 +66,20 @@ abstract class Picard extends BiopetJavaCommandLineFunction {
}
object Picard {
def getMetrics(file: File) = {
val lines = Source.fromFile(file).getLines().toArray
def getMetrics(file: File): Option[(Array[String], List[Array[String]])] =
val start = lines.indexWhere(_.startsWith("## METRICS CLASS")) + 1
val end = lines.indexOf("", start)
if (file.exists) {
val lines = Source.fromFile(file).getLines().toArray
val header = lines(start).split("\t")
val content = (for (i <- (start + 1) until end) yield lines(i).split("\t")).toList
val start = lines.indexWhere(_.startsWith("## METRICS CLASS")) + 1
val end = lines.indexOf("", start)
val header = lines(start).split("\t")
val content = (for (i <- (start + 1) until end) yield lines(i).split("\t")).toList
Option((header, content))
} else {
None
}
(header, content)
}
}
\ No newline at end of file
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