Skip to content

Commit

Permalink
Merge pull request #252 from dandi/enh-ngff
Browse files Browse the repository at this point in the history
Add support for detection and addition of ome/ngff "standard" into assets summary
  • Loading branch information
yarikoptic authored Nov 4, 2024
2 parents d3cc4b4 + f82c121 commit 4b17876
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
13 changes: 9 additions & 4 deletions dandischema/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,13 +380,18 @@ def _add_asset_to_stats(assetmeta: Dict[str, Any], stats: _stats_type) -> None:
stats["tissuesample"].append(sample)

stats["dataStandard"] = stats.get("dataStandard", [])

def add_if_missing(standard: dict) -> None:
if standard not in stats["dataStandard"]:
stats["dataStandard"].append(standard)

if "nwb" in assetmeta["encodingFormat"]:
if models.nwb_standard not in stats["dataStandard"]:
stats["dataStandard"].append(models.nwb_standard)
add_if_missing(models.nwb_standard)
# TODO: RF assumption that any .json implies BIDS
if set(Path(assetmeta["path"]).suffixes).intersection((".json", ".nii")):
if models.bids_standard not in stats["dataStandard"]:
stats["dataStandard"].append(models.bids_standard)
add_if_missing(models.bids_standard)
if Path(assetmeta["path"]).suffixes == [".ome", ".zarr"]:
add_if_missing(models.ome_ngff_standard)


# TODO?: move/bind such helpers as .from_metadata or alike within
Expand Down
5 changes: 5 additions & 0 deletions dandischema/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,11 @@ class StandardsType(BaseType):
identifier="RRID:SCR_016124",
).model_dump(mode="json", exclude_none=True)

ome_ngff_standard = StandardsType(
name="OME/NGFF Standard",
identifier="DOI:10.25504/FAIRsharing.9af712",
).model_dump(mode="json", exclude_none=True)


class ContactPoint(DandiBaseModel):
email: Optional[EmailStr] = Field(
Expand Down
12 changes: 8 additions & 4 deletions dandischema/tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ def test_aggregation_bids() -> None:
{
"id": "dandiasset:6668d37f-e842-4b73-8c20-082a1dd0d31a",
"path": "sub-MITU01/ses-20210703h01m05s04/microscopy/sub-MITU01_"
"run-1_sample-163_stain-YO_chunk-5_spim.h5",
"run-1_sample-163_stain-YO_chunk-5_spim.ome.zarr",
"access": [
{"status": "dandi:OpenAccess", "schemaKey": "AccessRequirements"}
],
Expand All @@ -565,7 +565,7 @@ def test_aggregation_bids() -> None:
"contentSize": 38474544973,
"dateModified": "2021-07-22T23:59:16.060551-04:00",
"schemaVersion": "0.4.4",
"encodingFormat": "application/x-hdf5",
"encodingFormat": "application/x-zarr",
"wasGeneratedBy": [
{
"id": "urn:uuid:aef77d59-7a7f-4320-9d4b-9b03f3e25e54",
Expand All @@ -588,7 +588,7 @@ def test_aggregation_bids() -> None:
{
"id": "dandiasset:84dd580f-8d4a-43f8-bda3-6fb53fb5d3a2",
"path": "sub-MITU01/ses-20210703h16m32s10/microscopy/sub-MITU01_"
"ses-20210703h16m32s10_run-1_sample-162_stain-LEC_chunk-5_spim.h5",
"ses-20210703h16m32s10_run-1_sample-162_stain-LEC_chunk-5_spim.ome.zarr",
"access": [
{"status": "dandi:OpenAccess", "schemaKey": "AccessRequirements"}
],
Expand All @@ -611,7 +611,7 @@ def test_aggregation_bids() -> None:
"contentSize": 61774316916,
"dateModified": "2021-10-01T18:28:16.038990-04:00",
"schemaVersion": "0.6.0",
"encodingFormat": "application/x-hdf5",
"encodingFormat": "application/x-zarr",
"wasGeneratedBy": [
{
"id": "urn:uuid:8f69a248-0e6a-4fa1-8369-ae1cc63d59d8",
Expand All @@ -634,3 +634,7 @@ def test_aggregation_bids() -> None:
]
summary = aggregate_assets_summary(data)
assert summary["numberOfSamples"] == 2
assert (
sum(_.get("name", "").startswith("OME/NGFF") for _ in summary["dataStandard"])
== 1
) # only a single entry so we do not duplicate them

0 comments on commit 4b17876

Please sign in to comment.