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

**URL:** <https://nextstrain.discourse.group/t/key-error-in-augur-export-if-node-strain-in-node-attrs-keyerror-strain/1076>\
**Category:** Help and Getting Started\
**Created:** [April 27, 2022, 11:50am UTC](https://nextstrain.discourse.group/t/key-error-in-augur-export-if-node-strain-in-node-attrs-keyerror-strain/1076 "2022-04-27T11:50:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![corneliusroemer](https://yyz1.discourse-cdn.com/flex031/user_avatar/nextstrain.discourse.group/corneliusroemer/32/175_2.png) [@corneliusroemer](https://nextstrain.discourse.group/u/corneliusroemer)\
**Post date:** [April 27, 2022, 11:50am UTC](https://nextstrain.discourse.group/t/key-error-in-augur-export-if-node-strain-in-node-attrs-keyerror-strain/1076/1 "2022-04-27T11:50:09Z")

</div>

_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.

```bash
augur export v2 \
 --tree results/tree.nwk \
 --metadata data/nextstrain_reinf.tsv \
 --node-data results/branch_lengths.json \
 --output auspice/sars-cov-2.json

```

```python
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](https://nextstrain.discourse.group/t/error-in-job-3-exporting-data-files-for-for-auspice/493)).

---

<div class="post-metadata">

**Author:** ![corneliusroemer](https://yyz1.discourse-cdn.com/flex031/user_avatar/nextstrain.discourse.group/corneliusroemer/32/175_2.png) [@corneliusroemer](https://nextstrain.discourse.group/u/corneliusroemer)\
**Post date:** [April 27, 2022, 11:53am UTC](https://nextstrain.discourse.group/t/key-error-in-augur-export-if-node-strain-in-node-attrs-keyerror-strain/1076/2 "2022-04-27T11:53:27Z")

</div>

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:

> <https://github.com/nextstrain/augur/issues/905#issuecomment-1110221199>
>
> A lot of users seem to get the following type of error:
> 
> \`\`\`
> Job 3: Exporting… data files for for auspice
> 
> 
> augur export v2 --tree results/global/tree.nwk --metadata data/metadata.tsv
> --node-data results/global/branch\_lengths.json results/global/nt\_muts.json results/global/aa\_muts.json results/global/subclades.json results/global/clades.json results/global/recency.json results/global/traits.json --auspice-config my\_profiles/covid/my\_auspice\_config.json --include-root-sequence --colors results/global/colors.tsv --lat-longs defaults/lat\_longs.tsv --title 'Genomic epidemiology of novel coronavirus - Global subsampling' --description my\_profiles/covid/my\_description.md --output results/global/ncov\_with\_accessions.json 2\>&1 | tee logs/export\_global.txt
> 
> Validating schema of 'results/global/aa\_muts.json'...
> Traceback (most recent call last):
> File "/home/charbel/miniconda3/envs/nextstrain/bin/augur", line 10, in \<module\>
> sys.exit(main())
> File "/home/charbel/miniconda3/envs/nextstrain/lib/python3.8/site-packages/augur/\_\_main\_\_.py", line 10, in main
> return augur.run( argv\[1:\] )
> File "/home/charbel/miniconda3/envs/nextstrain/lib/python3.8/site-packages/augur/\_\_init\_\_.py", line 75, in run
> return args.\_\_command\_\_.run(args)
> File "/home/charbel/miniconda3/envs/nextstrain/lib/python3.8/site-packages/augur/export.py", line 22, in run
> return run\_v2(args)
> File "/home/charbel/miniconda3/envs/nextstrain/lib/python3.8/site-packages/augur/export\_v2.py", line 903, in run\_v2
> node\_data, node\_attrs, node\_data\_names, metadata\_names = parse\_node\_data\_and\_metadata(T, args.node\_data, args.metadata)
> File "/home/charbel/miniconda3/envs/nextstrain/lib/python3.8/site-packages/augur/export\_v2.py", line 863, in parse\_node\_data\_and\_metadata
> if node\["strain"\] in node\_attrs: # i.e. this node name is in the tree
> KeyError: 'strain'
> \`\`\`
> https://nextstrain.discourse.group/t/error-in-job-3-exporting-data-files-for-for-auspice/493/4
> 
> It's a common discussion topic on our forum and also in emails we get to hello@nextstrain.org
> 
> I think it would help users a lot if we raised a more informative error so that users know directly how to fix it.
> 
> Also, we don't seem to have documented the requirement that the metadata needs to contain a column called \`strain\` with \_strainnames\_.
> 
> Both should be addressed.

> <https://github.com/nextstrain/augur/pull/906>
>
> Metadata reader class accepts either "name" or "strain" as strain name columns.
> …
> However, export thus far doesn't accept "name".
> This commit detects if "name" is used and uses it, thus getting rid of common error type.
> 
> \### Related issue(s)
> Fixes #905 
> 
> \### Testing
> I tested that metadata files with \`name\` instead of \`strain\` as the column name for strain names are now accepted - in line with what the metadata file class accepts. The reason we didn't emit useful error messages was that the metadata file class was happy with \`name\`. Yet export expected \`strain\` and wasn't happy with \`name\`.
> 
> Henceforth, this type of error shouldn't happen anymore: https://nextstrain.discourse.group/t/error-in-job-3-exporting-data-files-for-for-auspice/493
> 
> If you don't have either \`strain\` or \`name\` in metdata, you'll get a helpful error and all is good.
> 
> \`\`\`
> Traceback (most recent call last):
> File "/usr/local/Caskroom/mambaforge/base/envs/augur-dev/bin/augur", line 33, in \<module\>
> sys.exit(load\_entry\_point('nextstrain-augur', 'console\_scripts', 'augur')())
> File "/Users/cr/code/augur/augur/\_\_main\_\_.py", line 10, in main
> return augur.run( argv\[1:\] )
> File "/Users/cr/code/augur/augur/\_\_init\_\_.py", line 75, in run
> return args.\_\_command\_\_.run(args)
> File "/Users/cr/code/augur/augur/export.py", line 22, in run
> return run\_v2(args)
> File "/Users/cr/code/augur/augur/export\_v2.py", line 1002, in run\_v2
> metadata\_file, \_ = read\_metadata(args.metadata)
> File "/Users/cr/code/augur/augur/utils.py", line 82, in read\_metadata
> return MetadataFile(fname, query, as\_data\_frame).read()
> File "/Users/cr/code/augur/augur/util\_support/metadata\_file.py", line 19, in \_\_init\_\_
> self.key\_type = self.find\_key\_type()
> File "/Users/cr/code/augur/augur/util\_support/metadata\_file.py", line 73, in find\_key\_type
> raise ValueError(
> ValueError: Metadata file data/nextstrain\_reinf.tsv does not contain \`name\` or \`strain\`
> \`\`\`

---

<div class="post-metadata">

**Author:** ![corneliusroemer](https://yyz1.discourse-cdn.com/flex031/user_avatar/nextstrain.discourse.group/corneliusroemer/32/175_2.png) [@corneliusroemer](https://nextstrain.discourse.group/u/corneliusroemer)\
**Post date:** [April 27, 2022, 11:54am UTC](https://nextstrain.discourse.group/t/key-error-in-augur-export-if-node-strain-in-node-attrs-keyerror-strain/1076/3 "2022-04-27T11:54:54Z")

</div>

_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.
