Skip to content

Commit abe5f04

Browse files
committed
Added tests
1 parent a4597c2 commit abe5f04

File tree

6 files changed

+71
-4
lines changed

6 files changed

+71
-4
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "vitessce"
7-
version = "3.5.9"
7+
version = "3.6.0"
88
authors = [
99
{ name="Mark Keller", email="[email protected]" },
1010
]

src/vitessce/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ class FileType(DocEnum):
164164
ANNDATA_ZARR = "anndata.zarr", "Joint file type for AnnData objects"
165165
SPATIALDATA_ZARR = "spatialdata.zarr", "Joint file type for SpatialData objects"
166166
ANNDATA_H5AD = "anndata.h5ad", "Joint file type for AnnData objects"
167+
ANNDATA_ZIPPED_ZARR = "anndata.zarr.zip", "Joint file type for AnnData objects"
167168
OBS_EMBEDDING_CSV = 'obsEmbedding.csv', "File type for obsEmbedding values stored in a CSV file"
168169
OBS_LOCATIONS_CSV = 'obsLocations.csv', "File type for obsLocations values stored in a CSV file"
169170
OBS_LABELS_CSV = 'obsLabels.csv', "File type for obsLabels values stored in a CSV file"

src/vitessce/wrappers.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,6 +1229,7 @@ def __init__(self, adata_path=None, adata_url=None, adata_store=None, adata_arti
12291229
self._adata_url = adata_url
12301230
self._adata_store = adata_store
12311231
self._adata_artifact = adata_artifact
1232+
self.is_zip = False
12321233

12331234
# For reference spec JSON with .h5ad files
12341235
self._ref_path = ref_path
@@ -1250,11 +1251,15 @@ def __init__(self, adata_path=None, adata_url=None, adata_store=None, adata_arti
12501251
self.is_remote = False
12511252
self.is_store = False
12521253
self.zarr_folder = 'anndata.zarr'
1254+
if '.zip' in str(adata_path):
1255+
self.is_zip = True
1256+
self.zarr_folder = 'anndata.zarr.zip'
12531257
elif adata_url is not None or adata_artifact is not None:
12541258
self.is_remote = True
12551259
self.is_store = False
12561260
self.zarr_folder = None
1257-
1261+
if '.zip' in str(adata_url):
1262+
self.is_zip = True
12581263
# Store artifacts on AbstractWrapper.artifacts for downstream access,
12591264
# e.g. in lamindb.save_vitessce_config
12601265
if adata_artifact is not None:
@@ -1358,7 +1363,7 @@ def get_anndata_zarr(base_url):
13581363
options["refSpecUrl"] = self.get_ref_url(base_url, dataset_uid, obj_i)
13591364

13601365
obj_file_def = {
1361-
"fileType": ft.ANNDATA_ZARR.value if not self.is_h5ad else ft.ANNDATA_H5AD.value,
1366+
"fileType": ft.ANNDATA_ZIPPED_ZARR.value if self.is_zip else ft.ANNDATA_H5AD.value if self.is_h5ad else ft.ANNDATA_ZARR.value,
13621367
"url": self.get_zarr_url(base_url, dataset_uid, obj_i) if not self.is_h5ad else self.get_h5ad_url(base_url, dataset_uid, obj_i),
13631368
"options": options
13641369
}

tests/test_config.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,50 @@ def test_config_add_dataset():
7575
"initStrategy": "auto"
7676
}
7777

78+
def test_config_add_anndata_zip_url():
79+
vc = VitessceConfig(schema_version="1.0.15")
80+
vc.add_dataset(name='My Dataset').add_object(
81+
AnnDataWrapper(
82+
adata_url="http://example.com/adata.h5ad.zarr.zip",
83+
obs_set_paths=["obs/louvain"],
84+
)
85+
)
86+
87+
vc_dict = vc.to_dict()
88+
89+
assert vc_dict == {
90+
"version": "1.0.15",
91+
"name": "",
92+
"description": "",
93+
"datasets": [
94+
{
95+
'uid': 'A',
96+
'name': 'My Dataset',
97+
'files': [
98+
{
99+
"fileType": "anndata.zarr.zip",
100+
"url": "http://example.com/adata.h5ad.zarr.zip",
101+
"options": {
102+
"obsSets": [
103+
{
104+
"name": "louvain",
105+
"path": "obs/louvain",
106+
}
107+
]
108+
}
109+
}
110+
]
111+
}
112+
],
113+
'coordinationSpace': {
114+
'dataset': {
115+
'A': 'A'
116+
},
117+
},
118+
"layout": [],
119+
"initStrategy": "auto"
120+
}
121+
78122

79123
def test_config_add_anndata_url():
80124
vc = VitessceConfig(schema_version="1.0.15")

tests/test_wrappers.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,23 @@ def test_obs_segmentations_ome_zarr(self):
208208
'url': 'http://localhost:8000/A/0/test.ome.zarr'
209209
})
210210

211+
def test_anndata_with_zip(self):
212+
adata_path = data_path / 'test.h5ad.zarr.zip'
213+
w = AnnDataWrapper(adata_path,
214+
obs_set_paths=['obs/CellType'], obs_set_names=['Cell Type'],
215+
obs_labels_names=['Cell Label'], obs_labels_paths=['obs/CellLabel'],
216+
obs_embedding_paths=['obsm/X_umap'], obs_embedding_names=['UMAP'])
217+
w.local_dir_uid = 'anndata.zarr.zip'
218+
219+
file_def_creator = w.make_file_def_creator('A', 0)
220+
file_def = file_def_creator('http://localhost:8000')
221+
self.assertEqual(file_def, {'fileType': 'anndata.zarr.zip', 'url': 'http://localhost:8000/A/0/anndata.zarr.zip',
222+
'options': {
223+
'obsEmbedding': [{'path': 'obsm/X_umap', 'embeddingType': 'UMAP', 'dims': [0, 1]}],
224+
'obsSets': [{'path': 'obs/CellType', 'name': 'Cell Type'}],
225+
'obsLabels': [{'path': 'obs/CellLabel', 'obsLabelsType': 'Cell Label'}]
226+
}})
227+
211228
def test_anndata(self):
212229
adata_path = data_path / 'test.h5ad.zarr'
213230
w = AnnDataWrapper(adata_path,

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)