Query & analyze#
import lamindb as ln
import lnschema_bionty as lb
lb.settings.species = "human"
💡 loaded instance: testuser1/test-flow (lamindb 0.54.1)
ln.track()
💡 notebook imports: anndata==0.9.2 lamindb==0.54.1 lnschema_bionty==0.31.2 scanpy==1.9.5
💡 Transform(id='wukchS8V976Uz8', name='Query & analyze', short_name='facs2', version='0', type=notebook, updated_at=2023-09-22 18:45:48, created_by_id='DzTjkKse')
💡 Run(id='7av9RFYVfawKjJFsXBDv', run_at=2023-09-22 18:45:48, transform_id='wukchS8V976Uz8', created_by_id='DzTjkKse')
Inspect the CellMarker registry #
Inspect your aggregated cell marker registry:
lb.CellMarker.filter().df()
name | synonyms | gene_symbol | ncbi_gene_id | uniprotkb_id | species_id | bionty_source_id | updated_at | created_by_id | |
---|---|---|---|---|---|---|---|---|---|
id | |||||||||
k0zGbSgZEX3q | HLADR | HLA‐DR|HLA-DR|HLA DR | None | None | None | uHJU | vwab | 2023-09-22 18:45:32 | DzTjkKse |
sYcK7uoWCtco | Ccr7 | CCR7 | 1236 | P32248 | uHJU | vwab | 2023-09-22 18:45:32 | DzTjkKse | |
fpPkjlGv15C9 | Ccr6 | CCR6 | 1235 | P51684 | uHJU | vwab | 2023-09-22 18:45:32 | DzTjkKse | |
0vAls2cmLKWq | ICOS | ICOS | 29851 | Q53QY6 | uHJU | vwab | 2023-09-22 18:45:32 | DzTjkKse | |
4uiPHmCPV5i1 | CXCR5 | CXCR5 | 643 | A0N0R2 | uHJU | vwab | 2023-09-22 18:45:32 | DzTjkKse | |
0qCmUijBeByY | CD94 | KLRD1 | 3824 | Q13241 | uHJU | vwab | 2023-09-22 18:45:32 | DzTjkKse | |
a624IeIqbchl | CD45RA | None | None | None | uHJU | vwab | 2023-09-22 18:45:32 | DzTjkKse | |
ljp5UfCF9HCi | TCRgd | TCRGAMMADELTA|TCRγδ | None | None | None | uHJU | vwab | 2023-09-22 18:45:32 | DzTjkKse |
lRZYuH929QDw | CD85j | None | None | None | uHJU | vwab | 2023-09-22 18:45:32 | DzTjkKse | |
8OhpfB7wwV32 | Cd19 | CD19 | 930 | P15391 | uHJU | vwab | 2023-09-22 18:45:32 | DzTjkKse | |
a4hvNp34IYP0 | CD3 | None | None | None | uHJU | vwab | 2023-09-22 18:45:32 | DzTjkKse | |
0evamYEdmaoY | Igd | None | None | None | uHJU | vwab | 2023-09-22 18:45:32 | DzTjkKse | |
agQD0dEzuoNA | CXCR3 | CXCR3 | 2833 | P49682 | uHJU | vwab | 2023-09-22 18:45:32 | DzTjkKse | |
h4rkCALR5WfU | CD56 | NCAM1 | 4684 | P13591 | uHJU | vwab | 2023-09-22 18:45:32 | DzTjkKse | |
L0WKZ3fufq0J | CD11c | ITGAX | 3687 | P20702 | uHJU | vwab | 2023-09-22 18:45:32 | DzTjkKse | |
roEbL8zuLC5k | Cd14 | CD14 | 4695 | O43678 | uHJU | vwab | 2023-09-22 18:45:32 | DzTjkKse | |
CLFUvJpioHoA | CD28 | CD28 | 940 | B4E0L1 | uHJU | vwab | 2023-09-22 18:45:32 | DzTjkKse | |
n40112OuX7Cq | CD123 | IL3RA | 3563 | P26951 | uHJU | vwab | 2023-09-22 18:45:32 | DzTjkKse | |
2VeZenLi2dj5 | PD1 | PID1|PD-1|PD 1 | PDCD1 | 5133 | A0A0M3M0G7 | uHJU | vwab | 2023-09-22 18:45:32 | DzTjkKse |
L0m6f7FPiDeg | CD86 | CD86 | 942 | A8K632 | uHJU | vwab | 2023-09-22 18:45:32 | DzTjkKse | |
N2F6Qv9CxJch | CD11B | ITGAM | 3684 | P11215 | uHJU | vwab | 2023-09-22 18:45:32 | DzTjkKse | |
Nb2sscq9cBcB | CD57 | B3GAT1 | 27087 | Q9P2W7 | uHJU | vwab | 2023-09-22 18:45:32 | DzTjkKse | |
CR7DAHxybgyi | CD38 | CD38 | 952 | B4E006 | uHJU | vwab | 2023-09-22 18:45:32 | DzTjkKse | |
c3dZKHFOdllB | CD33 | CD33 | 945 | P20138 | uHJU | vwab | 2023-09-22 18:45:32 | DzTjkKse | |
YA5Ezh6SAy10 | DNA1 | None | None | None | uHJU | vwab | 2023-09-22 18:45:32 | DzTjkKse | |
bspnQ0igku6c | CD16 | FCGR3A | 2215 | O75015 | uHJU | vwab | 2023-09-22 18:45:32 | DzTjkKse | |
cFJEI6e6wml3 | CD20 | MS4A1 | 931 | A0A024R507 | uHJU | vwab | 2023-09-22 18:45:32 | DzTjkKse | |
yCyTIVxZkIUz | DNA2 | DNA2 | 1763 | P51530 | uHJU | vwab | 2023-09-22 18:45:32 | DzTjkKse | |
ttBc0Fs01sYk | CD8 | CD8A | 925 | P01732 | uHJU | vwab | 2023-09-22 18:45:32 | DzTjkKse | |
hVNEgxlcDV10 | CD127 | IL7R | 3575 | P16871 | uHJU | vwab | 2023-09-22 18:45:32 | DzTjkKse | |
gEfe8qTsIHl0 | CD24 | CD24 | 100133941 | B6EC88 | uHJU | vwab | 2023-09-22 18:45:32 | DzTjkKse | |
HEK41hvaIazP | Cd4 | CD4 | 920 | B4DT49 | uHJU | vwab | 2023-09-22 18:45:32 | DzTjkKse | |
4EojtgN0CjBH | CD161 | KLRB1 | 3820 | Q12918 | uHJU | vwab | 2023-09-22 18:45:32 | DzTjkKse | |
uThe3c0V3d4i | CD27 | CD27 | 939 | P26842 | uHJU | vwab | 2023-09-22 18:45:32 | DzTjkKse | |
50v4SaR2m5zQ | CD25 | IL2RA | 3559 | P01589 | uHJU | vwab | 2023-09-22 18:45:32 | DzTjkKse | |
XvpJ6oL3SG7w | CD45RO | None | None | None | uHJU | vwab | 2023-09-22 18:45:44 | DzTjkKse | |
Qa4ozz9tyesQ | Ki67 | Ki-67|KI 67 | None | None | None | uHJU | vwab | 2023-09-22 18:45:44 | DzTjkKse |
UMsp5g0fgMwY | CCR5 | CCR5 | 1234 | P51681 | uHJU | vwab | 2023-09-22 18:45:44 | DzTjkKse |
Search for a marker (synonyms aware):
lb.CellMarker.search("PD-1").head(2)
id | synonyms | __ratio__ | |
---|---|---|---|
name | |||
PD1 | 2VeZenLi2dj5 | PID1|PD-1|PD 1 | 100.0 |
Cd14 | roEbL8zuLC5k | 50.0 |
Look up markers with auto-complete:
markers = lb.CellMarker.lookup()
markers.cd14
CellMarker(id='roEbL8zuLC5k', name='Cd14', synonyms='', gene_symbol='CD14', ncbi_gene_id='4695', uniprotkb_id='O43678', updated_at=2023-09-22 18:45:32, species_id='uHJU', bionty_source_id='vwab', created_by_id='DzTjkKse')
Query files by markers #
Query panels and datasets based on markers, e.g., which datasets have 'CD14'
in the flow panel:
panels_with_cd14 = ln.FeatureSet.filter(cell_markers=markers.cd14).all()
ln.File.filter(feature_sets__in=panels_with_cd14).df()
storage_id | key | suffix | accessor | description | version | size | hash | hash_type | transform_id | run_id | initial_version_id | updated_at | created_by_id | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id | ||||||||||||||
CvTtSi7dfBfI3a9sOoc4 | 6o0SZiBV | None | .h5ad | AnnData | Flow cytometry file 2 | None | 6837528 | t6plg-pXZMxqmQN9naNeuw | md5 | SmQmhrhigFPLz8 | sdkqkslifGqV4CQWCsZ9 | None | 2023-09-22 18:45:44 | DzTjkKse |
bvBHOP5XnqkGPvDRmQlk | 6o0SZiBV | None | .h5ad | AnnData | Alpert19 | None | 33369696 | Piw2n0vdnoNoAV7ZxgsW-g | md5 | OWuTtS4SAponz8 | ZigRiMxLUv91mJc88S2a | None | 2023-09-22 18:45:36 | DzTjkKse |
Access registries:
features = ln.Feature.lookup()
efs = lb.ExperimentalFactor.lookup()
species = lb.Species.lookup()
Find shared cell markers between two files:
files = ln.File.filter(feature_sets__in=panels_with_cd14, species=species.human).list()
file1, file2 = files[0], files[1]
shared_markers = file1.features["var"] & file2.features["var"]
shared_markers.list("name")
['CD28', 'CD3', 'Cd19', 'CD127', 'CD27', 'Ccr7', 'Cd14', 'Cd4', 'CD8', 'CD57']
Load files into memory and concatenate:
adata1 = file1.load()
adata2 = file2.load()
import anndata as ad
adata = ad.concat(
[adata1, adata2],
label="file",
keys=[file1.description, file2.description],
)
adata
/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")
AnnData object with n_obs × n_vars = 231130 × 10
obs: 'file'
import scanpy as sc
sc.pp.pca(adata)
sc.pl.pca(adata, color=markers.cd14.name)
Create a concatenated dataset#
dataset = ln.Dataset(adata, name="Aggregated dataset")
dataset.save()
dataset.view_flow()
# clean up test instance
!lamin delete --force test-flow
!rm -r test-flow
💡 deleting instance testuser1/test-flow
✅ deleted instance settings file: /home/runner/.lamin/instance--testuser1--test-flow.env
✅ instance cache deleted
✅ deleted '.lndb' sqlite file
❗ consider manually deleting your stored data: /home/runner/work/lamin-usecases/lamin-usecases/docs/test-flow