facs4/4 Jupyter Notebook lamindata

Analyze the dataset and save a result#

import lamindb as ln
import lnschema_bionty as lb

ln.track()
💡 lamindb instance: testuser1/test-facs
💡 notebook imports: lamindb==0.63.2 lnschema_bionty==0.35.3 scanpy==1.9.6
💡 saved: Transform(uid='zzJzdgJ763Dyz8', name='Analyze the dataset and save a result', short_name='facs4', version='0', type=notebook, updated_at=2023-12-04 19:37:08 UTC, created_by_id=1)
💡 saved: Run(uid='1iS3PNGIcf9LUekxrozH', run_at=2023-12-04 19:37:08 UTC, transform_id=4, created_by_id=1)
ln.Dataset.filter().df()
uid name description version hash reference reference_type transform_id run_id file_id storage_id initial_version_id visibility updated_at created_by_id
id
1 EO3P6z394MZPW1UtXKvt My versioned cytometry dataset None 1 VsTnnzHN63ovNESaJtlRUQ None None 1 1 1.0 None NaN 1 2023-12-04 19:36:46.866029+00:00 1
2 ic5pZyKhYa79yBJiFjgw My versioned cytometry dataset None 2 ZKQxIw0uAvtMtdZk8SAj None None 2 2 NaN None 1.0 1 2023-12-04 19:36:58.262127+00:00 1
dataset = ln.Dataset.filter(name="My versioned cytometry dataset", version="2").one()
adata = dataset.load(join="inner")
/opt/hostedtoolcache/Python/3.9.18/x64/lib/python3.9/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.file_uid.cat.categories
Index(['EO3P6z394MZPW1UtXKvt', 'acyZj25tVSGpsvj9x1sh'], dtype='object')

By default, the intersection of features is used:

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

Let us create a plot:

markers = lb.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/5abb442bcc93fdb2686ec6699b65fbfd135750988d753f2514c497f9765a37d9.png
file = ln.File("./figures/pca_cd8.pdf", description="My result on CD8")

file.save()
file.view_flow()
_images/f248817498f4d42a2ca058057d3771de9deb6b2f3898cbdff7cd3fec23550169.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