diff --git a/scripts/README.md b/scripts/README.md index e3cca06c..9d591348 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -72,11 +72,13 @@ Run `python analyze.py [--correct]` to analyze annotations and optionally correct what can be corrected easily in `_corrected_.base64`. -| Check | Description | `--correct`ed | -| ----- | ----------- | ------------- | -| `has_consult` | Is "consult your pharmacist..." included in recommendation? | ✅ | -| `implication_severity` | Poor/ultrarapid phenotypes with "faster" or "slower" implication should have "much" keyword, intermediate/rapid not. Skips guidelines with multiple genes unless all results but one are missing or indeterminate. | ❌ | -| `red_warning` | Red warning level should always have recommendation "may not be the right medication" and vice versa. | ❌ | -| `yellow_warning` | Recommendation containing "adjusted" or "higher" or "lower" but not "may not be the right" should have yellow warning level. | ❌ | -| `green_warning` | Green warning level should have recommendation "at standard dose" but not "adjusted" and vise versa. | ❌ | -| `brand_whitespace` | Drug brand names should not have leading or trailing white space. | ✅ | +| Check | Description | `--correct`ed | Only for single-gene results* | +| ----- | ----------- | ------------- | ----------------------------- | +| `has_consult` | Is "consult your pharmacist..." included in recommendation? | ✅ | ❌ | +| `implication_severity` | Poor/ultrarapid phenotypes with "faster" or "slower" implication should have "much" keyword, intermediate/rapid not. | ❌ | ✅ | +| `red_warning` | Red warning level should always have recommendation "may not be the right medication" and vice versa. | ❌ | ❌ | +| `yellow_warning` | Recommendation containing "adjusted" or "higher" or "lower" but not "may not be the right" should have yellow warning level. | ❌ | ❌ | +| `green_warning` | Green warning level should have recommendation "at standard dose" but not "adjusted" and vise versa. | ❌ | ❌ | +| `brand_whitespace` | Drug brand names should not have leading or trailing white space. | ✅ | ❌ | + +\* Skips guidelines with multiple genes unless all results but one are missing or indeterminate. diff --git a/scripts/analyze.py b/scripts/analyze.py index d0915935..5a3fc98d 100644 --- a/scripts/analyze.py +++ b/scripts/analyze.py @@ -67,18 +67,18 @@ def has_consult(_, annotations): def check_implication_severity(guideline, annotations): phenotype = get_phenotype_key(guideline).lower() - check_applies = True gene_number = len(guideline['phenotypes'].keys()) missing_genes = phenotype.count('no result') + \ phenotype.count('indeterminate') if gene_number - missing_genes != 1: - return check_applies + return None severity_rules = [ { 'has_much': True, 'phenotype': 'ultrarapid', 'implication': 'faster' }, { 'has_much': True, 'phenotype': 'poor', 'implication': 'slower' }, { 'has_much': False, 'phenotype': 'rapid', 'implication': 'faster' }, { 'has_much': False, 'phenotype': 'intermediate', 'implication': 'slower' }, ] + check_applies = True for severity_rule in severity_rules: if severity_rule['phenotype'] == 'rapid' and 'ultrarapid' in phenotype: continue @@ -146,8 +146,8 @@ def correct_inconsistency(data, item, check_name, corrections): def log_not_annotated(log_content): log_content.append(' – _not annotated_\n') -def log_all_passed(log_content): - log_content.append(' – _all checks passed_\n') +def log_all_passed(log_content, postfix=''): + log_content.append(f' – _all checks passed_{postfix}\n') def log_annotations(log_content, annotations): for key, value in annotations.items(): @@ -157,6 +157,7 @@ def log_annotations(log_content, annotations): def handle_failed_checks( data, item, result, corrections, should_correct, annotations, log_content): failed_checks = [] + skipped_checks = [] for check_name, check_result in result.items(): if check_result == False: corrected = should_correct and \ @@ -165,9 +166,18 @@ def handle_failed_checks( check_name = f'{check_name} (corrected)' if corrected \ else check_name failed_checks.append(check_name) - log_content.append(' - _some checks failed_: ' \ - f'{", ".join(failed_checks)}\n') - log_annotations(log_content, annotations) + if check_result == None: + skipped_checks.append(check_name) + skipped_checks_string = '' + if len(skipped_checks) > 0: + skipped_checks_string = (' (skipped checks: ' \ + f'{", ".join(skipped_checks)})') + if len(failed_checks) > 0: + log_content.append(' - _some checks failed_: ' \ + f'{", ".join(failed_checks)}{skipped_checks_string}\n') + log_annotations(log_content, annotations) + else: + log_all_passed(log_content, postfix=skipped_checks_string) DRUG_CHECKS = { 'brand_whitespace': check_brand_name_whitespace,