scrna3/6 Jupyter Notebook lamindata

Query individual files#

Here, we’ll query individual files and inspect their metadata.

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

import lamindb as ln
import lnschema_bionty as lb
import anndata as ad
πŸ’‘ loaded instance: testuser1/test-scrna (lamindb 0.59.0)
ln.track()
πŸ’‘ notebook imports: anndata==0.9.2 lamindb==0.59.0 lnschema_bionty==0.34.0
πŸ’‘ Transform(uid='agayZTonayqAz8', name='Query individual files', short_name='scrna3', version='0', type=notebook, updated_at=2023-10-27 14:09:44, created_by_id=1)
πŸ’‘ Run(uid='WudOf34xwirCTrE9FU3W', run_at=2023-10-27 14:09:44, transform_id=3, created_by_id=1)

Query files by provenance metadata#

users = ln.User.lookup()
ln.Transform.filter(created_by=users.testuser1).search("scrna")
uid score
name
scRNA-seq Nv48yAceNSh8z8 90.0
Append a new batch of data ManDYgmftZ8Cz8 36.0
Query individual files agayZTonayqAz8 36.0
transform = ln.Transform.filter(uid="Nv48yAceNSh8z8").one()
ln.File.filter(transform=transform).df()
uid storage_id key suffix accessor description version size hash hash_type transform_id run_id initial_version_id visibility key_is_virtual updated_at created_by_id
id
1 OmLkMWSbDuMAxFj7BqyV 1 None .h5ad AnnData Conde22 None 57612943 9sXda5E7BYiVoDOQkTC0KB sha1-fl 1 1 None 0 True 2023-10-27 14:08:58 1

Query files by biological metadata#

assays = lb.ExperimentalFactor.lookup()
organism = lb.Organism.lookup()
cell_types = lb.CellType.lookup()
query = ln.File.filter(
    experimental_factors=assays.single_cell_rna_sequencing,
    organism=organism.human,
    cell_types=cell_types.gamma_delta_t_cell,
)
query.df()
uid storage_id key suffix accessor description version size hash hash_type transform_id run_id initial_version_id visibility key_is_virtual updated_at created_by_id
id
1 OmLkMWSbDuMAxFj7BqyV 1 None .h5ad AnnData Conde22 None 57612943 9sXda5E7BYiVoDOQkTC0KB sha1-fl 1 1 None 0 True 2023-10-27 14:08:58 1
2 viuAb9psg6SVruytRK7P 1 None .h5ad AnnData 10x reference adata None 857752 U4UmKxr_rN8KlwVK4WYKjw md5 2 2 None 0 True 2023-10-27 14:09:34 1

Inspect file metadata#

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

file1, file2 = query_set[0], query_set[1]
file1.describe()
File(uid='OmLkMWSbDuMAxFj7BqyV', suffix='.h5ad', accessor='AnnData', description='Conde22', size=57612943, hash='9sXda5E7BYiVoDOQkTC0KB', hash_type='sha1-fl', visibility=0, key_is_virtual=True, updated_at=2023-10-27 14:08:58)

Provenance:
  πŸ—ƒοΈ storage: Storage(uid='u254wjlq', root='/home/runner/work/lamin-usecases/lamin-usecases/docs/test-scrna', type='local', updated_at=2023-10-27 14:08:02, created_by_id=1)
  πŸ“” transform: Transform(uid='Nv48yAceNSh8z8', name='scRNA-seq', short_name='scrna', version='0', type='notebook', updated_at=2023-10-27 14:08:07, created_by_id=1)
  πŸ‘£ run: Run(uid='T5xPTY12UVw6rOOjgE7H', run_at=2023-10-27 14:08:07, transform_id=1, created_by_id=1)
  πŸ‘€ created_by: User(uid='DzTjkKse', handle='testuser1', name='Test User1', updated_at=2023-10-27 14:08:02)
  ⬇️ input_of (core.Run): ['2023-10-27 14:09:05']
Features:
  var: FeatureSet(uid='6qRKjbpfuxhgYAbbyN5d', n=36503, type='number', registry='bionty.Gene', hash='dnRexHCtxtmOU81_EpoJ', updated_at=2023-10-27 14:08:52, modality_id=1, created_by_id=1)
    'MIR1302-2HG', 'FAM138A', 'OR4F5', 'None', 'None', 'None', 'None', 'None', 'None', 'None', 'OR4F29', 'None', 'OR4F16', 'None', 'LINC01409', 'FAM87B', 'LINC01128', 'LINC00115', 'FAM41C', 'None', ...
  obs: FeatureSet(uid='BCo5J2bFOheDRHdwQ4Zd', n=4, registry='core.Feature', hash='JsxufswT1GUhRPy_OR3-', updated_at=2023-10-27 14:08:53, modality_id=2, created_by_id=1)
    πŸ”— cell_type (32, bionty.CellType): 'classical monocyte', 'T follicular helper cell', 'memory B cell', 'alveolar macrophage', 'naive thymus-derived CD4-positive, alpha-beta T cell', 'effector memory CD8-positive, alpha-beta T cell, terminally differentiated', 'alpha-beta T cell', 'CD4-positive helper T cell', 'naive thymus-derived CD8-positive, alpha-beta T cell', 'macrophage', ...
    πŸ”— assay (4, bionty.ExperimentalFactor): 'single-cell RNA sequencing', '10x 3' v3', '10x 5' v2', '10x 5' v1'
    πŸ”— tissue (17, bionty.Tissue): 'blood', 'thoracic lymph node', 'spleen', 'lung', 'mesenteric lymph node', 'lamina propria', 'liver', 'jejunal epithelium', 'omentum', 'bone marrow', ...
    πŸ”— donor (12, core.ULabel): 'D496', '621B', 'A29', 'A36', 'A35', '637C', 'A52', 'A37', 'D503', '640C', ...
