facs4/4 Jupyter Notebook lamindata

Analyze the collection and save a result#

import lamindb as ln
import bionty as bt

ln.track()
💡 lamindb instance: testuser1/test-facs
💡 notebook imports: bionty==0.40.3 lamindb==0.67.3 scanpy==1.9.8
💡 saved: Transform(uid='zzJzdgJ763Dy6K79', name='Analyze the collection and save a result', short_name='facs4', version='0', type=notebook, updated_at=2024-02-17 11:22:40 UTC, created_by_id=1)
💡 saved: Run(uid='ELjt5NSma5VbsHlulotb', run_at=2024-02-17 11:22:40 UTC, 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 xOHAsmxOu7Xpatte39OM My versioned cytometry collection None 2 ZKQxIw0uAvtMtdZk8SAj None None 2 2 NaN 1 2024-02-17 11:22:30.104938+00:00 2024-02-17 11:22:30.104960+00:00 1
1 xOHAsmxOu7Xpattes5Jz My versioned cytometry collection None 1 VsTnnzHN63ovNESaJtlRUQ None None 1 1 1.0 1 2024-02-17 11:22:19.061865+00:00 2024-02-17 11:22:19.061885+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.13/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(['4zxS952PixDPpHNWhCwO', 'xOHAsmxOu7Xpattes5Jz'], 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/03bf57094d963c5119fe35935c04234895cfdc7e2bdfd14d15d67a3e0bacba36.png
artifact = ln.Artifact("./figures/pca_cd8.pdf", description="My result on CD8")

artifact.save()
artifact.view_lineage()
_images/cd3da5521599813f99117233b1db15ef35a15f31b386781b0f5976c7557c9633.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 via the command line via:

lamin save <notebook_path>
# clean up test instance
!lamin delete --force test-facs
!rm -r test-flow
💡 deleting instance testuser1/test-facs
✅     deleted instance settings file: /home/runner/.lamin/instance--testuser1--test-facs.env
✅     instance cache deleted
✅     deleted '.lndb' sqlite file
❗     consider manually deleting your stored data: /home/runner/work/lamin-usecases/lamin-usecases/docs/test-facs
rm: cannot remove 'test-flow': No such file or directory