diff --git a/scripts/analyze.py b/scripts/analyze.py index d714fc37..413c1448 100644 --- a/scripts/analyze.py +++ b/scripts/analyze.py @@ -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 @@ -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 = { @@ -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) @@ -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()): @@ -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}') @@ -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', diff --git a/scripts/analyze_functions/checks/metabolization_type.py b/scripts/analyze_functions/checks/metabolization_type.py new file mode 100644 index 00000000..0dc3ad60 --- /dev/null +++ b/scripts/analyze_functions/checks/metabolization_type.py @@ -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) \ No newline at end of file diff --git a/scripts/analyze_functions/constants.py b/scripts/analyze_functions/constants.py index d55acdbc..88da27d0 100644 --- a/scripts/analyze_functions/constants.py +++ b/scripts/analyze_functions/constants.py @@ -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'