From cc99a41eba5493f53fa52c0c0d86b0aa2918adb7 Mon Sep 17 00:00:00 2001 From: Rabab Fatima Date: Fri, 13 Sep 2024 16:20:24 -0500 Subject: [PATCH] Fixed some of the linting errors --- backend/src/core/annotation_task.py | 51 ++++++++++--------- backend/tests/unit/conftest.py | 1 - backend/tests/unit/core/test_annotate.py | 1 - .../tests/unit/core/test_annotation_task.py | 31 ++++------- 4 files changed, 39 insertions(+), 45 deletions(-) diff --git a/backend/src/core/annotation_task.py b/backend/src/core/annotation_task.py index 566a68db..561ef914 100644 --- a/backend/src/core/annotation_task.py +++ b/backend/src/core/annotation_task.py @@ -41,12 +41,15 @@ def aggregate_string_replacements(self, base_string) -> str: genomic_unit['gene'] or genomic_unit['Entrez Gene Id'] example base string: - https://grch37.rest.ensembl.org/vep/human/hgvs/{hgvs_variant}?content-type=application/json;CADD=1;refseq=1; - return value: https://grch37.rest.ensembl.org/vep/human/hgvs/NM_001017980.3:c.164G>T?content-type=application/json;CADD=1;refseq=1; + https://grch37.rest.ensembl.org/vep/human/hgvs/{hgvs_variant}?content-type=application/json;CADD=1;refseq=1; + return value: + https://grch37.rest.ensembl.org/vep/human/hgvs/NM_001017980.3:c.164G>T?content-type=application/json;CADD=1;refseq=1; example base string: - .[].transcript_consequences[] | select( .transcript_id | contains(\"{transcript}\") ) | { CADD: .cadd_phred } - return value: .[].transcript_consequences[] | select( .transcript_id | contains(\"NM_001017980\") ) | { CADD: .cadd_phred } + .[].transcript_consequences[] | select( .transcript_id | contains(\"{transcript}\") ) + | { CADD: .cadd_phred } + return value: .[].transcript_consequences[] | select( .transcript_id | + contains(\"NM_001017980\") ) | { CADD: .cadd_phred } genomic unit within the annotation unit in this task to be { @@ -120,26 +123,29 @@ def extract(self, incomming_json): return annotations - def extract_version(self, incomming_version_json): - """ Extracts and returns as a 'string' to be saved in the database""" + def extract_version(self, incoming_version_json): + """ Interface extraction method for Version Annotation tasks""" - jq_query = "" - # depending on versioning_type have following - - # version_type = "rest" get jq result - - # version_type = "date" just save as is ? (NOT SURE) + version = "" + annotation_unit_json = {"version": self.annotation_unit.version} - # version_type = "rosalution" hardcode type, save as is + if self.annotation_unit.dataset['versioning_type'] == "rosalution": + annotation_unit_json["version"] = incoming_version_json["rosalution"] + elif self.annotation_unit.dataset['versioning_type'] == "date": + annotation_unit_json["version"] = incoming_version_json["date"] + else: + jq_query = self.annotation_unit.dataset['version_attribute'] - jq_results = empty_gen() - try: - jq_results = self.__json_extract__(jq_query, incomming_version_json) - except ValueError as value_error: - logger.info(('Failed to extract ', value_error)) - jq_result = next(jq_results, None) + jq_result = empty_gen() + try: + jq_result = self.__json_extract__(jq_query, incoming_version_json) + except ValueError as value_error: + logger.info(('Failed to extract version', value_error)) + jq_result = next(jq_result, None) + annotation_unit_json["version"] = jq_result - return jq_result + version = annotation_unit_json + return version class ForgeAnnotationTask(AnnotationTaskInterface): @@ -239,8 +245,6 @@ def annotate(self): return {} version = self.version_types[version_type]() - print("THIS IS THE VERSION RETREIVED FROM VERSION URL FOR " + version_type + " TYPE") - print(version) return version def get_annotation_version_from_rest(self): @@ -254,7 +258,8 @@ def get_annotation_version_from_rest(self): def build_versioning_url(self): """ - Builds the version URL from aggregate_string_replacements and then appends the list of query parameters for the list of datasets. + Builds the version URL from aggregate_string_replacements and + then appends the list of query parameters for the list of datasets. """ return self.aggregate_string_replacements(self.annotation_unit.dataset['version_url']) diff --git a/backend/tests/unit/conftest.py b/backend/tests/unit/conftest.py index 9c7e2aef..c3c34f9e 100644 --- a/backend/tests/unit/conftest.py +++ b/backend/tests/unit/conftest.py @@ -3,7 +3,6 @@ from unittest.mock import Mock import pytest -from backend.src.enums import GenomicUnitType from src.core.annotation_unit import AnnotationUnit from src.config import Settings from src.core.annotation import AnnotationService diff --git a/backend/tests/unit/core/test_annotate.py b/backend/tests/unit/core/test_annotate.py index 9f34b418..bcec22a9 100644 --- a/backend/tests/unit/core/test_annotate.py +++ b/backend/tests/unit/core/test_annotate.py @@ -2,7 +2,6 @@ from unittest.mock import Mock, patch import pytest -from src.core.annotation_unit import AnnotationUnit from src.core.annotation import AnnotationService from src.enums import GenomicUnitType from src.repository.analysis_collection import AnalysisCollection diff --git a/backend/tests/unit/core/test_annotation_task.py b/backend/tests/unit/core/test_annotation_task.py index d10d9c7d..34e1aeed 100644 --- a/backend/tests/unit/core/test_annotation_task.py +++ b/backend/tests/unit/core/test_annotation_task.py @@ -1,6 +1,5 @@ """Tests Annotation Tasks and the creation of them""" import pytest -from unittest.mock import patch from src.core.annotation_task import AnnotationTaskFactory, ForgeAnnotationTask, HttpAnnotationTask, VersionAnnotationTask from src.enums import GenomicUnitType @@ -124,9 +123,7 @@ def test_annotation_versioning_task_created(test_case, get_annotation_unit): ('LMNA', GenomicUnitType.GENE, 'OMIM', {"date": "rosalution-temp-manifest-00"}), ] ) -def test_process_annotation_versioning_all_types( - genomic_unit, genomic_unit_type, dataset_name, expected, get_version_task -): +def test_process_annotation_versioning_all_types(genomic_unit, dataset_name, expected, get_version_task): """Verifies that Version Annotation Tasks process and annotate for all 3 versioning types- date, rest, rosalution""" task = get_version_task(genomic_unit, dataset_name) actual_version_json = task.annotate() @@ -134,30 +131,24 @@ def test_process_annotation_versioning_all_types( @pytest.mark.parametrize( - "test_case", - [ - ( - 'VMA21', - GenomicUnitType.GENE, - 'Entrez Gene Id', - ), - # ('NM_001017980.3:c.164G>T', GenomicUnitType.HGVS_VARIANT, 'ClinVar_Variantion_Id') + "genomic_unit,genomic_unit_type,dataset_name,expected", [ + ('VMA21', GenomicUnitType.GENE, 'Entrez Gene Id', {"version": "rosalution-manifest-00"}), + ('VMA21', GenomicUnitType.GENE, 'Ensembl Gene Id', {"version": 112}), + ('LMNA', GenomicUnitType.GENE, 'OMIM', {"version": "rosalution-temp-manifest-00"}), ] ) -def test_version_extraction(test_case, get_annotation_unit): - genomic_unit, genomic_unit_type, dataset_name = test_case - annotation_unit = get_annotation_unit(genomic_unit, genomic_unit_type, dataset_name) - version_task = AnnotationTaskFactory.create_version_task(annotation_unit) - version_json = version_task.annotate() - actual_version_extraction = version_task.extract_version(version_json) - assert actual_version_extraction == "rosalution-temp-manifest-00" +def test_version_extraction(genomic_unit, dataset_name, expected, get_version_task): + """ Verifies extraction for datasets for all 3 versioning types - rest, date, rosalution""" + task = get_version_task(genomic_unit, dataset_name) + actual_version_extraction = task.extract_version(task.annotate()) + assert actual_version_extraction == expected ## Fixtures ## @pytest.fixture(name="get_version_task") -def get_version_annotation_task(get_annotation_unit, genomic_units_with_types): +def get_version_annotation_task(get_annotation_unit): """creating version task""" def _create_version_task(genomic_unit, dataset_name):