Bioinformatics Asked by blawney_dfci on June 5, 2021
I’m having trouble getting WDL’s read_json
to work as expected when trying to create a Map[String, Map[String, String]]
data structure. If I explicitly declare the data structure it works, as shown below (the gm
variable):
workflow TestWorkflow {
String genome_choice
String output_name = "xyz.txt"
Map[String, Map[String,String]] gm = {
"A": {"gtf":"A.gtf", "idx":"A.idx"},
"B": {"gtf":"B.gtf", "idx":"B.idx"}
}
call something {
input:
genome_file_map = gm[genome_choice],
outname = output_name
}
output {
File fout = something.fout
}
}
task something {
String outname
Map[String, String] genome_file_map
String idx = genome_file_map["idx"]
String gtf = genome_file_map["gtf"]
command {
echo ${idx} >> ${outname}
echo ${gtf} >> ${outname}
}
output {
File fout = "${outname}"
}
}
However, instead of explicitly writing gm
, I would like to read that from a file. If I then create a JSON-format file:
{
"A": {"gtf":"A.gtf", "idx":"A.idx"},
"B": {"gtf":"B.gtf", "idx":"B.idx"}
}
and submit that as an input file
workflow TestWorkflow {
...
File resource_map_jsonfile
...
Map[String, Map[String,String]] gm = read_json(resource_map_jsonfile)
it fails to parse, giving me:
ERROR: gm is declared as a Map[String, Map[String, String]] but the expression evaluates to a Object:
Map[String, Map[String,String]] gm = read_json(resource_map_jsonfile)
If I change the type declaration to Object
, then all the bracket-style indexing fails. So that’s out.
Curiously, if I instead declare gm
as a Map[String,String]
it then fails giving:
java.lang.IllegalArgumentException: No coercion defined from wom value(s) '{"gtf": "B.gtf", "idx": "B.idx"}' of type 'Map[String, String]' to 'String'.
so clearly it is parsing the JSON file correctly, as it identifies that nested Map[String, String]
. I can probably find ways around this (using other read_*
functions), but that’s less than ideal.
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP