Key error in augur export -- `if node["strain"] in node_attrs: KeyError: 'strain'`

This is copied from a user request - please post questions such as these in the discussion forum to make the question and answer visible and useful to others

Recently, we have tried to generate a json with the augur export v2 command to upload it to the profile. However, we get an error related to the branch_lengths.json file. I have checked the file and compared its structure with the one we obtained for the previous analysis, currently published in Nextstrain, and I can’t find the error.

The command and error message is:

No errors raised in previous steps.

augur export v2 \
 --tree results/tree.nwk \
 --metadata data/nextstrain_reinf.tsv \
 --node-data results/branch_lengths.json \
 --output auspice/sars-cov-2.json
Traceback (most recent call last):
File "/home/vhir/anaconda3/envs/nextstrain/bin/augur", line 10, in <module>
sys.exit(main())
File "/home/vhir/anaconda3/envs/nextstrain/lib/python3.9/site-packages/augur/__main__.py", line 10, in main
return augur.run( argv[1:] )
File "/home/vhir/anaconda3/envs/nextstrain/lib/python3.9/site-packages/augur/__init__.py", line 75, in run
return args.__command__.run(args)
File "/home/vhir/anaconda3/envs/nextstrain/lib/python3.9/site-packages/augur/export.py", line 22, in run
return run_v2(args)
File "/home/vhir/anaconda3/envs/nextstrain/lib/python3.9/site-packages/augur/export_v2.py", line 974, in run_v2
node_data, node_attrs, node_data_names, metadata_names = parse_node_data_and_metadata(T, node_data_file, metadata_file)
File "/home/vhir/anaconda3/envs/nextstrain/lib/python3.9/site-packages/augur/export_v2.py", line 919, in parse_node_data_and_metadata
if node["strain"] in node_attrs: # i.e. this node name is in the tree
KeyError: 'strain'`

We are sending the files, in case you could check them, as mentioned in an issue published in Nextstrain (Error in Job 3: Exporting data files for for auspice).

I think the problem is that your metadata file does not have a column called “strain”. Instead the strain names are called “name”.

If you rename the metadata column from “name” to “strain” things should work.

There is currently some inconsistency within augur whether name is an acceptable alternative to strain in the metadata file. Some commands accept name but export currently doesn’t.

We’re actively working on fixing this in future augur versions, see Github issue/PR:

From the user

It solved the problem, thank you so much! I did not consider it as I read in a documentation file that this column could be named “name” or “strain” indistinctly.