@@ -133,7 +133,7 @@ def assign_clades(clade_designations, all_muts, tree, ref=None):
133
133
node .sequences [gene ][pos ] = d
134
134
135
135
136
- # second pass to assign 'clade_annotation' to basal nodes within each clade
136
+ # store names of basal nodes of each clade in `basal_clade_nodes` and `clade_membership` dicts.
137
137
# if multiple nodes match, assign annotation to largest
138
138
# otherwise occasional unwanted cousin nodes get assigned the annotation
139
139
for clade_name , clade_alleles in clade_designations .items ():
@@ -147,7 +147,7 @@ def assign_clades(clade_designations, all_muts, tree, ref=None):
147
147
basal_clade_nodes [target_node .name ] = clade_name
148
148
clade_membership [target_node .name ] = clade_name # basal nodes are members of the clade
149
149
150
- # third pass to propagate 'clade_membership'
150
+ # propagate 'clade_membership' to children nodes
151
151
# don't propagate if encountering 'clade_annotation'
152
152
for node in tree .find_clades (order = 'preorder' ):
153
153
for child in node :
@@ -157,29 +157,6 @@ def assign_clades(clade_designations, all_muts, tree, ref=None):
157
157
return (basal_clade_nodes , clade_membership )
158
158
159
159
160
- def create_node_data_structure (basal_clade_nodes , clade_membership , args ):
161
- node_data = {}
162
-
163
- if (not args .label_name and not args .trait_name ):
164
- print ("WARNING: running `augur clades` without specifying --label-name and/or" )
165
- print (" --trait-name is deprecated. To preserve backwards compatibility" )
166
- print (" we will use 'clade' and 'clade_membership', respectively." )
167
- print (" (Note that 'clade' is now exported as a 'branch_label')" )
168
-
169
- label_name = "clade"
170
- trait_name = "clade_membership"
171
- else :
172
- label_name = args .label_name
173
- trait_name = args .trait_name
174
-
175
- if trait_name :
176
- node_data ['nodes' ] = {node : {trait_name : clade } for node ,clade in clade_membership .items ()}
177
- if label_name :
178
- node_data ['branch_labels' ] = {node : {label_name : clade } for node ,clade in basal_clade_nodes .items ()}
179
-
180
- return node_data
181
-
182
-
183
160
def get_reference_sequence_from_root_node (all_muts , root_name ):
184
161
# attach sequences to root
185
162
ref = {}
@@ -202,8 +179,7 @@ def register_arguments(parser):
202
179
parser .add_argument ('--mutations' , nargs = '+' , help = 'JSON(s) containing ancestral and tip nucleotide and/or amino-acid mutations ' )
203
180
parser .add_argument ('--reference' , nargs = '+' , help = 'fasta files containing reference and tip nucleotide and/or amino-acid sequences ' )
204
181
parser .add_argument ('--clades' , type = str , help = 'TSV file containing clade definitions by amino-acid' )
205
- parser .add_argument ('--trait-name' , type = str , help = 'name to use to store clade membership (set for every node belonging to the clade)' )
206
- parser .add_argument ('--label-name' , type = str , help = 'name to use for branch labels (set on basal branches for each clade)' )
182
+ parser .add_argument ('--attribute-name' , type = str , default = "clade" , help = "name to use for clade membership & branch labels" , required = False )
207
183
parser .add_argument ('--output-node-data' , type = str , help = 'name of JSON file to save clade assignments to' )
208
184
209
185
@@ -230,8 +206,12 @@ def run(args):
230
206
231
207
(basal_clade_nodes , clade_membership ) = assign_clades (clade_designations , all_muts , tree , ref )
232
208
233
- node_data = create_node_data_structure (basal_clade_nodes , clade_membership , args )
209
+ # create node_data for export as a JSON
210
+ node_data = {
211
+ 'nodes' : {node : {args .attribute_name : clade } for node ,clade in clade_membership .items ()},
212
+ 'branch_labels' : {node : {args .attribute_name : clade } for node ,clade in basal_clade_nodes .items ()}
213
+ }
234
214
235
215
out_name = get_json_name (args )
236
216
write_json (node_data , out_name )
237
- print ("clades written to" , out_name , file = sys .stdout )
217
+ print (f "clades written to { out_name } using attribute name { args . attribute_name } " , file = sys .stdout )
0 commit comments