Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
biopet.biopet
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mirrors
biopet.biopet
Commits
55b5629d
Commit
55b5629d
authored
9 years ago
by
Peter van 't Hof
Browse files
Options
Downloads
Patches
Plain Diff
Added function to convert kraken to krona output
parent
0b1fec3f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
public/gears/src/main/scala/nl/lumc/sasc/biopet/pipelines/gears/GearsKraken.scala
+58
-0
58 additions, 0 deletions
...ala/nl/lumc/sasc/biopet/pipelines/gears/GearsKraken.scala
with
58 additions
and
0 deletions
public/gears/src/main/scala/nl/lumc/sasc/biopet/pipelines/gears/GearsKraken.scala
+
58
−
0
View file @
55b5629d
package
nl.lumc.sasc.biopet.pipelines.gears
import
java.io.
{
File
,
PrintWriter
}
import
nl.lumc.sasc.biopet.core.SampleLibraryTag
import
nl.lumc.sasc.biopet.core.summary.SummaryQScript
import
nl.lumc.sasc.biopet.extensions.kraken.
{
KrakenReport
,
Kraken
}
import
nl.lumc.sasc.biopet.extensions.tools.KrakenReportToJson
import
nl.lumc.sasc.biopet.utils.ConfigUtils
import
nl.lumc.sasc.biopet.utils.config.Configurable
import
org.broadinstitute.gatk.queue.QScript
import
scala.collection.mutable
import
scala.xml.Node
/**
* Created by pjvanthof on 04/12/15.
*/
...
...
@@ -77,3 +83,55 @@ class GearsKraken(val root: Configurable) extends QScript with SummaryQScript wi
case
_
=>
Map
()
})
}
object
GearsKraken
{
def
convertKrakenJsonToKronaXml
(
files
:
Map
[
String
,
File
],
outputFile
:
File
)
:
Unit
=
{
val
oriMap
=
files
.
map
{
case
(
k
,
v
)
=>
k
->
ConfigUtils
.
fileToConfigMap
(
v
)
}
val
taxs
:
mutable.Map
[
String
,
Any
]
=
mutable
.
Map
()
def
addTax
(
map
:
Map
[
String
,
Any
],
path
:
List
[
String
]
=
Nil
)
:
Unit
=
{
val
name
=
map
(
"name"
).
toString
val
x
=
path
.
foldLeft
(
taxs
)((
a
,
b
)
=>
if
(
a
.
contains
(
b
))
a
(
b
).
asInstanceOf
[
mutable.Map
[
String
,
Any
]]
else
{
a
+=
b
->
mutable
.
Map
[
String
,
Any
]()
a
(
b
).
asInstanceOf
[
mutable.Map
[
String
,
Any
]]
})
if
(!
x
.
contains
(
name
))
x
+=
name
->
mutable
.
Map
[
String
,
Any
]()
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
]])
}
def
getValue
(
sample
:
String
,
path
:
List
[
String
],
key
:
String
)
=
{
path
.
foldLeft
(
oriMap
(
sample
)(
"classified"
).
asInstanceOf
[
Map
[
String
,
Any
]])
{
(
b
,
a
)
=>
b
.
getOrElse
(
"children"
,
List
[
Map
[
String
,
Any
]]())
.
asInstanceOf
[
List
[
Map
[
String
,
Any
]]]
.
find
(
_
.
getOrElse
(
"name"
,
""
)
==
a
).
getOrElse
(
Map
[
String
,
Any
]())
}.
get
(
key
)
}
def
createNodes
(
map
:
mutable.Map
[
String
,
Any
],
path
:
List
[
String
]
=
Nil
)
:
Seq
[
Node
]
=
{
(
map
.
map
{
case
(
k
,
v
)
=>
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
size
=
<
size
>{
sizes
}</
size
>
node
.
copy
(
child
=
size
++
createNodes
(
v
.
asInstanceOf
[
mutable.Map
[
String
,
Any
]],
path
:::
k
::
Nil
))
}).
toSeq
}
val
xml
=
<
krona
>
<
attributes
magnitude
=
"size"
>
<
attribute
display
=
"size"
>
size
</
attribute
>
</
attributes
>
<
datasets
>
{
oriMap
.
keySet
.
map
{
sample
=>
<
dataset
>{
sample
}</
dataset
>
}
}
</
datasets
>
</
krona
>
val
writer
=
new
PrintWriter
(
outputFile
)
writer
.
println
(
xml
.
copy
(
child
=
xml
.
child
++
createNodes
(
taxs
)).
toString
())
writer
.
close
()
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment