From e27a1595fad0b2f1cb2f90da8f5808a4a38115d1 Mon Sep 17 00:00:00 2001 From: Dave Lawrence Date: Tue, 26 Sep 2023 15:08:12 +0930 Subject: [PATCH] #805 - rename VARIANT_CLASSIFICATION_ to CLASSIFICATION_ --- .../evidence_from_variant.py | 2 +- classification/classification_stats.py | 2 +- ...f_check_variant_classification_settings.py | 33 +++++++++ classification/models/classification.py | 14 ++-- ...lassification_variant_fields_validation.py | 2 +- .../classification_variant_info_models.py | 4 +- classification/models/evidence_mixin.py | 2 +- classification/models/variant_resolver.py | 2 +- .../signals/classification_search.py | 2 +- ...assification_import_map_and_insert_task.py | 12 ++-- .../classification/classifications.html | 20 +++--- .../create_classification_for_variant.html | 2 +- .../tags/classification_group_row.html | 6 +- .../templatetags/classification_tags.py | 10 +-- .../models/test_classification_validation.py | 6 +- .../tests/utils/test_clinvar_export.py | 2 +- .../tests/views/test_classification_view.py | 8 +-- .../views/classification_dashboard_view.py | 2 +- .../views/classification_datatables.py | 16 ++--- .../views/classification_export_view.py | 2 +- .../classification_export_formatter_csv.py | 2 +- classification/views/views.py | 14 ++-- snpdb/models/models.py | 4 +- snpdb/processors.py | 2 +- snpdb/templatetags/lab_tags.py | 2 +- snpdb/views/views.py | 10 +-- .../settings/components/default_settings.py | 67 +++++++++---------- .../env/parallelsparallelsvirtualplatform.py | 6 +- variantgrid/settings/env/shariant.py | 48 ++++++------- variantgrid/settings/env/sharianttest.py | 4 +- 30 files changed, 170 insertions(+), 138 deletions(-) create mode 100644 classification/migrations/0112_one_off_check_variant_classification_settings.py diff --git a/classification/autopopulate_evidence_keys/evidence_from_variant.py b/classification/autopopulate_evidence_keys/evidence_from_variant.py index 151def8e9..b59b7cc9f 100644 --- a/classification/autopopulate_evidence_keys/evidence_from_variant.py +++ b/classification/autopopulate_evidence_keys/evidence_from_variant.py @@ -381,7 +381,7 @@ def get_evidence_fields_from_preferred_transcript( data[SpecialEKeys.P_HGVS] = clingen_allele.get_p_hgvs(transcript_version.accession, match_version=False) # If we have a synonymous protein change, but a molecular consequence of splicing, change the "=" into "?" - if settings.VARIANT_CLASSIFICATION_AUTO_POPULATE_P_HGVS_SYNONYMOUS_SPLICE_CHANGE_TO_UNKNOWN: + if settings.CLASSIFICATION_AUTO_POPULATE_P_HGVS_SYNONYMOUS_SPLICE_CHANGE_TO_UNKNOWN: p_hgvs = data[SpecialEKeys.P_HGVS] if p_hgvs and "=" in p_hgvs and "splice" in transcript_data.get("consequence", ""): prefix, allele = p_hgvs.split(":", 1) diff --git a/classification/classification_stats.py b/classification/classification_stats.py index d0422715a..d82f1842e 100644 --- a/classification/classification_stats.py +++ b/classification/classification_stats.py @@ -58,7 +58,7 @@ def get_classification_counts_allele(qs: QuerySet[ClassificationModification], f def get_visible_classifications_qs(user: User) -> QuerySet[ClassificationModification]: # now excludes external labs (don't want to report on Shariant only data within SA Path for example) - shared = settings.VARIANT_CLASSIFICATION_STATS_USE_SHARED + shared = settings.CLASSIFICATION_STATS_USE_SHARED kwargs = {"classification__lab__external": False} if shared: kwargs["clinical_significance__isnull"] = False diff --git a/classification/migrations/0112_one_off_check_variant_classification_settings.py b/classification/migrations/0112_one_off_check_variant_classification_settings.py new file mode 100644 index 000000000..a25178bc6 --- /dev/null +++ b/classification/migrations/0112_one_off_check_variant_classification_settings.py @@ -0,0 +1,33 @@ +# Generated by Django 4.2.2 on 2023-09-26 05:13 +import logging + +from django.conf import settings +from django.db import migrations + +from manual.operations.manual_operations import ManualOperation + +def _check_settings_for_variant_classification(apps): + has_old_settings = False + for x in dir(settings): + if x.startswith("VARIANT_CLASSIFICATION"): + if not has_old_settings: # Only show 1st time + logging.warning("Your developer settings has obsolete settings. Please rename:") + has_old_settings = True + old_setting = x + new_setting = x[len("VARIANT_"):] + logging.warning("settings.%s -> %s", old_setting, new_setting) + return has_old_settings + + +class Migration(migrations.Migration): + + dependencies = [ + ('classification', '0111_alter_resolvedvariantinfo_options'), + ] + + operations = [ + ManualOperation.operation_other([ + "Rename settings from VARIANT_CLASSIFICATION_X to CLASSIFICATION_X" + ], test=_check_settings_for_variant_classification), + ] + diff --git a/classification/models/classification.py b/classification/models/classification.py index 39837b85c..e87108e98 100644 --- a/classification/models/classification.py +++ b/classification/models/classification.py @@ -577,8 +577,8 @@ class Meta: @staticmethod def can_create_via_web_form(user: User): - can_create = settings.VARIANT_CLASSIFICATION_WEB_FORM_CREATE - return can_create and (user.is_superuser or settings.VARIANT_CLASSIFICATION_WEB_FORM_CREATE_BY_NON_ADMIN) + can_create = settings.CLASSIFICATION_WEB_FORM_CREATE + return can_create and (user.is_superuser or settings.CLASSIFICATION_WEB_FORM_CREATE_BY_NON_ADMIN) @staticmethod def dashboard_report_new_classifications(since) -> int: @@ -691,7 +691,7 @@ def id_str(self): @property def cr_lab_id(self): - if settings.VARIANT_CLASSIFICATION_ID_OVERRIDE_PREFIX: + if settings.CLASSIFICATION_ID_OVERRIDE_PREFIX: return f"CR_{self.id}" return self.lab_record_id @@ -1033,7 +1033,7 @@ def process_option_values(cell: VCDataCell, values: List[Any]) -> Optional[List[ matched_option = Classification.match_option(options, check_value) if matched_option: results.append(matched_option.get('key')) - if settings.VARIANT_CLASSIFICATION_REQUIRE_OVERWRITE_NOTE and \ + if settings.CLASSIFICATION_REQUIRE_OVERWRITE_NOTE and \ matched_option.get('override') and cell.note is None and cell.explain is None: cell.add_validation( code=ValidationCode.REQUIRES_NOTE, @@ -1246,7 +1246,7 @@ def process_entry(self, cell: VCDataCell, source: str): message='Transcript should include version e.g. NM_001256799.1') elif e_key.key == SpecialEKeys.AGE: - if settings.VARIANT_CLASSIFICATION_AUTOFUZZ_AGE: + if settings.CLASSIFICATION_AUTOFUZZ_AGE: cell.value = patch_fuzzy_age(value) # ensure we have one non None value before returning the structure @@ -2200,7 +2200,7 @@ def __str__(self) -> str: @staticmethod def check_can_create_no_classification_via_web_form(_user: User): - if not settings.VARIANT_CLASSIFICATION_WEB_FORM_CREATE_ALLOW_NO_VARIANT: + if not settings.CLASSIFICATION_WEB_FORM_CREATE_ALLOW_NO_VARIANT: raise CreateNoClassificationForbidden() @@ -2289,7 +2289,7 @@ def id_str(self) -> str: @property def cr_lab_id(self) -> str: - if settings.VARIANT_CLASSIFICATION_ID_OVERRIDE_PREFIX: + if settings.CLASSIFICATION_ID_OVERRIDE_PREFIX: return f"CR_{self.classification.id_str}" return self.classification.lab_record_id diff --git a/classification/models/classification_variant_fields_validation.py b/classification/models/classification_variant_fields_validation.py index 68dcf9aa8..6c9cea32b 100644 --- a/classification/models/classification_variant_fields_validation.py +++ b/classification/models/classification_variant_fields_validation.py @@ -24,7 +24,7 @@ def validate_variant_fields(sender, **kwargs) -> Optional[ValidationMerger]: # """ vm = ValidationMerger() - if not settings.VARIANT_CLASSIFICATION_MATCH_VARIANTS: + if not settings.CLASSIFICATION_MATCH_VARIANTS: # while this technically isn't about matching a variant, much of the work in get_variant_tuple -> pyhgvs # requires return vm diff --git a/classification/models/classification_variant_info_models.py b/classification/models/classification_variant_info_models.py index 877f43041..523447db0 100644 --- a/classification/models/classification_variant_info_models.py +++ b/classification/models/classification_variant_info_models.py @@ -131,7 +131,7 @@ def set_variant_and_save(self, variant: Variant) -> 'ResolvedVariantInfo': c_hgvs = hgvs_variant.format() c_hgvs_obj = CHGVS(c_hgvs) self.c_hgvs = c_hgvs - self.c_hgvs_full = hgvs_variant.format(max_ref_length=settings.VARIANT_CLASSIFICATION_MAX_REFERENCE_LENGTH) + self.c_hgvs_full = hgvs_variant.format(max_ref_length=settings.CLASSIFICATION_MAX_REFERENCE_LENGTH) self.transcript_version = c_hgvs_obj.transcript_version_model(genome_build=genome_build) self.gene_symbol = GeneSymbol.objects.filter(symbol=c_hgvs_obj.gene_symbol).first() except Exception as exception: @@ -586,7 +586,7 @@ def issue_icon(self) -> Optional[IconWithTooltip]: def is_supported_transcript(transcript_or_hgvs: str): if not transcript_or_hgvs: return False - for transcript_type in settings.VARIANT_CLASSIFICATION_SUPPORTED_TRANSCRIPTS: + for transcript_type in settings.CLASSIFICATION_SUPPORTED_TRANSCRIPTS: if transcript_or_hgvs.startswith(transcript_type): return True return False diff --git a/classification/models/evidence_mixin.py b/classification/models/evidence_mixin.py index 92eabbd44..136e4ea83 100644 --- a/classification/models/evidence_mixin.py +++ b/classification/models/evidence_mixin.py @@ -122,7 +122,7 @@ def loaded_citations(self) -> CitationFetchResponse: @property def is_likely_acmg(self) -> bool: - if non_standard_res := settings.VARIANT_CLASSIFICATION_NON_ACMG_ASSERTION_METHOD: + if non_standard_res := settings.CLASSIFICATION_NON_ACMG_ASSERTION_METHOD: if assertion_method := self.get(SpecialEKeys.ASSERTION_METHOD): for non_standard_re in non_standard_res: if non_standard_re.match(assertion_method): diff --git a/classification/models/variant_resolver.py b/classification/models/variant_resolver.py index 7fa255418..cf72bfe6e 100644 --- a/classification/models/variant_resolver.py +++ b/classification/models/variant_resolver.py @@ -26,7 +26,7 @@ def _classification_import_from(self, genome_build: GenomeBuild): def queue_resolve(self, imported_allele_info: ImportedAlleleInfo) -> bool: actually_queued = False - if settings.VARIANT_CLASSIFICATION_MATCH_VARIANTS: + if settings.CLASSIFICATION_MATCH_VARIANTS: if imported_allele_info.status == ImportedAlleleInfoStatus.PROCESSING and imported_allele_info.classification_import is None: if genome_build_version := imported_allele_info.imported_genome_build_patch_version: self.all_count += 1 diff --git a/classification/signals/classification_search.py b/classification/signals/classification_search.py index e4b51e1cd..29a3ec459 100644 --- a/classification/signals/classification_search.py +++ b/classification/signals/classification_search.py @@ -20,7 +20,7 @@ search_type=Classification, example=SearchExample( note="The lab record ID", - examples=["CR_1545" if settings.VARIANT_CLASSIFICATION_ID_OVERRIDE_PREFIX else "vc1545"] + examples=["CR_1545" if settings.CLASSIFICATION_ID_OVERRIDE_PREFIX else "vc1545"] ) ) def classification_search(search_input: SearchInputInstance): diff --git a/classification/tasks/classification_import_map_and_insert_task.py b/classification/tasks/classification_import_map_and_insert_task.py index 418b97432..a1ccfda20 100644 --- a/classification/tasks/classification_import_map_and_insert_task.py +++ b/classification/tasks/classification_import_map_and_insert_task.py @@ -26,7 +26,7 @@ class ClassificationImportMapInsertTask(Task): @property def data_dir(self) -> Path: - if data_dir_str := settings.VARIANT_CLASSIFICATION_OMNI_IMPORTER_DATA_DIR: + if data_dir_str := settings.CLASSIFICATION_OMNI_IMPORTER_DATA_DIR: data_dir = pathlib.Path(data_dir_str) data_dir.mkdir(parents=True, exist_ok=True) if not data_dir.exists(): @@ -35,15 +35,15 @@ def data_dir(self) -> Path: @property def omni_importer_dir(self) -> Path: - if omni_importer_dir_str := settings.VARIANT_CLASSIFICATION_OMNI_IMPORTER_APP_DIR: + if omni_importer_dir_str := settings.CLASSIFICATION_OMNI_IMPORTER_APP_DIR: omni_importer_dir = pathlib.Path(omni_importer_dir_str) if not omni_importer_dir.exists(): raise ValueError(f"{omni_importer_dir_str} does not exist") if not (omni_importer_dir / "main.py").exists(): - raise ValueError(f"main.py doesn't exist inside OMNI IMPORTER DIR {settings.VARIANT_CLASSIFICATION_OMNI_IMPORTER_APP_DIR}") + raise ValueError(f"main.py doesn't exist inside OMNI IMPORTER DIR {settings.CLASSIFICATION_OMNI_IMPORTER_APP_DIR}") return omni_importer_dir else: - raise ValueError("Require settings.VARIANT_CLASSIFICATION_OMNI_IMPORTER_APP_DIR to be set to do automated imports") + raise ValueError("Require settings.CLASSIFICATION_OMNI_IMPORTER_APP_DIR to be set to do automated imports") @staticmethod def update_status(upload_file: UploadedClassificationsUnmapped, status: UploadedClassificationsUnmappedStatus): @@ -99,8 +99,8 @@ def run(self, upload_classifications_unmapped_id: int, import_records: bool = Tr # and import it # --file data/path_west/sharmvl_grch38molecular_variants20220326_060243.json --publish logged_in_users --org path_west --lab unit_1 --env prod - publish = settings.VARIANT_CLASSIFICATION_OMNI_IMPORTER_PUBLISH_LEVEL - include_source = settings.VARIANT_CLASSIFICATION_OMNI_IMPORTER_INCLUDE_SOURCE + publish = settings.CLASSIFICATION_OMNI_IMPORTER_PUBLISH_LEVEL + include_source = settings.CLASSIFICATION_OMNI_IMPORTER_INCLUDE_SOURCE args: List[str] = [ settings.PYTHON_COMMAND, "main.py", diff --git a/classification/templates/classification/classifications.html b/classification/templates/classification/classifications.html index 690a88c5e..f06a4c276 100644 --- a/classification/templates/classification/classifications.html +++ b/classification/templates/classification/classifications.html @@ -150,10 +150,10 @@ {% endblock %} {% block content %} - {% settings_value 'VARIANT_CLASSIFICATION_GRID_SHOW_USERNAME' as VARIANT_CLASSIFICATION_GRID_SHOW_USERNAME %} - {% settings_value 'VARIANT_CLASSIFICATION_GRID_SHOW_ORIGIN' as VARIANT_CLASSIFICATION_GRID_SHOW_ORIGIN %} - {% settings_value 'VARIANT_CLASSIFICATION_ID_FILTER' as VARIANT_CLASSIFICATION_ID_FILTER %} - {% settings_value 'VARIANT_CLASSIFICATION_REDCAP_EXPORT' as VARIANT_CLASSIFICATION_REDCAP_EXPORT %} + {% settings_value 'CLASSIFICATION_GRID_SHOW_USERNAME' as CLASSIFICATION_GRID_SHOW_USERNAME %} + {% settings_value 'CLASSIFICATION_GRID_SHOW_ORIGIN' as CLASSIFICATION_GRID_SHOW_ORIGIN %} + {% settings_value 'CLASSIFICATION_ID_FILTER' as CLASSIFICATION_ID_FILTER %} + {% settings_value 'CLASSIFICATION_REDCAP_EXPORT' as CLASSIFICATION_REDCAP_EXPORT %}
{% if labs.count > 0 and can_create_classification %} @@ -177,10 +177,10 @@

