Skip to content

Commit

Permalink
add print lab builder tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JLoveUOA committed Sep 12, 2024
1 parent b350f40 commit ba68385
Show file tree
Hide file tree
Showing 6 changed files with 223 additions and 98 deletions.
49 changes: 23 additions & 26 deletions src/ingestion_targets/print_lab_genomics/print_crate_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def add_medical_condition(
Returns:
ContextEntity: a context entity representing the medical condition
"""
identifier = medical_condition.identifier
identifier = medical_condition.roc_id
if condition := self.crate.dereference(identifier):
return condition
properties: Dict[str, str | list[str] | dict[str, Any]] = {
Expand Down Expand Up @@ -110,7 +110,7 @@ def add_participant(
now stored in the RO-Crate
"""

identifier = participant.id
identifier = participant.roc_id
if participant_obj := self.crate.dereference(identifier):
return participant_obj
properties: Dict[str, str | list[str] | dict[str, Any]] = {
Expand Down Expand Up @@ -162,44 +162,41 @@ def add_experiment(self, experiment: Experiment) -> ContextEntity:
return super().add_experiment(experiment)
properties: Dict[str, str | list[str] | dict[str, Any]] = {
"@type": "DataCatalog",
"participant": (
self.add_participant(experiment.participant).id
if experiment.participant
else ""
),
"gender": experiment.gender if experiment.gender else "",
"name": experiment.name,
"associated_disease": (
[
self.add_medical_condition(condition).id
for condition in experiment.associated_disease
]
if experiment.associated_disease
else []
),
"body_location": (
self.add_medical_condition(experiment.body_location).id
if experiment.body_location
else ""
),
"tissue_processing_method": (
experiment.tissue_processing_method
if experiment.tissue_processing_method
else ""
),
"analyate": experiment.analyate if experiment.analyate else "",
"description": experiment.description,
}
projects = []
for project in experiment.projects:
if crate_project := self.crate.dereference("#" + str(project.id)):
if crate_project := self.crate.dereference(project.roc_id):
projects.append(crate_project)
else:
projects.append(self.add_project(project))
experiment_obj = self._update_experiment_meta(
experiment=experiment, properties=properties, projects=projects
)

associated_diseases = (
[
self.add_medical_condition(condition)
for condition in experiment.associated_disease
]
if experiment.associated_disease
else []
)
experiment_obj.append_to("associated_disease", associated_diseases)
body_location = (
self.add_medical_condition(experiment.body_location)
if experiment.body_location
else None
)
experiment_obj.append_to(
"tissue_processing_method", experiment.tissue_processing_method
)
experiment_obj.append_to("body_location", body_location)
participant = self.add_participant(experiment.participant)
experiment_obj.append_to("participant", participant)
return self.crate.add(experiment_obj)

def add_dataset(self, dataset: Dataset) -> ContextEntity:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class SampleExperiment(
participant: Participant
analyate: Optional[str]
portion: Optional[str]
schema_type = "DataCatalog"
schema_type = ["DataCatalog", "BioSample"]


@dataclass(kw_only=True)
Expand Down
Loading

0 comments on commit ba68385

Please sign in to comment.