Skip to content

Commit

Permalink
feat(#639): add same metabolization check
Browse files Browse the repository at this point in the history
  • Loading branch information
tamslo committed Oct 16, 2024
1 parent 4d9313c commit 0d0d7d8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
13 changes: 10 additions & 3 deletions scripts/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from analyze_functions.checks.brand_name import check_brand_name_comma, check_brand_name_whitespace
from analyze_functions.checks.metabolization_before_consequence import check_metabolization_before_consequence
from analyze_functions.checks.fallback_guidelines import check_single_any_fallback_guideline, check_single_lookup_fallback_guideline
from analyze_functions.checks.metabolization_type import check_same_metabolization_type
from analyze_functions.checks.non_metabolizer import check_non_metabolizer
from analyze_functions.checks.normal_side_effect_risk import check_normal_side_effect_risk
from analyze_functions.checks.slow_titration import check_slow_titration
Expand All @@ -27,6 +28,7 @@
'single_any_fallback': check_single_any_fallback_guideline,
'fallback_single_lookup': check_single_lookup_fallback_guideline,
'annotated_but_not_staged': check_if_fully_annotated_staged,
'same_metabolization': check_same_metabolization_type,
}

DRUG_CORRECTIONS = {
Expand Down Expand Up @@ -115,6 +117,11 @@ def run_analyses():
log_content.append(f'* {drug_name}')
used_bricks += get_used_bricks(drug)
drug_annotations = get_drug_annotations(data, drug)
guideline_ids = drug['guidelines']
guidelines = list(map(
lambda guideline_id: get_guideline_by_id(data, guideline_id),
guideline_ids,
))
if not has_annotations(drug_annotations):
missing_drug_annotation_count += 1
log_not_annotated(log_content)
Expand All @@ -126,6 +133,7 @@ def run_analyses():
'annotations': drug_annotations,
'data': data,
'drug_name': drug_name,
'drug_guidelines': guidelines,
},
)
if not all(drug_result.values()):
Expand All @@ -136,8 +144,7 @@ def run_analyses():
failed_drug_annotation_count += failed
else:
log_all_passed(log_content)
for guideline_id in drug['guidelines']:
guideline = get_guideline_by_id(data, guideline_id)
for guideline in guidelines:
used_bricks += get_used_bricks(guideline)
phenotype = get_phenotype_key(guideline)
log_content.append(f' * {phenotype}')
Expand Down Expand Up @@ -167,7 +174,7 @@ def run_analyses():
log_header = [
'# Analyze annotation data\n\n',
f'Correct if possible: {correct_inconsistencies}\n\n',
'Failed annotation checks (search for `_some checks failed_`):\n\n',
'**Failed annotation checks** (search for `_some checks failed_`):\n\n',
f'* Drugs: {failed_drug_annotation_count}\n',
f'* Guidelines: {failed_guideline_annotation_count}\n\n',
'Missing annotations (search for `_not annotated_`):\n\n',
Expand Down
16 changes: 16 additions & 0 deletions scripts/analyze_functions/checks/metabolization_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from analyze_functions.constants import ACTIVATE_TEXT, BREAK_DOWN_TEXT
from analyze_functions.data_helpers import get_guideline_annotations

def check_same_metabolization_type(args):
data = args['data']
guidelines = args['drug_guidelines']
has_activate = False
has_break_down = False
for guideline in guidelines:
if has_activate and has_break_down: break
annotations = get_guideline_annotations(data, guideline)
implication = annotations['implication']
if implication == None: continue
if ACTIVATE_TEXT in implication: has_activate = True
if BREAK_DOWN_TEXT in implication: has_break_down = True
return not (has_activate and has_break_down)
4 changes: 3 additions & 1 deletion scripts/analyze_functions/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
'HLA-B',
'HLA-A',
]
METABOLIZER_TEXTS = ['break down', 'activate']
BREAK_DOWN_TEXT = 'break down'
ACTIVATE_TEXT = 'activate'
METABOLIZER_TEXTS = [BREAK_DOWN_TEXT, ACTIVATE_TEXT]
MISSING_PHENOTYPES = ['no result', 'indeterminate']
IGNORED_PHENOTYPES = [*MISSING_PHENOTYPES, 'normal metabolizer']
RED_TEXT = 'not be the right medication'
Expand Down

0 comments on commit 0d0d7d8

Please sign in to comment.