Vitessce integration
¶
For more comprehensive integration tests, see: laminlabs/lamin-spatial
!lamin login testuser1
!lamin init --storage "s3://lamindb-ci/test-vitessce"
→ logged in testuser1
! updating cloud SQLite 's3://lamindb-ci/test-vitessce/.lamindb/lamin.db' of instance 'testuser1/test-vitessce'
! locked instance (to unlock and push changes to the cloud SQLite file, call: lamin disconnect)
→ initialized lamindb: testuser1/test-vitessce
import lamindb as ln
import pytest
from vitessce import (
VitessceConfig,
AnnDataWrapper,
)
→ connected lamindb: testuser1/test-vitessce
/opt/hostedtoolcache/Python/3.14.6/x64/lib/python3.14/site-packages/vitessce/__init__.py:37: UserWarning: Extra installs are necessary to use widgets: No module named 'anywidget'
warn(f'Extra installs are necessary to use widgets: {e}')
/opt/hostedtoolcache/Python/3.14.6/x64/lib/python3.14/site-packages/vitessce/__init__.py:63: UserWarning: Extra installs are necessary to use exports: No module named 'starlette'
warn(f'Extra installs are necessary to use exports: {e}')
Set up test data:
pbmc68k = ln.examples.datasets.anndata_pbmc68k_reduced()[:100, :200].copy()
zarr_filepath = "my_test.zarr"
# write the anndata to a local zarr path
pbmc68k.write_zarr(zarr_filepath)
# create an artifact from the path
dataset_artifact = ln.Artifact(zarr_filepath, description="Test dataset").save()
# this is the where the zarr folder is located on a public S3 bucket
dataset_artifact.path.to_url()
! no run & transform got linked, call `ln.track()` & re-run
/opt/hostedtoolcache/Python/3.14.6/x64/lib/python3.14/site-packages/anndata/_io/zarr.py:44: UserWarning: Writing zarr v2 data will no longer be the default in the next minor release. v3 data will be written by default. If you are explicitly setting this configuration, consider migrating to the zarr v3 file format.
f = open_write_group(store)
'https://lamindb-ci.s3-us-west-1.amazonaws.com/test-vitessce/.lamindb/rD8iU6faIndg1biq.zarr'
Create a VitessceConfig object:
vc = VitessceConfig(schema_version="1.0.15")
vc.add_dataset(name="test1").add_object(
AnnDataWrapper(
adata_artifact=dataset_artifact,
obs_embedding_paths=["obsm/X_umap"],
),
)
vc.to_dict()
Show code cell output
{'version': '1.0.15',
'name': '',
'description': '',
'datasets': [{'uid': 'A',
'name': 'test1',
'files': [{'fileType': 'anndata.zarr',
'url': 'https://lamindb-ci.s3-us-west-1.amazonaws.com/test-vitessce/.lamindb/rD8iU6faIndg1biq.zarr',
'options': {'obsEmbedding': [{'path': 'obsm/X_umap',
'dims': [0, 1],
'embeddingType': 'X_umap'}]}}]}],
'coordinationSpace': {'dataset': {'A': 'A'}},
'layout': [],
'initStrategy': 'auto'}
vitessce_config_artifact = ln.integrations.save_vitessce_config(
vc, description="View testdata in Vitessce"
)
→ VitessceConfig references these artifacts:
Artifact(uid='rD8iU6faIndg1biq0000', key=None, description='Test dataset', suffix='.zarr', kind=None, otype='AnnData', size=209757, hash='qe4IpUWpZa2hv6zUVstHDw', n_files=129, n_observations=None, extra_data=None, branch_id=1, created_on_id=1, space_id=1, storage_id=1, run_id=None, schema_id=None, created_by_id=1, created_at=2026-06-22 07:42:26 UTC, is_locked=False, version_tag=None, is_latest=True)
→ VitessceConfig: https://lamin.ai/testuser1/test-vitessce/artifact/ACWsbzIvbkcXigAh0000
→ Dataset: https://lamin.ai/testuser1/test-vitessce/artifact/rD8iU6faIndg1biq0000
# different equivalent ways of testing that the action is attached
assert dataset_artifact._actions.get() == vitessce_config_artifact
assert vitessce_config_artifact._action_targets.get() == dataset_artifact
assert vitessce_config_artifact._actions.first() is None
assert vitessce_config_artifact.kind == "__lamindb_config__"
assert ln.Artifact.get(_actions=vitessce_config_artifact) == dataset_artifact
dataset_artifact.delete(permanent=True)
vitessce_config_artifact.delete(permanent=True)
→ deleting all versions of this artifact because they all share the same store
Test validation within save_vitessce_config:
# pass an artifact URL instead of the artifact object itself
vc = VitessceConfig(schema_version="1.0.15")
with pytest.raises(AttributeError) as error:
vc.add_dataset(name="test1").add_object(
AnnDataWrapper(
adata_artifact=dataset_artifact.path.to_url(),
obs_embedding_paths=["obsm/X_umap"],
),
)
print(error.exconly())
assert error.exconly().startswith(
"AttributeError: 'str' object has no attribute 'path'"
)
AttributeError: 'str' object has no attribute 'path'
!rm -rf test-vitessce
!lamin delete --force test-vitessce
→ deleted storage record on hub 62c8d91900dd5de9a05da1141a7659a8 | s3://lamindb-ci/test-vitessce
→ deleted instance record on hub d8e685232e9c545a89b3f5b869dc5a16