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'
! 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.10.16/x64/lib/python3.10/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.10.16/x64/lib/python3.10/site-packages/vitessce/__init__.py:68: 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/j9FruzeY7zxwkgbP.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/j9FruzeY7zxwkgbP.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='j9FruzeY7zxwkgbP0000', is_latest=True, description='Test dataset', suffix='.zarr', otype='AnnData', size=185899, hash='LjIw9T99EBlrxvFNjwyauQ', n_files=128, space_id=1, storage_id=1, created_by_id=1, created_at=2025-01-12 14:04:53 UTC)
 VitessceConfig: https://lamin.ai/testuser1/test-vitessce/artifact/e7cCrnIt9XtW7nIK0000
 Dataset: https://lamin.ai/testuser1/test-vitessce/artifact/j9FruzeY7zxwkgbP0000
# 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