Skip to content
Snippets Groups Projects
Commit 2b882e6f authored by Peter van 't Hof's avatar Peter van 't Hof
Browse files

Added sorting for samples

parent 55b5629d
No related branches found
No related tags found
No related merge requests found
...@@ -85,10 +85,18 @@ class GearsKraken(val root: Configurable) extends QScript with SummaryQScript wi ...@@ -85,10 +85,18 @@ class GearsKraken(val root: Configurable) extends QScript with SummaryQScript wi
} }
object GearsKraken { object GearsKraken {
def convertKrakenJsonToKronaXml(files: Map[String, File], outputFile: File): Unit = { def convertKrakenJsonToKronaXml(files: Map[String, File], outputFile: File): Unit = {
val summaries = files.map { case (k, v) => k -> ConfigUtils.fileToConfigMap(v) }
convertKrakenSummariesToKronaXml(summaries, outputFile)
}
def convertKrakenSummariesToKronaXml(summaries: Map[String, Map[String, Any]], outputFile: File): Unit = {
val samples = summaries.keys.toList.sorted
val oriMap = files.map { case (k, v) => k -> ConfigUtils.fileToConfigMap(v) }
val taxs: mutable.Map[String, Any] = mutable.Map() val taxs: mutable.Map[String, Any] = mutable.Map()
def addTax(map: Map[String, Any], path: List[String] = Nil): Unit = { def addTax(map: Map[String, Any], path: List[String] = Nil): Unit = {
val name = map("name").toString val name = map("name").toString
val x = path.foldLeft(taxs)((a, b) => if (a.contains(b)) a(b).asInstanceOf[mutable.Map[String, Any]] else { val x = path.foldLeft(taxs)((a, b) => if (a.contains(b)) a(b).asInstanceOf[mutable.Map[String, Any]] else {
...@@ -100,12 +108,11 @@ object GearsKraken { ...@@ -100,12 +108,11 @@ object GearsKraken {
map("children").asInstanceOf[List[Any]].foreach(x => addTax(x.asInstanceOf[Map[String, Any]], path ::: name :: Nil)) map("children").asInstanceOf[List[Any]].foreach(x => addTax(x.asInstanceOf[Map[String, Any]], path ::: name :: Nil))
} }
oriMap.foreach { x =>
addTax(x._2("classified").asInstanceOf[Map[String, Any]]) summaries.foreach { x => addTax(x._2("classified").asInstanceOf[Map[String, Any]]) }
}
def getValue(sample: String, path: List[String], key: String) = { def getValue(sample: String, path: List[String], key: String) = {
path.foldLeft(oriMap(sample)("classified").asInstanceOf[Map[String, Any]]) { (b, a) => path.foldLeft(summaries(sample)("classified").asInstanceOf[Map[String, Any]]) { (b, a) =>
b.getOrElse("children", List[Map[String, Any]]()) b.getOrElse("children", List[Map[String, Any]]())
.asInstanceOf[List[Map[String, Any]]] .asInstanceOf[List[Map[String, Any]]]
.find(_.getOrElse("name", "") == a).getOrElse(Map[String, Any]()) .find(_.getOrElse("name", "") == a).getOrElse(Map[String, Any]())
...@@ -113,20 +120,23 @@ object GearsKraken { ...@@ -113,20 +120,23 @@ object GearsKraken {
} }
def createNodes(map: mutable.Map[String, Any], path: List[String] = Nil): Seq[Node] = { def createNodes(map: mutable.Map[String, Any], path: List[String] = Nil): Seq[Node] = {
(map.map { map.map {
case (k, v) => case (k, v) =>
val node = <node name={ k }></node> val node = <node name={k}></node>
val sizes = oriMap.keySet.toList.map { sample => <val>{ getValue(sample, (path ::: k :: Nil).tail, "size").getOrElse(0) }</val> } val sizes = samples.map { sample => <val>
val size = <size>{ sizes }</size> {getValue(sample, (path ::: k :: Nil).tail, "size").getOrElse(0)}
</val>
}
val size = <size>{sizes}</size>
node.copy(child = size ++ createNodes(v.asInstanceOf[mutable.Map[String, Any]], path ::: k :: Nil)) node.copy(child = size ++ createNodes(v.asInstanceOf[mutable.Map[String, Any]], path ::: k :: Nil))
}).toSeq }.toSeq
} }
val xml = <krona> val xml = <krona>
<attributes magnitude="size"> <attributes magnitude="size">
<attribute display="size">size</attribute> <attribute display="size">size</attribute>
</attributes> </attributes>
<datasets> <datasets>
{ oriMap.keySet.map { sample => <dataset>{ sample }</dataset> } } { samples.map { sample => <dataset>{ sample }</dataset> } }
</datasets> </datasets>
</krona> </krona>
......
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