Labels:
  🏷️ organism (1, bionty.Organism): 'human'
  🏷️ tissues (17, bionty.Tissue): 'blood', 'thoracic lymph node', 'spleen', 'lung', 'mesenteric lymph node', 'lamina propria', 'liver', 'jejunal epithelium', 'omentum', 'bone marrow', ...
  🏷️ cell_types (32, bionty.CellType): 'classical monocyte', 'T follicular helper cell', 'memory B cell', 'alveolar macrophage', 'naive thymus-derived CD4-positive, alpha-beta T cell', 'effector memory CD8-positive, alpha-beta T cell, terminally differentiated', 'alpha-beta T cell', 'CD4-positive helper T cell', 'naive thymus-derived CD8-positive, alpha-beta T cell', 'macrophage', ...
  🏷️ experimental_factors (4, bionty.ExperimentalFactor): 'single-cell RNA sequencing', '10x 3' v3', '10x 5' v2', '10x 5' v1'
  🏷️ ulabels (12, core.ULabel): 'D496', '621B', 'A29', 'A36', 'A35', '637C', 'A52', 'A37', 'D503', '640C', ...
file1.view_flow()
_images/005bed6d1b39a17bbc5a99f58c0031ded9eafa2511684863e1613ff051417f2d.svg
file2.describe()
File(uid='viuAb9psg6SVruytRK7P', suffix='.h5ad', accessor='AnnData', description='10x reference adata', size=857752, hash='U4UmKxr_rN8KlwVK4WYKjw', hash_type='md5', visibility=0, key_is_virtual=True, updated_at=2023-10-27 14:09:34)

Provenance:
  πŸ—ƒοΈ storage: Storage(uid='u254wjlq', root='/home/runner/work/lamin-usecases/lamin-usecases/docs/test-scrna', type='local', updated_at=2023-10-27 14:08:02, created_by_id=1)
  πŸ“” transform: Transform(uid='ManDYgmftZ8Cz8', name='Append a new batch of data', short_name='scrna2', version='0', type='notebook', updated_at=2023-10-27 14:09:05, created_by_id=1)
  πŸ‘£ run: Run(uid='y3ZljwUGmUeTdj2jFLJH', run_at=2023-10-27 14:09:05, transform_id=2, created_by_id=1)
  πŸ‘€ created_by: User(uid='DzTjkKse', handle='testuser1', name='Test User1', updated_at=2023-10-27 14:08:02)
Features:
  var: FeatureSet(uid='3ew3YYt0kI1BeTlYVQA2', n=754, type='number', registry='bionty.Gene', hash='WMDxN7253SdzGwmznV5d', updated_at=2023-10-27 14:09:34, modality_id=1, created_by_id=1)
    'IL18', 'NPM3', 'S100A9', 'S100A8', 'CNN2', 'ARHGAP45', 'RNF34', 'GPX4', 'S100A6', 'ADISSP', 'S100A4', 'FAM174C', 'SIT1', 'CCDC107', 'RSL1D1', 'TLN1', 'HES4', 'TNFRSF17', 'PCNA', 'RAB13', ...
  obs: FeatureSet(uid='2np8n6GtX3ngtJf1cPgm', n=1, registry='core.Feature', hash='o_VeIetTYgrhSdlswoWg', updated_at=2023-10-27 14:09:34, modality_id=2, created_by_id=1)
    πŸ”— cell_type (9, bionty.CellType): 'B cell, CD19-positive', 'dendritic cell', 'CD24-positive, CD4 single-positive thymocyte', 'CD8-positive, CD25-positive, alpha-beta regulatory T cell', 'CD16-positive, CD56-dim natural killer cell, human', 'gamma-delta T cell', 'monocyte', 'cytotoxic T cell', 'CD4-positive, alpha-beta T cell'
  external: FeatureSet(uid='hFHf5NbOEs6KqsfilEiu', n=2, registry='core.Feature', hash='m7vr-9W9Irr2iGKqfw8p', updated_at=2023-10-27 14:09:35, modality_id=2, created_by_id=1)
    πŸ”— assay (1, bionty.ExperimentalFactor): 'single-cell RNA sequencing'
    πŸ”— organism (1, bionty.Organism): 'human'
Labels:
  🏷️ organism (1, bionty.Organism): 'human'
  🏷️ cell_types (9, bionty.CellType): 'B cell, CD19-positive', 'dendritic cell', 'CD24-positive, CD4 single-positive thymocyte', 'CD8-positive, CD25-positive, alpha-beta regulatory T cell', 'CD16-positive, CD56-dim natural killer cell, human', 'gamma-delta T cell', 'monocyte', 'cytotoxic T cell', 'CD4-positive, alpha-beta T cell'
  🏷️ experimental_factors (1, bionty.ExperimentalFactor): 'single-cell RNA sequencing'
file2.view_flow()
_images/cce57b346bded9ce583a83b11b85b85b31a0f09ede5be574f9b49aac45a39a73.svg

Compare features#

Here we compute shared genes without loading files:

file1_genes = file1.features["var"]
file2_genes = file2.features["var"]

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

Compare cell types#

file1_celltypes = file1.cell_types.all()
file2_celltypes = file2.cell_types.all()

shared_celltypes = file1_celltypes & file2_celltypes
shared_celltypes_names = shared_celltypes.list("name")
shared_celltypes_names
['CD16-positive, CD56-dim natural killer cell, human', 'gamma-delta T cell']

Load the individual files#

We could either load the files into memory or access them in backed mode through .backed() to lazily load their content from the cloud or the disk.display_markdown

Let’s load them into memory:

adata1 = file1.load()
adata2 = file2.load()

We can now subset the two datasets 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)]