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)
! the database (0.76.15) is behind your installed lamindb package (0.77.0)
→ consider migrating your database: lamin migrate deploy
! updating local SQLite & locking cloud SQLite (sync back & unlock: lamin disconnect)
→ connected lamindb: testuser1/test-vitessce
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: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/UiWeyYL7NviJ6SdI.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/UiWeyYL7NviJ6SdI.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='UiWeyYL7NviJ6SdI0000', 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-11-25 06:34:06 UTC)
→ VitessceConfig: https://lamin.ai/testuser1/test-vitessce/artifact/oh1RXIUQ9kkGlPIm0000
→ Dataset: https://lamin.ai/testuser1/test-vitessce/artifact/UiWeyYL7NviJ6SdI0000
# 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
! the database (0.76.15) is behind your installed lamindb package (0.77.0)
→ consider migrating your database: lamin migrate deploy
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.9.20/x64/bin/lamin", line 8, in <module>
    sys.exit(main())
  File "/opt/hostedtoolcache/Python/3.9.20/x64/lib/python3.9/site-packages/rich_click/rich_command.py", line 367, in __call__
    return super().__call__(*args, **kwargs)
  File "/opt/hostedtoolcache/Python/3.9.20/x64/lib/python3.9/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/opt/hostedtoolcache/Python/3.9.20/x64/lib/python3.9/site-packages/rich_click/rich_command.py", line 152, in main
    rv = self.invoke(ctx)
  File "/opt/hostedtoolcache/Python/3.9.20/x64/lib/python3.9/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/opt/hostedtoolcache/Python/3.9.20/x64/lib/python3.9/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/opt/hostedtoolcache/Python/3.9.20/x64/lib/python3.9/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/opt/hostedtoolcache/Python/3.9.20/x64/lib/python3.9/site-packages/lamin_cli/__main__.py", line 209, in delete
    return delete(instance, force=force)
  File "/opt/hostedtoolcache/Python/3.9.20/x64/lib/python3.9/site-packages/lamindb_setup/_delete.py", line 102, in delete
    n_objects = check_storage_is_empty(
  File "/opt/hostedtoolcache/Python/3.9.20/x64/lib/python3.9/site-packages/lamindb_setup/core/upath.py", line 826, in check_storage_is_empty
    raise InstanceNotEmpty(message)
lamindb_setup.core.upath.InstanceNotEmpty: Storage 's3://lamindb-ci/test-vitessce/.lamindb' contains 128 objects - delete them prior to deleting the instance