Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions bia_ro_crate/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
Protocol,
SpecimenImagingPreparationProtocol,
Study,
FileReference
)
from .bia_to_zarr_crate.conversion import create_ro_crate_for_image
from pathlib import Path
Expand Down Expand Up @@ -78,15 +79,9 @@ def convert(
),
] = Path(__file__).parents[1],
):
# crate_path = (
# Path(__file__).parents[0]
# / "model"
# / "example"
# / "S-BIAD1494"
# / "ro-crate-version"
# )

crate = crate_read(crate_path)
# Just for validation
crate_read(crate_path)

entities = process_ro_crate(crate_path)

Expand All @@ -97,7 +92,8 @@ def convert(

study_uuid = study.uuid

api_objects += Dataset.create_api_dataset(entities, study_uuid)
datasets = Dataset.create_api_dataset(entities, study_uuid)
api_objects += datasets
api_objects += AnnotationMethod.create_api_image_acquisition_protocol(
entities, study_uuid
)
Expand All @@ -110,6 +106,11 @@ def convert(
entities, study_uuid
)


api_objects += FileReference.create_file_reference(
entities, study_uuid, crate_path
)

ApiModels = RootModel[list]
write_out = ApiModels(api_objects)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"@context": {
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"bia": "http://bia/",
"schema": "http://schema.org/",
"name": {
Expand Down Expand Up @@ -226,7 +227,7 @@
"@type": "@id"
},
"association": {
"@id": "biashapes:association",
"@id": "bia:association",
"@type": "@id"

},
Expand Down Expand Up @@ -498,7 +499,7 @@
},
{
"@id": "_:a0",
"@type": "biashape:Association",
"@type": "bia:Association",
"associated_bio_sample": [
"Nup133 mouse stem cells"
],
Expand All @@ -521,7 +522,7 @@
},
{
"@id": "_:a1",
"@type": "biashape:Association",
"@type": "bia:Association",
"associated_bio_sample": [
"Nup133 mouse stem cells"
],
Expand All @@ -544,7 +545,7 @@
},
{
"@id": "_:a2",
"@type": "biashape:Association",
"@type": "bia:Association",
"associated_bio_sample": [
"Nup133 mouse stem cells"
],
Expand All @@ -567,7 +568,7 @@
},
{
"@id": "_:a3",
"@type": "biashape:Association",
"@type": "bia:Association",
"associated_bio_sample": [
"Nup133 mouse stem cells"
],
Expand All @@ -590,7 +591,7 @@
},
{
"@id": "_:a4",
"@type": "biashape:Association",
"@type": "bia:Association",
"associated_bio_sample": [
"Nup133 mouse stem cells"
],
Expand All @@ -613,7 +614,7 @@
},
{
"@id": "_:a5",
"@type": "biashape:Association",
"@type": "bia:Association",
"associated_bio_sample": [
"Nup133 mouse stem cells"
],
Expand All @@ -636,7 +637,7 @@
},
{
"@id": "_:a6",
"@type": "biashape:Association",
"@type": "bia:Association",
"associated_bio_sample": [
"Nup133 mouse stem cells"
],
Expand All @@ -659,7 +660,7 @@
},
{
"@id": "_:a7",
"@type": "biashape:Association",
"@type": "bia:Association",
"associated_bio_sample": [
"Nup133 mouse stem cells"
],
Expand All @@ -682,7 +683,7 @@
},
{
"@id": "_:a8",
"@type": "biashape:Association",
"@type": "bia:Association",
"associated_bio_sample": [
"Nup133 mouse stem cells"
],
Expand All @@ -705,7 +706,7 @@
},
{
"@id": "_:a9",
"@type": "biashape:Association",
"@type": "bia:Association",
"associated_bio_sample": [
"Wild type mouse stem cells"
],
Expand All @@ -728,7 +729,7 @@
},
{
"@id": "_:a10",
"@type": "biashape:Association",
"@type": "bia:Association",
"associated_bio_sample": [
"Wild type mouse stem cells"
],
Expand All @@ -751,7 +752,7 @@
},
{
"@id": "_:a11",
"@type": "biashape:Association",
"@type": "bia:Association",
"associated_bio_sample": [
"Wild type mouse stem cells"
],
Expand All @@ -774,7 +775,7 @@
},
{
"@id": "_:a12",
"@type": "biashape:Association",
"@type": "bia:Association",
"associated_bio_sample": [
"Wild type mouse stem cells"
],
Expand All @@ -797,7 +798,7 @@
},
{
"@id": "_:a13",
"@type": "biashape:Association",
"@type": "bia:Association",
"associated_bio_sample": [
"Wild type mouse stem cells"
],
Expand All @@ -820,7 +821,7 @@
},
{
"@id": "_:a14",
"@type": "biashape:Association",
"@type": "bia:Association",
"associated_bio_sample": [
"Wild type mouse stem cells"
],
Expand All @@ -843,7 +844,7 @@
},
{
"@id": "_:a15",
"@type": "biashape:Association",
"@type": "bia:Association",
"associated_bio_sample": [
"Wild type mouse stem cells"
],
Expand All @@ -866,7 +867,7 @@
},
{
"@id": "_:a16",
"@type": "biashape:Association",
"@type": "bia:Association",
"associated_bio_sample": [
"Wild type mouse stem cells"
],
Expand All @@ -889,7 +890,7 @@
},
{
"@id": "_:a17",
"@type": "biashape:Association",
"@type": "bia:Association",
"associated_bio_sample": [
"Wild type mouse stem cells"
],
Expand Down
17 changes: 16 additions & 1 deletion bia_ro_crate/ro_crate_to_bia/crate_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
import bia_ro_crate.ro_crate_to_bia.ingest_models as ingest_models
import inspect
import pyld
import rdflib
import logging

logger = logging.getLogger("__main__." + __name__)


def read_json_from_ro_crate(crate_path: str) -> dict:
Expand All @@ -26,6 +30,7 @@ def read_json_from_ro_crate(crate_path: str) -> dict:


def validate_json(data):
# TODO: Implement actual validation logic using models & context. RO-CRATE json structure is still under a lot of discussion, so defaulting to True for now.
return True


Expand All @@ -49,7 +54,17 @@ def load_entities(data: dict) -> dict[str, ROCrateModel]:
crate_objects_by_id[object.id] = object
break
if len(crate_objects_by_id) == start_len:
print(f"Could not find class for {entity}")
if "ro-crate-metadata.json" == entity.get("@id"):
logger.info("Skipping ro-crate-metadata.json entity.")
elif str(rdflib.RDF.Property) in entity_type:
logger.info(
f"Skipping RDF.Property: {entity.get('name')}. Though we may want to processes these in some way later"
)
else:
logger.warning(
f"Could not find class for entity of types: {entity_type}"
)
logger.debug(f"Entity: {entity}")
return crate_objects_by_id


Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from uuid import UUID
from bia_ro_crate.ro_crate_to_bia.pydantic_ld.ROCrateModel import ROCrateModel
from bia_shared_datamodels import uuid_creation
from bia_integrator_api.models import AnnotationMethod as APIAnnotationMethod
import bia_ro_crate.ro_crate_to_bia.ingest_models as ROCrateModels
import logging

logger = logging.getLogger("__main__." + __name__)


def create_api_image_acquisition_protocol(
crate_objects_by_id: dict[str, ROCrateModel], study_uuid: str
Expand All @@ -16,18 +19,15 @@ def create_api_image_acquisition_protocol(
annotation_method_list = []
for annotation_method in ro_crate_annotation_method:
annotation_method_list.append(
convert_annotation_method(
annotation_method, crate_objects_by_id, study_uuid
)
convert_annotation_method(annotation_method, study_uuid)
)

return annotation_method_list


def convert_annotation_method(
ro_crate_annotation_method: ROCrateModels.AnnotationMethod,
crate_objects_by_id: dict[str, ROCrateModel],
study_uuid: UUID,
study_uuid: str,
) -> APIAnnotationMethod:
iap = {
"uuid": uuid_creation.create_annotation_method_uuid(
Expand All @@ -39,6 +39,7 @@ def convert_annotation_method(
"annotation_coverage": ro_crate_annotation_method.annotation_coverage,
"method_type": ro_crate_annotation_method.method_type,
"annotation_source_indicator": ro_crate_annotation_method.annotation_source_indicator,
"version": 0,
}

return APIAnnotationMethod(**iap)
8 changes: 5 additions & 3 deletions bia_ro_crate/ro_crate_to_bia/entity_conversion/BioSample.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from uuid import UUID
from bia_ro_crate.ro_crate_to_bia.pydantic_ld.ROCrateModel import ROCrateModel
from bia_shared_datamodels import uuid_creation
import bia_integrator_api.models as APIModels
import bia_ro_crate.ro_crate_to_bia.ingest_models as ROCrateModels
import logging

logger = logging.getLogger("__main__." + __name__)


def create_api_bio_sample(
Expand All @@ -25,7 +27,7 @@ def create_api_bio_sample(
def convert_bio_sample(
ro_crate_bio_sample: ROCrateModels.BioSample,
crate_objects_by_id: dict[str, ROCrateModel],
study_uuid: UUID,
study_uuid: str,
) -> APIModels.BioSample:

taxons = []
Expand All @@ -37,7 +39,7 @@ def convert_bio_sample(
uuid_creation.create_bio_sample_uuid(ro_crate_bio_sample.id, study_uuid)
),
"title_id": ro_crate_bio_sample.id,
"version": 1,
"version": 0,
"organism_classification": taxons,
"biological_entity_description": ro_crate_bio_sample.biological_entity_description,
"intrinsic_variable_description": ro_crate_bio_sample.intrinsic_variable_description,
Expand Down
23 changes: 9 additions & 14 deletions bia_ro_crate/ro_crate_to_bia/entity_conversion/Dataset.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from uuid import UUID
from bia_ro_crate.ro_crate_to_bia.pydantic_ld.ROCrateModel import ROCrateModel
from bia_shared_datamodels import uuid_creation
import bia_integrator_api.models as APIModels
import bia_ro_crate.ro_crate_to_bia.ingest_models as ROCrateModels
import logging

logger = logging.getLogger("__main__." + __name__)


def create_api_dataset(
Expand All @@ -16,17 +18,14 @@ def create_api_dataset(

dataset_list = []
for dataset in ro_crate_datasets:
dataset_list.append(
convert_image_acquisition_protocol(dataset, crate_objects_by_id, study_uuid)
)
dataset_list.append(convert_dataset(dataset, study_uuid))

return dataset_list


def convert_image_acquisition_protocol(
def convert_dataset(
ro_crate_dataset: ROCrateModels.Dataset,
crate_objects_by_id: dict[str, ROCrateModel],
study_uuid: UUID,
study_uuid: str,
) -> APIModels.Dataset:

title = None
Expand All @@ -36,16 +35,12 @@ def convert_image_acquisition_protocol(
title = ro_crate_dataset.id

dataset = {
"uuid": str(
uuid_creation.create_image_acquisition_protocol_uuid(
ro_crate_dataset.id, study_uuid
)
),
"uuid": str(uuid_creation.create_dataset_uuid(ro_crate_dataset.id, study_uuid)),
"submitted_in_study_uuid": study_uuid,
"title_id": title,
"description": ro_crate_dataset.description,
"version": 1,
"example_image_uri": []
"version": 0,
"example_image_uri": [],
}

return APIModels.Dataset(**dataset)
Loading
Loading