Skip to content

Commit

Permalink
Created metadata to store masknames for zarr stores (#134)
Browse files Browse the repository at this point in the history
* Created metadata to store masknames for zarr stores

* Adjusted version and manifest
  • Loading branch information
tkakar authored Sep 16, 2024
1 parent 7bb1807 commit 1202495
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion containers/seg-mudata-to-zarr/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.1
0.0.2
10 changes: 10 additions & 0 deletions containers/seg-mudata-to-zarr/context/create_zarr_stores.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import mudata as md
import pandas as pd
import numpy as np
import json

VAR_CHUNK_SIZE = 10
index_mapping = None
Expand Down Expand Up @@ -86,5 +87,14 @@ def create_zarr_for_masks(mdata, output_path):
zarr_store_path = f'{output_path}/{mask_name}.zarr'
mask_data.write_zarr(zarr_store_path, chunks=chunks)
print(f'Created Zarr store for the mask: {mask_name}')
write_masknames_to_metadata(mask_names, output_path)
except Exception as e:
print(f'Error in getting mask names from mudata {str(e)}')


def write_masknames_to_metadata(mask_names, output_path):
if isinstance(mask_names, pd.Categorical):
mask_names = mask_names.categories.tolist()
data = {'mask_names': mask_names}
with open(f'{output_path}/metadata.json', 'w') as file:
json.dump(data, file, indent=4)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"mask_names": [
"mask_0",
"mask_1",
"mask_2",
"mask_3",
"mask_4"
]
}
2 changes: 1 addition & 1 deletion seg-mudata-to-zarr-manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"pattern": "seg-to-mudata-zarr/multiome_downstream_tfidf.zarr/(.*)\\.zgroup",
"pattern": "seg-to-mudata-zarr/secondary_analysis.zarr/(.*)/(.*)\\.zgroup",
"description": "MuData Zarr store for storing annotations for segmentation masks",
"edam_ontology_term": "EDAM_1.24.format_2333"
}
Expand Down
2 changes: 1 addition & 1 deletion seg-mudata-to-zarr.cwl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class: CommandLineTool
baseCommand: ['python', '/main.py', '--output_dir', './seg-to-mudata-zarr', '--input_dir']
hints:
DockerRequirement:
dockerPull: hubmap/portal-container-seg-mudata-to-zarr:0.0.1
dockerPull: hubmap/portal-container-seg-mudata-to-zarr:0.0.2
inputs:
input_directory:
type: Directory
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"mask_names": [
"mask_0",
"mask_1",
"mask_2",
"mask_3",
"mask_4"
]
}

0 comments on commit 1202495

Please sign in to comment.