-
Notifications
You must be signed in to change notification settings - Fork 136
refine: warn if doing timetree and there's apparent mismatch between metadata and sequence ids #1902
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
corneliusroemer
wants to merge
7
commits into
master
Choose a base branch
from
refine-warning
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+62
−0
Open
refine: warn if doing timetree and there's apparent mismatch between metadata and sequence ids #1902
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
61c8f5d
refine: Warn when sequence IDs don't match metadata IDs
corneliusroemer 9c95ef9
Update CHANGES.md for refine ID mismatch warning
corneliusroemer 849dac6
Update augur/refine.py
corneliusroemer 0b08c3d
Apply suggestions from code review
corneliusroemer 8e56117
Simplify ID mismatch warning and add functional test
corneliusroemer 3353be6
Reduce test file by generating metadata inline
corneliusroemer 5adc31b
Fix CRAM test indentation for ID mismatch warning
corneliusroemer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -309,6 +309,16 @@ def run(args): | |
| except InvalidYearBounds as error: | ||
| raise AugurError(f"Invalid value for --year-bounds: {error}") | ||
|
|
||
| terminal_names = {n.name for n in T.get_terminals()} | ||
| matched_ids = terminal_names & set(dates.keys()) | ||
|
|
||
| if len(matched_ids) < len(terminal_names) * 0.5: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: warn on any missing metadata. That would match the expectation for typical Augur workflows. |
||
| print(f"\nWARNING: For {len(terminal_names)} sequence IDs, only {len(matched_ids)} corresponding metadata rows could be matched.", file=sys.stderr) | ||
| print(f" Metadata has {len(dates)} entries in total.", file=sys.stderr) | ||
| print(f" Metadata is using '{metadata_object.id_column}' as the ID column.", file=sys.stderr) | ||
| print(f" You may need to explicitly set the metadata ID column using --metadata-id-columns.", file=sys.stderr) | ||
| print(f" By default, the columns {DEFAULT_ID_COLUMNS} are tried in order.\n", file=sys.stderr) | ||
|
|
||
| # save input state string for later export | ||
| for n in T.get_terminals(): | ||
| if n.name in metadata.index and METADATA_DATE_COLUMN in metadata.columns: | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| Setup | ||
|
|
||
| $ source "$TESTDIR"/_setup.sh | ||
|
|
||
| Create metadata with mismatched IDs by adding a 'name' column with correct IDs | ||
| and replacing the 'strain' column with wrong IDs. | ||
|
|
||
| $ awk -F'\t' 'BEGIN {OFS="\t"} NR==1 {print $0,"name"} NR>1 {print "wrong_id_"NR,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$1}' \ | ||
| > "$TESTDIR/../data/metadata.tsv" > metadata_mismatch.tsv | ||
|
|
||
| Try building a time tree with mismatched sequence and metadata IDs. | ||
| This should produce a warning because the default 'strain' column has wrong IDs. | ||
| The command will fail due to insufficient matching IDs, so redirect stdout. | ||
|
|
||
| $ ${AUGUR} refine \ | ||
| > --tree "$TESTDIR/../data/tree_raw.nwk" \ | ||
| > --alignment "$TESTDIR/../data/aligned.fasta" \ | ||
| > --metadata metadata_mismatch.tsv \ | ||
| > --output-tree tree_mismatch.nwk \ | ||
| > --output-node-data branch_lengths_mismatch.json \ | ||
| > --timetree \ | ||
| > --seed 314159 > /dev/null | ||
|
|
||
| WARNING: For 11 sequence IDs, only 0 corresponding metadata rows could be matched. | ||
| Metadata has 12 entries in total. | ||
| Metadata is using 'strain' as the ID column. | ||
| You may need to explicitly set the metadata ID column using --metadata-id-columns. | ||
| By default, the columns ('strain', 'name') are tried in order. | ||
|
|
||
| ERROR: ERROR: ALMOST NO VALID DATE CONSTRAINTS | ||
|
|
||
|
|
||
| ERROR from TreeTime: This error is most likely due to a problem with your input data. | ||
| Please check your input data and try again. If you continue to have problems, please open a new issue including | ||
| the original command and the error above: <https://github.com/nextstrain/augur/issues/new/choose> | ||
|
|
||
| [2] | ||
|
|
||
| Now try with the correct ID column specified. | ||
| This should work without the ID mismatch warning. | ||
|
|
||
| $ ${AUGUR} refine \ | ||
| > --tree "$TESTDIR/../data/tree_raw.nwk" \ | ||
| > --alignment "$TESTDIR/../data/aligned.fasta" \ | ||
| > --metadata metadata_mismatch.tsv \ | ||
| > --metadata-id-columns name \ | ||
| > --output-tree tree_correct.nwk \ | ||
| > --output-node-data branch_lengths_correct.json \ | ||
| > --timetree \ | ||
| > --seed 314159 > /dev/null |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest we make more explicit, something like "if more than half of the tip names are missing corresponding metadata"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Otherwise PR looks good!)