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.42.9 lamindb==0.71.0 scanpy==1.10.1
馃挕 saved: Transform(uid='zzJzdgJ763Dy6K79', name='Analyze the collection and save a result', key='facs4', version='0', type='notebook', updated_at=2024-05-01 18:53:44 UTC, created_by_id=1)
馃挕 saved: Run(uid='KobnPcvEDksHkySSan8m', transform_id=4, created_by_id=1)
ln.Collection.df()
uid name description version hash reference reference_type transform_id run_id artifact_id visibility created_at updated_at created_by_id
id
2 HTrdwbAlVOM0WX6aPw80 My versioned cytometry collection None 2 aIyjTZDm9LEyi4udLlQ- None None 2 2 None 1 2024-05-01 18:53:34.248736+00:00 2024-05-01 18:53:34.248760+00:00 1
1 HTrdwbAlVOM0WX6aNptu My versioned cytometry collection None 1 _SSVHoSL17yyiRlHc8Hr None None 1 1 None 1 2024-05-01 18:53:23.402360+00:00 2024-05-01 18:53:23.402386+00:00 1
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:1838: 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(['xRZvdCScS4EGAOaS8uak', 'TPjJBPzyNCizdD52cNIE'], 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/877564fba303f0546f6fc72d03757043da96aeccc56b42c7bb5c87a7a35b5f3e.png
artifact = ln.Artifact("./figures/pca_cd8.pdf", description="My result on CD8")

artifact.save()
Artifact(uid='EWywqiIAPBuLIeJbs7Vv', suffix='.pdf', description='My result on CD8', size=5622580, hash='3M-ppRjmxfCIGaIFq-QpjQ', hash_type='md5', visibility=1, key_is_virtual=True, updated_at=2024-05-01 18:54:02 UTC, storage_id=1, transform_id=4, run_id=4, created_by_id=1)
artifact.view_lineage()
_images/d16f2c374b3516e7bfec98937de36408790af34c71c801a38dcb8dcd1172c64d.svg

Given the image is part of the notebook, there isn鈥檛 an actual need to save it and you can also rely on the report that you鈥檒l create when saving the notebook via the command line via:

lamin save <notebook_path>
# 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 360, 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 140, 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 814, 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 4 objects ('./lamindb/_is_initialized'  ignored) - delete them prior to deleting the instance
['/home/runner/work/lamin-usecases/lamin-usecases/docs/test-facs/.lamindb/EWywqiIAPBuLIeJbs7Vv.pdf', '/home/runner/work/lamin-usecases/lamin-usecases/docs/test-facs/.lamindb/TPjJBPzyNCizdD52cNIE.h5ad', '/home/runner/work/lamin-usecases/lamin-usecases/docs/test-facs/.lamindb/_is_initialized', '/home/runner/work/lamin-usecases/lamin-usecases/docs/test-facs/.lamindb/xRZvdCScS4EGAOaS8uak.h5ad']
rm: cannot remove 'test-flow': No such file or directory