scrna3/6 Jupyter Notebook lamindata

Query artifacts#

Here, we鈥檒l query artifacts and inspect their metadata.

This guide can be skipped if you are only interested in how to leverage the overall collection.

import lamindb as ln
import bionty as bt
馃挕 connected lamindb: testuser1/test-scrna
ln.settings.transform.stem_uid = "agayZTonayqA"
ln.settings.transform.version = "1"
ln.track()
馃挕 notebook imports: bionty==0.42.9 lamindb==0.71.0
馃挕 saved: Transform(uid='agayZTonayqA5zKv', name='Query artifacts', key='scrna3', version='1', type='notebook', updated_at=2024-05-01 18:52:10 UTC, created_by_id=1)
馃挕 saved: Run(uid='qYhpmileyPNnpJzHjZJU', transform_id=3, created_by_id=1)

Query artifacts by provenance metadata#

users = ln.User.lookup()
ln.Transform.filter(created_by=users.testuser1).search("scrna")
uid score
name
scRNA-seq Nv48yAceNSh85zKv 90.0
Standardize and append a batch of data ManDYgmftZ8C5zKv 45.0
Query artifacts agayZTonayqA5zKv 36.0
transform = ln.Transform.filter(uid="Nv48yAceNSh85zKv").one()
ln.Artifact.filter(transform=transform).df()
uid storage_id key suffix accessor description version size hash hash_type n_objects n_observations transform_id run_id visibility key_is_virtual created_at updated_at created_by_id
id
1 V9W98oInfXKLfLbFMu3X 1 None .h5ad AnnData Human immune cells from Conde22 None 57612943 9sXda5E7BYiVoDOQkTC0KB sha1-fl None 1648 1 1 1 True 2024-05-01 18:51:32.352027+00:00 2024-05-01 18:51:35.891084+00:00 1

Query artifacts by biological metadata#

organism = bt.Organism.lookup()
tissues = bt.Tissue.lookup()
query = ln.Artifact.filter(
    organism=organism.human,
    tissues=tissues.bone_marrow,
)
query.df()
uid key suffix accessor description version size hash hash_type n_objects n_observations visibility key_is_virtual created_at updated_at storage_id transform_id run_id created_by_id
id

Inspect artifact metadata#

query_set = ln.Artifact.filter().all()

artifact1, artifact2 = query_set[0], query_set[1]
artifact1.describe()
Artifact(uid='V9W98oInfXKLfLbFMu3X', suffix='.h5ad', accessor='AnnData', description='Human immune cells from Conde22', size=57612943, hash='9sXda5E7BYiVoDOQkTC0KB', hash_type='sha1-fl', n_observations=1648, visibility=1, key_is_virtual=True, updated_at=2024-05-01 18:51:35 UTC)

Provenance:
  馃搸 storage: Storage(uid='PG7LAtZPUQAO', root='/home/runner/work/lamin-usecases/lamin-usecases/docs/test-scrna', type='local', instance_uid='5ZP9QR2HPILj')
  馃搸 transform: Transform(uid='Nv48yAceNSh85zKv', name='scRNA-seq', key='scrna', version='1', type='notebook')
  馃搸 run: Run(uid='576RCqKj0I54MWSZIMUs', started_at=2024-05-01 18:49:39 UTC, is_consecutive=True)
  馃搸 created_by: User(uid='DzTjkKse', handle='testuser1', name='Test User1')
  馃搸 input_of (core.Run): ['2024-05-01 18:51:43 UTC']
Features:
  var: FeatureSet(uid='bEMqtuZxE3XcWVnXY4hD', n=36503, type='number', registry='bionty.Gene')
    'NPTXR', 'WEE2-AS1', 'BUD31', 'C1QTNF1-AS1', 'UQCRFS1-DT', 'HMMR-AS1', 'RASGRP4', 'UBE2E2-DT', 'ZNF304', 'LAMB1', 'ELP5', 'LRRC2', 'IRS4', 'CHST1', 'OR10A7', 'POLR3A', 'TP53INP2', 'TMEM79', 'TNFSF11', 'IL27', ...
  obs: FeatureSet(uid='fBDpr3Aj5v5RJU80kIei', n=4, registry='core.Feature')
    馃敆 donor (12, core.ULabel): 'A36', 'D503', 'D496', '582C', 'A31', '637C', '640C', '621B', 'A52', 'A35', ...
    馃敆 tissue (17, bionty.Tissue): 'thymus', 'sigmoid colon', 'lung', 'omentum', 'bone marrow', 'ileum', 'duodenum', 'blood', 'lamina propria', 'jejunal epithelium', ...
    馃敆 cell_type (32, bionty.CellType): 'animal cell', 'plasmacytoid dendritic cell', 'alveolar macrophage', 'megakaryocyte', 'CD16-negative, CD56-bright natural killer cell, human', 'effector memory CD4-positive, alpha-beta T cell', 'progenitor cell', 'group 3 innate lymphoid cell', 'T follicular helper cell', 'gamma-delta T cell', ...
    馃敆 assay (3, bionty.ExperimentalFactor): '10x 3' v3', '10x 5' v2', '10x 5' v1'
