Skip to content

Commit

Permalink
Use try/except to catch missing sequences
Browse files Browse the repository at this point in the history
As noted in the TODO.
  • Loading branch information
victorlin committed Nov 7, 2023
1 parent 2e7d620 commit b045099
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions augur/io/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,11 @@ def read_metadata_with_sequences(metadata, metadata_delimiters, fasta, seq_id_co
else:
processed_metadata_ids.add(seq_id)

# Skip records that do not have a matching sequence
# TODO: change this to try/except to fetch sequences and catch
# KeyError for non-existing sequences when https://github.com/lmdu/pyfastx/issues/50 is resolved
if seq_id not in sequence_ids:
try:
sequence_record = sequences[id_to_index[seq_id]]
except KeyError:
# Skip records that do not have a matching sequence

# Immediately raise an error if requested to error on the first unmatched record
if unmatched_reporting is DataErrorMethod.ERROR_FIRST:
raise AugurError(f"Encountered metadata record {seq_id!r} without a matching sequence.")
Expand Down

0 comments on commit b045099

Please sign in to comment.