File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -25,6 +25,24 @@ This part of the workflow usually includes the following steps:
2525See Augur's usage docs for these commands for more details.
2626"""
2727
28+ rule set_hidden_attribute :
29+ input :
30+ clades = "results/{build}/clades.json" ,
31+ clade_defs = lambda w : config ["build_params" ][w .build ]["files" ].get ("clades" ),
32+ output :
33+ hidden = "results/{build}/hidden.json" ,
34+ benchmark :
35+ "benchmarks/{build}/set_hidden_attribute.txt"
36+ log :
37+ "logs/{build}/set_hidden_attribute.txt"
38+ shell :
39+ r"""
40+ exec &> >(tee {log:q})
41+
42+ ./scripts/set-hidden-attribute.py {input.clades:q} {output.hidden:q}
43+ """
44+
45+
2846def export_node_data_inputs (w ):
2947 files = [
3048 f"results/{ w .build } /branch_lengths.json" ,
@@ -35,6 +53,7 @@ def export_node_data_inputs(w):
3553 if config ["build_params" ][w .build ]["files" ].get ("clades" ):
3654 files += [
3755 f"results/{ w .build } /clades.json" ,
56+ f"results/{ w .build } /hidden.json" ,
3857 ]
3958 return files
4059
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
2+
3+ import argparse
4+ import json
5+
6+
7+ def main ():
8+ parser = argparse .ArgumentParser (
9+ description = "Mark certain nodes with a hidden flag."
10+ )
11+ parser .add_argument ("node_attrs_in" , help = "Path to a node attributes file." )
12+ parser .add_argument ("node_attrs_out" , help = "Path for the output node attributes file." )
13+
14+ args = parser .parse_args ()
15+ process_json (args .node_attrs_in , args .node_attrs_out )
16+
17+
18+ def process_json (node_attrs_in , node_attrs_out ):
19+ with open (node_attrs_in , "r" ) as f :
20+ data = json .load (f )
21+
22+ nodes_in = data .get ("nodes" , {})
23+ nodes_out = {}
24+
25+ for node_id , node_info in nodes_in .items ():
26+ # Hide if the node has no clade info.
27+ if node_info .get ("clade_membership" ) == "unassigned" :
28+ nodes_out [node_id ] = {"hidden" : "timetree" }
29+ continue
30+
31+ with open (node_attrs_out , "w" ) as f :
32+ json .dump ({"nodes" : nodes_out }, f , indent = 2 )
33+
34+
35+ if __name__ == "__main__" :
36+ main ()
You can’t perform that action at this time.
0 commit comments