facs4/4 Jupyter Notebook lamindata

Analyze the collection and save a result

import lamindb as ln
import bionty as bt

ln.settings.transform.stem_uid = "zzJzdgJ763Dy"
ln.settings.transform.version = "0"
ln.track()
💡 connected lamindb: testuser1/test-facs
💡 notebook imports: bionty==0.44.0 lamindb==0.74.1 scanpy==1.10.2
💡 saved: Transform(uid='zzJzdgJ763Dy6K79', version='0', name='Analyze the collection and save a result', key='facs4', type='notebook', created_by_id=1, updated_at='2024-07-01 13:59:08 UTC')
💡 saved: Run(uid='PfrnFv5RCiiOp8srU5MO', transform_id=4, created_by_id=1)
Run(uid='PfrnFv5RCiiOp8srU5MO', started_at='2024-07-01 13:59:08 UTC', is_consecutive=True, transform_id=4, created_by_id=1)
ln.Collection.df()
uid version name description hash reference reference_type visibility transform_id artifact_id run_id created_by_id updated_at
id
2 eeJY9esbPxC8ldIvt9Yw 2 My versioned cytometry collection None aIyjTZDm9LEyi4udLlQ- None None 1 2 None 2 1 2024-07-01 13:58:59.166326+00:00
1 eeJY9esbPxC8ldIvCBiV 1 My versioned cytometry collection None _SSVHoSL17yyiRlHc8Hr None None 1 1 None 1 1 2024-07-01 13:58:49.269545+00:00
collection = ln.Collection.filter(
    name="My versioned cytometry collection", version="2"
).one()
adata = collection.load(join="inner")
/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/anndata/_core/anndata.py:1818: UserWarning: Observation names are not unique. To make them unique, call `.obs_names_make_unique`.
  utils.warn_names_duplicates("obs")

The AnnData has the reference to the individual files in the .obs annotations:

adata.obs.artifact_uid.cat.categories
Index(['mk6q3qCTNYXBVz0vaqcz', '6iPyp7YLY9fnKHWtXcks'], dtype='object')

By default, the intersection of features is used:

adata.var.index
Index(['CD8', 'CD27', 'Ccr7', 'Cd4', 'CD45RA', 'CD3'], dtype='object')

Let us create a plot:

markers = bt.CellMarker.lookup()
import scanpy as sc

sc.pp.pca(adata)
sc.pl.pca(adata, color=markers.cd8.name, save="_cd8")
WARNING: saving figure to file figures/pca_cd8.pdf
_images/8df70fef4cbf2383ba4f646fa76145c60de234695fe1e799323c1c30904ed880.png
artifact = ln.Artifact("./figures/pca_cd8.pdf", description="My result on CD8").save()
artifact.view_lineage()
_images/5e7e0dda04db5f96f64b1249866bcb75b61ffcc94f9d8699350aa6dc4aec4299.svg

Given the image is part of the notebook, there isn’t an actual need to save it and you can also rely on the report that you’ll create when saving the notebook:

ln.finish()
# clean up test instance
!lamin delete --force test-facs
!rm -r test-flow
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.10.14/x64/bin/lamin", line 8, in <module>
    sys.exit(main())
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/rich_click/rich_command.py", line 367, in __call__
    return super().__call__(*args, **kwargs)
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/rich_click/rich_command.py", line 152, in main
    rv = self.invoke(ctx)
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/lamin_cli/__main__.py", line 103, in delete
    return delete(instance, force=force)
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/lamindb_setup/_delete.py", line 98, in delete
    n_objects = check_storage_is_empty(
  File "/opt/hostedtoolcache/Python/3.10.14/x64/lib/python3.10/site-packages/lamindb_setup/core/upath.py", line 779, in check_storage_is_empty
    raise InstanceNotEmpty(message)
lamindb_setup.core.upath.InstanceNotEmpty: Storage /home/runner/work/lamin-usecases/lamin-usecases/docs/test-facs/.lamindb contains 3 objects ('_is_initialized' ignored) - delete them prior to deleting the instance
['/home/runner/work/lamin-usecases/lamin-usecases/docs/test-facs/.lamindb/6iPyp7YLY9fnKHWtXcks.h5ad', '/home/runner/work/lamin-usecases/lamin-usecases/docs/test-facs/.lamindb/7ZlKzyskfgBTxdN8jnQn.pdf', '/home/runner/work/lamin-usecases/lamin-usecases/docs/test-facs/.lamindb/_is_initialized', '/home/runner/work/lamin-usecases/lamin-usecases/docs/test-facs/.lamindb/mk6q3qCTNYXBVz0vaqcz.h5ad']
rm: cannot remove 'test-flow': No such file or directory