Skip to content

Commit

Permalink
Allow passing artifacts as data in addition to paths, urls, and zarr …
Browse files Browse the repository at this point in the history
…stores (#371)

* Register artifacts in wrapper constructors

* Docs

* Add test

* Update

* Version bump

* Lint

* Update is_remote logic

* Update
  • Loading branch information
keller-mark authored Oct 4, 2024
1 parent 6bac2c2 commit bc5e21c
Show file tree
Hide file tree
Showing 4 changed files with 197 additions and 35 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "vitessce"
version = "3.3.5"
version = "3.4.0"
authors = [
{ name="Mark Keller", email="mark_keller@hms.harvard.edu" },
]
Expand Down
63 changes: 63 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@
)


class MockArtifactPath:
def __init__(self, url):
self.url = url

def to_url(self):
return self.url


class MockArtifact:
def __init__(self, name, url):
self.name = name
self.path = MockArtifactPath(url)


def test_config_creation():
vc = VitessceConfig(schema_version="1.0.15")
vc_dict = vc.to_dict()
Expand Down Expand Up @@ -107,6 +121,55 @@ def test_config_add_anndata_url():
}


def test_config_add_anndata_artifact():
vc = VitessceConfig(schema_version="1.0.15")
vc.add_dataset(name='My Dataset').add_object(
AnnDataWrapper(
adata_artifact=MockArtifact("My anndata artifact", "http://example.com/adata.h5ad.zarr"),
obs_set_paths=["obs/louvain"],
)
)

vc_dict = vc.to_dict()

assert vc_dict == {
"version": "1.0.15",
"name": "",
"description": "",
"datasets": [
{
'uid': 'A',
'name': 'My Dataset',
'files': [
{
"fileType": "anndata.zarr",
"url": "http://example.com/adata.h5ad.zarr",
"options": {
"obsSets": [
{
"name": "louvain",
"path": "obs/louvain",
}
]
}
}
]
}
],
'coordinationSpace': {
'dataset': {
'A': 'A'
},
},
"layout": [],
"initStrategy": "auto"
}

vc_artifacts = vc.get_artifacts()
assert list(vc_artifacts.keys()) == ["http://example.com/adata.h5ad.zarr"]
assert vc_artifacts["http://example.com/adata.h5ad.zarr"].name == "My anndata artifact"


def test_config_add_dataset_add_files():
vc = VitessceConfig(schema_version="1.0.15")
vc.add_dataset(name='My Chained Dataset').add_file(
Expand Down
19 changes: 19 additions & 0 deletions vitessce/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,13 @@ def get_routes(self):

return routes

def get_artifacts(self):
artifacts = {}
for obj in self.objs:
artifacts.update(obj.get_artifacts())

return artifacts

def get_stores(self, base_url=None):
stores = {}
for obj in self.objs:
Expand Down Expand Up @@ -1590,6 +1597,18 @@ def get_routes(self):
routes += d.get_routes()
return routes

def get_artifacts(self):
"""
Get all artifacts for this view config from the datasets.
:returns: A dict mapping artifact URLs to corresponding artifact objects.
:rtype: dict[str, lamindb.Artifact]
"""
artifacts = {}
for d in self.config["datasets"]:
artifacts.update(d.get_artifacts())
return artifacts

def get_stores(self, base_url=None):
"""
Convert the routes for this view config from the datasets.
Expand Down
Loading

0 comments on commit bc5e21c

Please sign in to comment.