-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: test cases for annotated variants
- Loading branch information
Showing
12 changed files
with
517 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,132 @@ | ||
import logging | ||
from datetime import datetime | ||
from typing import Union | ||
|
||
from ga4gh.core.entity_models import Contribution | ||
from ga4gh.core.entity_models import Contribution, Coding, Extension | ||
|
||
from mavedb.models.experiment_set import ExperimentSet | ||
from mavedb.models.experiment import Experiment | ||
from mavedb.models.score_set import ScoreSet | ||
from mavedb.models.mapped_variant import MappedVariant | ||
from mavedb.lib.annotation.agent import mavedb_api_agent, mavedb_vrs_agent, pillar_project_calibration_agent | ||
from mavedb.models.variant import Variant | ||
from mavedb.models.user import User | ||
from mavedb.lib.annotation.agent import ( | ||
mavedb_api_agent, | ||
mavedb_vrs_agent, | ||
mavedb_user_agent, | ||
pillar_project_calibration_agent, | ||
) | ||
from mavedb.lib.annotation.method import mavedb_api_as_method, mavedb_vrs_as_method, pillar_project_calibration_method | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
# Non-exhaustive | ||
ResourceWithCreationModificationDates = Union[ExperimentSet, Experiment, ScoreSet, MappedVariant, Variant] | ||
|
||
|
||
def mavedb_api_contribution() -> Contribution: | ||
return Contribution(contributor=[mavedb_api_agent()], date=datetime.today(), specifiedBy=[mavedb_api_as_method()]) | ||
""" | ||
Create a [VA Contribution](https://va-ga4gh.readthedocs.io/en/latest/core-information-model/entities/activities/contribution.html#contribution) | ||
object for an arbitary contribution from the MaveDB API/software distribution. | ||
""" | ||
return Contribution( | ||
contributor=[mavedb_api_agent()], | ||
date=datetime.today().strftime("%Y-%m-%d"), | ||
specifiedBy=[mavedb_api_as_method()], | ||
activityType=Coding( | ||
label="application programming interface", | ||
system="http://purl.obolibrary.org/obo/swo.owl", | ||
systemVersion="2023-03-05", | ||
code="SWO_9000054", | ||
), | ||
) | ||
|
||
|
||
def mavedb_vrs_contribution(mapped_variant: MappedVariant) -> Contribution: | ||
""" | ||
Create a [VA Contribution](https://va-ga4gh.readthedocs.io/en/latest/core-information-model/entities/activities/contribution.html#contribution) | ||
object from the provided mapped variant. | ||
""" | ||
return Contribution( | ||
contributor=[mavedb_vrs_agent(mapped_variant.mapping_api_version)], | ||
date=mapped_variant.mapped_date, | ||
date=datetime.strftime(mapped_variant.mapped_date, "%Y-%m-%d"), | ||
specifiedBy=[mavedb_vrs_as_method()], | ||
activityType=Coding( | ||
label="planned process", | ||
system="http://purl.obolibrary.org/obo/swo.owl", | ||
systemVersion="2023-03-05", | ||
code="OBI_0000011", | ||
), | ||
) | ||
|
||
|
||
def pillar_project_calibration_contribution() -> Contribution: | ||
""" | ||
Create a [VA Contribution](https://va-ga4gh.readthedocs.io/en/latest/core-information-model/entities/activities/contribution.html#contribution) | ||
object for a sofware agent which performs calibrations on an arbitrary data set. | ||
""" | ||
return Contribution( | ||
contributor=[pillar_project_calibration_agent()], | ||
specifiedBy=[pillar_project_calibration_method()], | ||
activityType=Coding( | ||
label="planned process", | ||
system="http://purl.obolibrary.org/obo/swo.owl", | ||
systemVersion="2023-03-05", | ||
code="OBI_0000011", | ||
), | ||
) | ||
|
||
|
||
def mavedb_creator_contribution(created_resource: ResourceWithCreationModificationDates, creator: User) -> Contribution: | ||
""" | ||
Create a [VA Contribution](https://va-ga4gh.readthedocs.io/en/latest/core-information-model/entities/activities/contribution.html#contribution) | ||
object from the provided createable resource (a resource with both a creation date and creator). | ||
""" | ||
return Contribution( | ||
contributor=[pillar_project_calibration_agent()], specifiedBy=[pillar_project_calibration_method()] | ||
contributor=[mavedb_user_agent(creator)], | ||
date=datetime.strftime(created_resource.creation_date, "%Y-%m-%d"), | ||
label="Resource First Submitted", | ||
activityType=Coding( | ||
label="submitter role", | ||
system="http://purl.obolibrary.org/obo/cro.owl", | ||
code="CRO_0000105", | ||
systemVersion="v2019-08-16", | ||
), | ||
extensions=[Extension(name="resourceType", value=created_resource.__class__.__name__)], | ||
) | ||
|
||
|
||
def mavedb_modifier_contribution( | ||
modified_resource: ResourceWithCreationModificationDates, modifier: User | ||
) -> Contribution: | ||
""" | ||
Create a [VA Contribution](https://va-ga4gh.readthedocs.io/en/latest/core-information-model/entities/activities/contribution.html#contribution) | ||
object from the provided modifiable resource (a resource with both a modification date and modifier). | ||
""" | ||
return Contribution( | ||
contributor=[mavedb_user_agent(modifier)], | ||
date=datetime.strftime(modified_resource.modification_date, "%Y-%m-%d"), | ||
label="Resource Last Updated", | ||
activityType=Coding( | ||
label="modifier role", | ||
system="http://purl.obolibrary.org/obo/cro.owl", | ||
code="CRO_0000103", | ||
systemVersion="v2019-08-16", | ||
), | ||
extensions=[Extension(name="resourceType", value=modified_resource.__class__.__name__)], | ||
) | ||
|
||
|
||
# TODO: Although we would ideally provide a contribution object for the publisher of the data set, we don't | ||
# save which user actually published it. We could proxy this by just using the creator, but this is | ||
# not always strictly accurate. | ||
# | ||
# ResourceWithPublicationDate = Union[ExperimentSet, Experiment, ScoreSet] | ||
# def mavedb_publisher_contribution(published_resource: ResourceWithCreatorModifier, publisher: User) -> Contribution: | ||
# return Contribution( | ||
# contributor=[mavedb_user_agent(publisher)], | ||
# date=datetime.strftime(published_resource.publication_date, "%Y-%m-%d"), | ||
# label="Resource First Published", | ||
# activityType=Coding(label="author role", system="http://purl.obolibrary.org/obo/cro.owl", code="CRO_0000001", systemVersion="v2019-08-16"), | ||
# extensions=[Extension(name="resourceType", value=published_resource.__class__)], | ||
# ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,29 @@ | ||
import logging | ||
from datetime import datetime | ||
|
||
from ga4gh.core.entity_models import DataSet | ||
|
||
from mavedb.models.score_set import ScoreSet | ||
|
||
from mavedb.lib.annotation.contribution import mavedb_creator_contribution, mavedb_modifier_contribution | ||
from mavedb.lib.annotation.document import score_set_to_document | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
# TODO: How deep should these objects get? See: https://github.com/ga4gh/va-spec/blob/1.x/examples/mavedb/pten-variant-example.json | ||
def score_set_to_data_set(score_set: ScoreSet) -> DataSet: | ||
""" | ||
Transforms a score set object to a GA4GH DataSet object. | ||
Create a [VA Data Set](https://va-ga4gh.readthedocs.io/en/latest/core-information-model/entities/information-entities/dataset.html#data-set) | ||
object from the provided MaveDB score set. | ||
""" | ||
return DataSet( | ||
id=score_set.urn, | ||
subtype="variant effect data set", | ||
label="Variant effect data set", | ||
license=score_set.license.short_name, | ||
# TODO: Stitch together constants to create this string. | ||
# TODO: Better to use this IRI reference, or the actual `Document` GA4GH object? | ||
reportedIn=score_set_to_document(score_set), | ||
reportedIn=[score_set_to_document(score_set)], | ||
contributions=[ | ||
mavedb_creator_contribution(score_set, score_set.created_by), | ||
mavedb_modifier_contribution(score_set, score_set.modified_by), | ||
], | ||
releaseDate=datetime.strftime(score_set.published_date, "%Y-%m-%d"), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.