Skip to content

Fix AttributeError when AMRFinderPlus subclass is not in CARD conversion table - #35

Open
sanjaynagi wants to merge 1 commit into
AMRverse:mainfrom
sanjaynagi:fix/issue-28-amrfp-subclass-attributeerror
Open

Fix AttributeError when AMRFinderPlus subclass is not in CARD conversion table#35
sanjaynagi wants to merge 1 commit into
AMRverse:mainfrom
sanjaynagi:fix/issue-28-amrfp-subclass-attributeerror

Conversation

@sanjaynagi

Copy link
Copy Markdown

Fixes #28.

Genotype._assign_drug_from_amrfp() chained .get('drug', '-') / .get('class', '-') directly onto card_amrfp_conversion.get(self.amrfp_subclass). The amrfp_to_card_drugs_classes.txt conversion table is maintained by hand and can lag behind whatever AMRFinderPlus/NCBI database is in use. When a subclass isn't in the table (e.g. FUSIDIC_ACID vs a table only carrying FUSIDIC ACID), the outer .get() returns None, and .get('drug', '-') on None raises AttributeError: 'NoneType' object has no attribute 'get', crashing the whole run.

Found via a real production failure: 19 pipeline runs hit exactly this for an unmapped FUSIDIC_ACID subclass on S. aureus samples.

Fix: fall back to {} when the lookup misses, so it flows into the existing if self.drug_class == '-': self.drug_class = 'unassigned markers' path instead of crashing, and emit a warnings.warn() so an unmapped subclass is at least visible rather than silent.

(Re-opened from #34 under a different account — same commit, no code changes.)

…ion table

Fixes AMRverse#28

_assign_drug_from_amrfp() called card_amrfp_conversion.get(self.amrfp_subclass)
and then immediately chained .get('drug', '-') / .get('class', '-') onto the
result. When the AMRFinderPlus subclass has no entry in the hand-maintained
amrfp_to_card_drugs_classes.txt table, the outer .get() returns None and the
chained .get() raises AttributeError: 'NoneType' object has no attribute 'get',
crashing the whole run instead of falling through to the existing
"unassigned markers" fallback path a few lines below.

This now defaults the lookup to an empty dict when the subclass is missing
(matching the .get('drug class', '-') fallback pattern already used in
_assign_drug_from_rule), and emits a warnings.warn() so a gap in the
conversion table is visible instead of silent.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AttributeError in _assign_drug_from_amrfp

2 participants