Fix AttributeError when AMRFinderPlus subclass is not in CARD conversion table - #35
Open
sanjaynagi wants to merge 1 commit into
Open
Conversation
…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.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #28.
Genotype._assign_drug_from_amrfp()chained.get('drug', '-')/.get('class', '-')directly ontocard_amrfp_conversion.get(self.amrfp_subclass). Theamrfp_to_card_drugs_classes.txtconversion 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_ACIDvs a table only carryingFUSIDIC ACID), the outer.get()returnsNone, and.get('drug', '-')onNoneraisesAttributeError: '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_ACIDsubclass on S. aureus samples.Fix: fall back to
{}when the lookup misses, so it flows into the existingif self.drug_class == '-': self.drug_class = 'unassigned markers'path instead of crashing, and emit awarnings.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.)