diff --git a/backend/src/core/annotation.py b/backend/src/core/annotation.py index e3331b74..89937fc5 100644 --- a/backend/src/core/annotation.py +++ b/backend/src/core/annotation.py @@ -122,7 +122,7 @@ def process_tasks(annotation_queue, genomic_unit_collection): # pylint: disable continue - task = AnnotationTaskFactory.create(annotation_unit.genomic_unit, annotation_unit.dataset) + task = AnnotationTaskFactory.create(annotation_unit) logger.info('%s Creating Task To Annotate...', format_annotation_logging(annotation_unit)) annotation_task_futures[executor.submit(task.annotate)] = (annotation_unit.genomic_unit, task) diff --git a/backend/src/core/annotation_task.py b/backend/src/core/annotation_task.py index 9fc96410..c12eebc6 100644 --- a/backend/src/core/annotation_task.py +++ b/backend/src/core/annotation_task.py @@ -10,6 +10,8 @@ import jq import requests +from ..core.annotation_unit import AnnotationUnit + # create logger logger = logging.getLogger(__name__) @@ -26,9 +28,9 @@ def empty_gen(): class AnnotationTaskInterface: """Abstract class to define the interface for the the types of Annotation Task""" - def __init__(self, genomic_unit_json: dict): + def __init__(self, genomic_unit: dict): self.dataset = {} - self.genomic_unit = genomic_unit_json + self.genomic_unit = genomic_unit def set(self, dataset: dict): """Adds the dataset configuration for the annotation""" @@ -110,9 +112,9 @@ class ForgeAnnotationTask(AnnotationTaskInterface): annotation depedencies and its genomic unit """ - def __init__(self, genomic_unit_json): + def __init__(self, genomic_unit): """Instantiates the force annotation task with the genomic unit's json""" - AnnotationTaskInterface.__init__(self, genomic_unit_json) + AnnotationTaskInterface.__init__(self, genomic_unit) def annotate(self): """ @@ -126,9 +128,9 @@ def annotate(self): class NoneAnnotationTask(AnnotationTaskInterface): """An empty annotation task to be a place holder for datasets that do not have an annotation type yet""" - def __init__(self, genomic_unit_json): + def __init__(self, genomic_unit): """Instantiates the annotation task for the fake annotation with a genomic unit""" - AnnotationTaskInterface.__init__(self, genomic_unit_json) + AnnotationTaskInterface.__init__(self, genomic_unit) def annotate(self): """Creates a fake 'annotation' using a randomly generated pause time to a query io operation""" @@ -144,9 +146,9 @@ def annotate(self): class CsvAnnotationTask(AnnotationTaskInterface): """Example placeholder for a future type of annotation task""" - def __init__(self, genomic_unit_json): + def __init__(self, genomic_unit): """Insantiates the annotation task associated with the genomic unit""" - AnnotationTaskInterface.__init__(self, genomic_unit_json) + AnnotationTaskInterface.__init__(self, genomic_unit) def annotate(self): """placeholder for annotating a genomic unit""" @@ -156,9 +158,9 @@ def annotate(self): class HttpAnnotationTask(AnnotationTaskInterface): """Initializes the annotation that uses an HTTP request to fetch the annotation""" - def __init__(self, genomic_unit_json): + def __init__(self, genomic_unit): """initializes the task with the genomic_unit""" - AnnotationTaskInterface.__init__(self, genomic_unit_json) + AnnotationTaskInterface.__init__(self, genomic_unit) def annotate(self): """builds the complete url and fetches the annotation with an http request""" @@ -191,9 +193,9 @@ def build_url(self): class VersionAnnotationTask(AnnotationTaskInterface): """An annotation task that gets the version of the annotation""" - def __init__(self, genomic_unit_json): + def __init__(self, genomic_unit): """initializes the task with the genomic_unit""" - AnnotationTaskInterface.__init__(self, genomic_unit_json) + AnnotationTaskInterface.__init__(self, genomic_unit) def annotate(self): """placeholder for annotating a genomic unit with version""" @@ -250,13 +252,13 @@ def register(cls, key: str, annotation_task_interface: AnnotationTaskInterface): cls.tasks[key] = annotation_task_interface @classmethod - def create(cls, genomic_unit_json: dict, dataset: dict): + def create(cls, annotation_unit: AnnotationUnit): """ Creates an annotation task with a genomic_units and dataset json. Instantiates the class according to a datasets 'annotation_source_type' from the datasets configurtion. """ # In the future, this could be modified to use a static function instead # and those would be set to the dict, or an additional dictionary - new_task = cls.tasks[dataset["annotation_source_type"]](genomic_unit_json) - new_task.set(dataset) + new_task = cls.tasks[annotation_unit.dataset["annotation_source_type"]](annotation_unit.genomic_unit) + new_task.set(annotation_unit.dataset) return new_task diff --git a/backend/tests/unit/core/test_annotation_task.py b/backend/tests/unit/core/test_annotation_task.py index 972bce38..dcbad512 100644 --- a/backend/tests/unit/core/test_annotation_task.py +++ b/backend/tests/unit/core/test_annotation_task.py @@ -3,6 +3,7 @@ from src.core.annotation_task import AnnotationTaskFactory, ForgeAnnotationTask, HttpAnnotationTask from src.enums import GenomicUnitType +from src.core.annotation_unit import AnnotationUnit def test_http_annotation_base_url(http_annotation_transcript_id): @@ -24,9 +25,9 @@ def test_http_annotation_task_build_url_with_dependency(http_annotation_task_gen assert actual == "https://hpo.jax.org/api/hpo/gene/45614" -def test_annotation_task_create_http_task(hgvs_variant_genomic_unit, transcript_id_dataset): +def test_annotation_task_create_http_task(hgvs_variant_annotation_unit): """Verifies that the annotation task factory creates the correct annotation task according to the dataset type""" - actual_task = AnnotationTaskFactory.create(hgvs_variant_genomic_unit, transcript_id_dataset) + actual_task = AnnotationTaskFactory.create(hgvs_variant_annotation_unit) assert isinstance(actual_task, HttpAnnotationTask) @@ -189,6 +190,15 @@ def fixture_transcript_id_dataset(): } +@pytest.fixture(name="hgvs_variant_annotation_unit") +def fixture_hgvs_variant_annotation_unit(hgvs_variant_genomic_unit, transcript_id_dataset): + """ + Returns the annotation unit with hgvs_variant genomic unit and transcript_id dataset + """ + annotation_unit = AnnotationUnit(hgvs_variant_genomic_unit, transcript_id_dataset) + return annotation_unit + + @pytest.fixture(name="http_annotation_transcript_id") def fixture_http_annotation_transcript_id(hgvs_variant_genomic_unit, transcript_id_dataset): """An HTTP annotation task with a single dataset"""