{% endif %}

- Export the grid below by clicking the CSV {% if VARIANT_CLASSIFICATION_REDCAP_EXPORT %} or Redcap {% endif %}buttons on the bottom left of the grid.
+ Export the grid below by clicking the CSV {% if CLASSIFICATION_REDCAP_EXPORT %} or Redcap {% endif %}buttons on the bottom left of the grid.
The export will be using your default genome build.

- {% if VARIANT_CLASSIFICATION_REDCAP_EXPORT %} + {% if CLASSIFICATION_REDCAP_EXPORT %}

You can import into REDCap using this data definition.
Records will only be included in REDCap downloads if they have a value for redcap_record_id. @@ -200,19 +200,19 @@ {% endif %} {% crispy lab_form form_helper.horizontal_no_labels %}

- {% if VARIANT_CLASSIFICATION_GRID_SHOW_USERNAME %} + {% if CLASSIFICATION_GRID_SHOW_USERNAME %}
Filter : My Classifications {% crispy user_form form_helper.horizontal_no_labels %}
{% endif %} - {% if VARIANT_CLASSIFICATION_GRID_SHOW_ORIGIN %} + {% if CLASSIFICATION_GRID_SHOW_ORIGIN %}

{% crispy allele_origin_form form_helper.horizontal_no_labels %}
{% endif %} - {% if VARIANT_CLASSIFICATION_ID_FILTER %} + {% if CLASSIFICATION_ID_FILTER %}

@@ -241,7 +241,7 @@
Download as CSV - {% if VARIANT_CLASSIFICATION_REDCAP_EXPORT %}, + {% if CLASSIFICATION_REDCAP_EXPORT %}, REDCap {% endif %}
diff --git a/classification/templates/classification/create_classification_for_variant.html b/classification/templates/classification/create_classification_for_variant.html index 7e2b56ece..1caad37a5 100644 --- a/classification/templates/classification/create_classification_for_variant.html +++ b/classification/templates/classification/create_classification_for_variant.html @@ -9,7 +9,7 @@ {% block title %}Variant Classification{% endblock %} {% block head %} -{% settings_value 'VARIANT_CLASSIFICATION_WEB_FORM_CREATE_INITIALLY_REQUIRE_SAMPLE' as initially_require_sample %} +{% settings_value 'CLASSIFICATION_WEB_FORM_CREATE_INITIALLY_REQUIRE_SAMPLE' as initially_require_sample %}