Skip to content

Commit

Permalink
Allow metadata index to be exported
Browse files Browse the repository at this point in the history
  • Loading branch information
victorlin committed Jul 24, 2023
1 parent bb4c4ca commit 72f645c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
10 changes: 8 additions & 2 deletions augur/export_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1074,10 +1074,16 @@ def run(args):

if args.metadata is not None:
try:
metadata_file = read_metadata(
metadata_df = read_metadata(
args.metadata,
delimiters=args.metadata_delimiters,
id_columns=args.metadata_id_columns).to_dict(orient="index")
id_columns=args.metadata_id_columns)

# Add the index as a column.
metadata_df[metadata_df.index.name] = metadata_df.index

metadata_file = metadata_df.to_dict(orient="index")

for strain in metadata_file.keys():
if "strain" not in metadata_file[strain]:
metadata_file[strain]["strain"] = strain
Expand Down
3 changes: 1 addition & 2 deletions tests/functional/export_v2/cram/metadata-with-accession.t
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ Run export with metadata that contains "accession".
{}

Run export with metadata that contains "accession", and use "accession" as the ID column.
Currently, this results in losing the accession from the node attributes.

$ ${AUGUR} export v2 \
> --tree "$TESTDIR/../data/tree.nwk" \
Expand All @@ -30,4 +29,4 @@ Currently, this results in losing the accession from the node attributes.

$ python3 "$TESTDIR/../../../../scripts/diff_jsons.py" "$TESTDIR/../data/dataset_with_accession.json" dataset.json \
> --exclude-paths "root['meta']['updated']" "root['meta']['maintainers']"
{'dictionary_item_removed': [root['tree']['children'][0]['node_attrs']['accession'], root['tree']['children'][1]['children'][0]['node_attrs']['accession'], root['tree']['children'][1]['children'][1]['node_attrs']['accession'], root['tree']['children'][2]['children'][0]['node_attrs']['accession'], root['tree']['children'][2]['children'][1]['node_attrs']['accession'], root['tree']['children'][2]['children'][2]['node_attrs']['accession']]}
{}

0 comments on commit 72f645c

Please sign in to comment.