Labels:
  馃搸 tissues (17, bionty.Tissue): 'thymus', 'sigmoid colon', 'lung', 'omentum', 'bone marrow', 'ileum', 'duodenum', 'blood', 'lamina propria', 'jejunal epithelium', ...
  馃搸 cell_types (32, bionty.CellType): 'animal cell', 'plasmacytoid dendritic cell', 'alveolar macrophage', 'megakaryocyte', 'CD16-negative, CD56-bright natural killer cell, human', 'effector memory CD4-positive, alpha-beta T cell', 'progenitor cell', 'group 3 innate lymphoid cell', 'T follicular helper cell', 'gamma-delta T cell', ...
  馃搸 experimental_factors (3, bionty.ExperimentalFactor): '10x 3' v3', '10x 5' v2', '10x 5' v1'
  馃搸 ulabels (12, core.ULabel): 'A36', 'D503', 'D496', '582C', 'A31', '637C', '640C', '621B', 'A52', 'A35', ...
artifact1.view_lineage()
_images/c72516c759ba7e5f469b0d1a30b35ef157cf8a0db6ef1b3d370c12268ffe0e1e.svg
artifact2.describe()
Artifact(uid='2zYWzCjkNwbeOcCleuyR', suffix='.h5ad', accessor='AnnData', description='10x reference adata', size=857752, hash='0Fozmib89XWbFoD6hSq5yA', hash_type='md5', n_observations=70, visibility=1, key_is_virtual=True, updated_at=2024-05-01 18:52:02 UTC)

Provenance:
  馃搸 storage: Storage(uid='PG7LAtZPUQAO', root='/home/runner/work/lamin-usecases/lamin-usecases/docs/test-scrna', type='local', instance_uid='5ZP9QR2HPILj')
  馃搸 transform: Transform(uid='ManDYgmftZ8C5zKv', name='Standardize and append a batch of data', key='scrna2', version='1', type='notebook')
  馃搸 run: Run(uid='bKXzQTJlj2eaUJ6VNVhE', started_at=2024-05-01 18:51:43 UTC, is_consecutive=True)
  馃搸 created_by: User(uid='DzTjkKse', handle='testuser1', name='Test User1')
Features:
  var: FeatureSet(uid='sDZZmuIad3xWV8RPfggU', n=754, type='number', registry='bionty.Gene')
    'FTL', 'LGALS3', 'CYB561A3', 'AKR1C3', 'CCDC115', 'ZNHIT1', 'RAB7A', 'IFITM3', 'LDHA', 'BAD', 'CST3', 'TTC39C', 'CCNI', 'ZNF706', 'CD4', 'PIK3IP1', 'U2AF1L4', 'RABAC1', 'CD8B', 'TSC22D1', ...
  obs: FeatureSet(uid='zcky6bvQ7pzMebqPXkXa', n=1, registry='core.Feature')
    馃敆 cell_type (9, bionty.CellType): 'CD16-positive, CD56-dim natural killer cell, human', 'CD38-positive naive B cell', 'B cell, CD19-positive', 'CD14-positive, CD16-negative classical monocyte', 'dendritic cell', 'cytotoxic T cell', 'CD8-positive, CD25-positive, alpha-beta regulatory T cell', 'effector memory CD4-positive, alpha-beta T cell, terminally differentiated', 'CD4-positive, alpha-beta T cell'
Labels:
  馃搸 cell_types (9, bionty.CellType): 'CD16-positive, CD56-dim natural killer cell, human', 'CD38-positive naive B cell', 'B cell, CD19-positive', 'CD14-positive, CD16-negative classical monocyte', 'dendritic cell', 'cytotoxic T cell', 'CD8-positive, CD25-positive, alpha-beta regulatory T cell', 'effector memory CD4-positive, alpha-beta T cell, terminally differentiated', 'CD4-positive, alpha-beta T cell'
artifact2.view_lineage()
_images/f06bf5531448552bbb1cb67b040ab5067ecfe4e0b5d76e53a75ff57588055d30.svg

Compare features#

Here we compute shared genes:

artifact1_genes = artifact1.features["var"]
artifact2_genes = artifact2.features["var"]

shared_genes = artifact1_genes & artifact2_genes
len(shared_genes)
749
shared_genes.list("symbol")[:10]
['HES4',
 'TNFRSF4',
 'SSU72',
 'PARK7',
 'RBP7',
 'SRM',
 'MAD2L2',
 'AGTRAP',
 'TNFRSF1B',
 'EFHD2']

Compare cell types#

artifact1_celltypes = artifact1.cell_types.all()
artifact2_celltypes = artifact2.cell_types.all()

shared_celltypes = artifact1_celltypes & artifact2_celltypes
shared_celltypes_names = shared_celltypes.list("name")
shared_celltypes_names
['CD16-positive, CD56-dim natural killer cell, human']

Load the individual artifacts#

We could either load the artifacts into memory or access them in backed mode through .backed() to lazily load their content.

Let鈥檚 load them into memory:

adata1 = artifact1.load()
adata2 = artifact2.load()

We can now subset the two collections by shared cell types:

adata1_subset = adata1[adata1.obs["cell_type"].isin(shared_celltypes_names)]
adata2_subset = adata2[adata2.obs["cell_type"].isin(shared_celltypes_names)]