Vitessce integration

For more comprehensive integration tests, see: https://github.com/laminlabs/lamin-spatial

!lamin login testuser1
!lamin init --storage "s3://lamindb-ci/test-vitessce"
✓ logged in with email testuser1@lamin.ai (uid: DzTjkKse)
→ go to: https://lamin.ai/testuser1/test-vitessce
! updating cloud SQLite 's3://lamindb-ci/test-vitessce/d8e685232e9c545a89b3f5b869dc5a16.lndb' of instance 'testuser1/test-vitessce'
→ connected lamindb: testuser1/test-vitessce
! locked instance (to unlock and push changes to the cloud SQLite file, call: lamin disconnect)
import lamindb as ln
import pytest
from vitessce import (
    VitessceConfig,
    Component as cm,
    AnnDataWrapper,
)
→ connected lamindb: testuser1/test-vitessce
/opt/hostedtoolcache/Python/3.9.20/x64/lib/python3.9/site-packages/vitessce/__init__.py:42: 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.9.20/x64/lib/python3.9/site-packages/vitessce/__init__.py:67: 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.core.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
'https://lamindb-ci.s3-us-west-1.amazonaws.com/test-vitessce/.lamindb/c748vcZrgomQrDw5.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()
Hide 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/c748vcZrgomQrDw5.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='c748vcZrgomQrDw50000', is_latest=True, description='Test dataset', suffix='.zarr', size=185899, hash='LjIw9T99EBlrxvFNjwyauQ', n_objects=128, _hash_type='md5-d', _accessor='AnnData', visibility=1, _key_is_virtual=True, storage_id=1, created_by_id=1, created_at=2024-10-18 15:58:42 UTC)
→ VitessceConfig: https://lamin.ai/testuser1/test-vitessce/artifact/YJxIT3RUpZ5azK8b0000
→ Dataset: https://lamin.ai/testuser1/test-vitessce/artifact/c748vcZrgomQrDw50000
# 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 ln.Artifact.get(_actions=vitessce_config_artifact) == dataset_artifact
dataset_artifact.delete(permanent=True)
vitessce_config_artifact.delete(permanent=True)

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
• deleting instance testuser1/test-vitessce
→ deleted storage record on hub 62c8d91900dd5de9a05da1141a7659a8
→ deleted instance record on hub d8e685232e9c545a89b3f5b869dc5a16