Skip to content

Commit

Permalink
Fixed some of the linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
fatimarabab committed Sep 13, 2024
1 parent 4d277ab commit cc99a41
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 45 deletions.
51 changes: 28 additions & 23 deletions backend/src/core/annotation_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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'])

Expand Down
1 change: 0 additions & 1 deletion backend/tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion backend/tests/unit/core/test_annotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 11 additions & 20 deletions backend/tests/unit/core/test_annotation_task.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -124,40 +123,32 @@ 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()
assert actual_version_json == expected


@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):
Expand Down

0 comments on commit cc99a41

Please sign in to comment.