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.57.2)
ln.track()
๐ก notebook imports: anndata==0.9.2 lamindb==0.57.2 lnschema_bionty==0.33.0
๐ก Transform(uid='agayZTonayqAz8', name='Query individual files', short_name='scrna3', version='0', type=notebook, updated_at=2023-10-23 17:48:19, created_by_id=1)
๐ก Run(uid='wNdQZmvlKeZbcGppGyRs', run_at=2023-10-23 17:48:19, transform_id=3, created_by_id=1)
Access #
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 | updated_at | created_by_id | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id | |||||||||||||||
1 | KHDuUmCEv6SwM8UNQulB | 1 | None | .h5ad | AnnData | Conde22 | None | 57615999 | 6Hu1BywwK6bfIU2Dpku2xZ | sha1-fl | 1 | 1 | None | 2023-10-23 17:47:33 | 1 |
Query files based on 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 | updated_at | created_by_id | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id | |||||||||||||||
1 | KHDuUmCEv6SwM8UNQulB | 1 | None | .h5ad | AnnData | Conde22 | None | 57615999 | 6Hu1BywwK6bfIU2Dpku2xZ | sha1-fl | 1 | 1 | None | 2023-10-23 17:47:33 | 1 |
2 | LnH0qcPKHapOHPwc6LrM | 1 | None | .h5ad | AnnData | 10x reference adata | None | 857752 | U4UmKxr_rN8KlwVK4WYKjw | md5 | 2 | 2 | None | 2023-10-23 17:48:08 | 1 |
Transform #
Compare gene sets#
Get file objects:
query = ln.File.filter()
file1, file2 = query.list()
file1.describe()
File(uid='KHDuUmCEv6SwM8UNQulB', suffix='.h5ad', accessor='AnnData', description='Conde22', size=57615999, hash='6Hu1BywwK6bfIU2Dpku2xZ', hash_type='sha1-fl', updated_at=2023-10-23 17:47:33)
Provenance:
๐๏ธ storage: Storage(uid='ZIqsTwSZ', root='/home/runner/work/lamin-usecases/lamin-usecases/docs/test-scrna', type='local', updated_at=2023-10-23 17:46:37, created_by_id=1)
๐ transform: Transform(uid='Nv48yAceNSh8z8', name='scRNA-seq', short_name='scrna', version='0', type='notebook', updated_at=2023-10-23 17:46:43, created_by_id=1)
๐ฃ run: Run(uid='IEKKxa53gZdZ0HW3weYa', run_at=2023-10-23 17:46:43, transform_id=1, created_by_id=1)
๐ค created_by: User(uid='DzTjkKse', handle='testuser1', name='Test User1', updated_at=2023-10-23 17:46:37)
โฌ๏ธ input_of (core.Run): ['2023-10-23 17:47:41']
Features:
var: FeatureSet(uid='5cU3jVnVC7TmCShMOHGI', n=36503, type='number', registry='bionty.Gene', hash='dnRexHCtxtmOU81_EpoJ', updated_at=2023-10-23 17:47:27, 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='YMf0jITlhFBIzo97KFNP', n=4, registry='core.Feature', hash='sTKN4H5ua2p0aUB7Qf41', updated_at=2023-10-23 17:47:28, 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()
file2.describe()
File(uid='LnH0qcPKHapOHPwc6LrM', suffix='.h5ad', accessor='AnnData', description='10x reference adata', size=857752, hash='U4UmKxr_rN8KlwVK4WYKjw', hash_type='md5', updated_at=2023-10-23 17:48:08)
Provenance:
๐๏ธ storage: Storage(uid='ZIqsTwSZ', root='/home/runner/work/lamin-usecases/lamin-usecases/docs/test-scrna', type='local', updated_at=2023-10-23 17:46:37, 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-23 17:47:41, created_by_id=1)
๐ฃ run: Run(uid='ZDcOJl5E15UoqnTxZJ7t', run_at=2023-10-23 17:47:41, transform_id=2, created_by_id=1)
๐ค created_by: User(uid='DzTjkKse', handle='testuser1', name='Test User1', updated_at=2023-10-23 17:46:37)
Features:
var: FeatureSet(uid='JP1OvnEx2ITWEjurSjHk', n=754, type='number', registry='bionty.Gene', hash='WMDxN7253SdzGwmznV5d', updated_at=2023-10-23 17:48:08, 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='kq35k5DEtE4DkfG02hgo', n=1, registry='core.Feature', hash='iuyPNK3smIuvcnCIlFSV', updated_at=2023-10-23 17:48:08, 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='4tILjB6W30HNtBGOI5uS', n=2, registry='core.Feature', hash='LNTvx6NLtiHp0Nw8h_T5', updated_at=2023-10-23 17:48:08, 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()
Load files into memory:
file1_adata = file1.load()
file2_adata = file2.load()
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']
We can now subset the two datasets by shared cell types:
file1_adata_subset = file1_adata[
file1_adata.obs["cell_type"].isin(shared_celltypes_names)
]
file2_adata_subset = file2_adata[
file2_adata.obs["cell_type"].isin(shared_celltypes_names)
]
Concatenate subsetted datasets:
adata_concat = ad.concat(
[file1_adata_subset, file2_adata_subset],
label="file",
keys=[file1.description, file2.description],
)
adata_concat
AnnData object with n_obs ร n_vars = 187 ร 749
obs: 'cell_type', 'file'
obsm: 'X_umap'
adata_concat.obs.value_counts()
cell_type file
CD16-positive, CD56-dim natural killer cell, human Conde22 114
gamma-delta T cell Conde22 66
10x reference adata 4
CD16-positive, CD56-dim natural killer cell, human 10x reference adata 3
dtype: int64