facs4/4 Jupyter Notebook lamindata

Analyze the collection and save a result

import lamindb as ln
import bionty as bt

ln.track("zzJzdgJ763Dy0000")
 connected lamindb: testuser1/test-facs
 created Transform('zzJzdgJ763Dy0000', key='facs4.ipynb'), started new Run('lpbLRD22zQ6A5qft') at 2026-01-27 17:33:57 UTC
 notebook imports: bionty==2.1.0 lamindb==2.0.1 scanpy==1.12
ln.Collection.to_dataframe()
Hide code cell output
uid key description hash reference reference_type version_tag is_latest is_locked created_at branch_id space_id created_by_id run_id meta_artifact_id
id
2 H8uYmr7T8vpS8FHG0001 My versioned cytometry collection None jgzEDgrAk78j6zH0DPB4GQ None None 2 True False 2026-01-27 17:33:49.515000+00:00 1 1 3 2 None
1 H8uYmr7T8vpS8FHG0000 My versioned cytometry collection None gKJFJJqKr0KQ6Q6EaoGrSA None None 1 False False 2026-01-27 17:33:40.215000+00:00 1 1 3 1 None
collection = ln.Collection.get(key="My versioned cytometry collection", version="2")
adata = collection.load(join="inner")
Hide code cell output
/opt/hostedtoolcache/Python/3.12.12/x64/lib/python3.12/site-packages/anndata/_core/anndata.py:1806: 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
Hide code cell output
Index(['kyLpa9ZqecVQP7xk0000', 'inC8ObNeKbrN9Ep20000'], dtype='object')

By default, the intersection of features is used:

adata.var.index
Hide code cell output
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")
Hide code cell output
WARNING: saving figure to file figures/pca_cd8.pdf
/tmp/ipykernel_3474/1861229803.py:4: FutureWarning: Argument `save` is deprecated and will be removed in a future version. Use `sc.pl.plot(show=False).figure.savefig()` instead.
  sc.pl.pca(adata, color=markers.cd8.name, save="_cd8")
_images/22f8bb4fe8991b58503cbe11c329eb88fa57fea06a384754d29ca77ae59e9123.png
artifact = ln.Artifact("./figures/pca_cd8.pdf", description="My result on CD8").save()
artifact.view_lineage()
_images/0f6f01b2439990607bcb8c2752a9ae08fe0ee20bcb643afa051b9c8274a2bb2a.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
!rm -r test-flow
!lamin delete --force test-facs
Hide code cell output
rm: cannot remove 'test-flow': No such file or directory
╭─ Error ──────────────────────────────────────────────────────────────────────╮
 '/home/runner/work/lamin-usecases/lamin-usecases/docs/test-facs/.lamindb'    
 contains 3 objects:                                                          
 /home/runner/work/lamin-usecases/lamin-usecases/docs/test-facs/.lamindb/01Dq 
 OghLAafRhwuj0000.pdf                                                         
 /home/runner/work/lamin-usecases/lamin-usecases/docs/test-facs/.lamindb/inC8 
 ObNeKbrN9Ep20000.h5ad                                                        
 /home/runner/work/lamin-usecases/lamin-usecases/docs/test-facs/.lamindb/kyLp 
 a9ZqecVQP7xk0000.h5ad                                                        
 delete them prior to deleting the storage location                           
╰──────────────────────────────────────────────────────────────────────────────╯