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.70.3
馃挕 saved: Transform(uid='agayZTonayqA5zKv', name='Query artifacts', key='scrna3', version='1', type='notebook', updated_at=2024-04-22 10:42:39 UTC, created_by_id=1)
馃挕 saved: Run(uid='rNG4PQngawr8BlTAwa9R', 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 | Tshv8ZcuQUs1VfprMZ55 | 1 | None | .h5ad | AnnData | Human immune cells from Conde22 | None | 57612943 | 9sXda5E7BYiVoDOQkTC0KB | sha1-fl | None | 1648 | 1 | 1 | 1 | True | 2024-04-22 10:42:03.415587+00:00 | 2024-04-22 10:42:06.762408+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='Tshv8ZcuQUs1VfprMZ55', 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-04-22 10:42:06 UTC)
Provenance:
馃搸 storage: Storage(uid='KwQeXzq5', root='/home/runner/work/lamin-usecases/lamin-usecases/docs/test-scrna', type='local')
馃搸 transform: Transform(uid='Nv48yAceNSh85zKv', name='scRNA-seq', key='scrna', version='1', type='notebook')
馃搸 run: Run(uid='IINE0MbPjgvFpAUeyzBH', started_at=2024-04-22 10:40:11 UTC, is_consecutive=True)
馃搸 created_by: User(uid='DzTjkKse', handle='testuser1', name='Test User1')
馃搸 input_of (core.Run): ['2024-04-22 10:42:13 UTC']
Features:
var: FeatureSet(uid='LF1XYQjNoUipLfEEALoP', n=36503, type='number', registry='bionty.Gene')
'LINC02731', 'RALA', 'EPB41L2', 'DNMBP-AS1', 'USP1', 'TLR10', 'ZKSCAN3', 'LINC00654', 'NEMF', 'INTS6', 'KXD1-AS1', 'MICOS13', 'WDR35-DT', 'UBXN8', 'CASP4', 'LINC02253', 'COMMD5', 'ACVR1C', 'KIF5B', 'CHKB', ...
obs: FeatureSet(uid='cz0e1Iz4dZSe91DZy0we', n=4, registry='core.Feature')
馃敆 donor (12, core.ULabel): '637C', 'A35', 'A29', 'A37', '640C', 'A36', 'A52', '582C', 'D496', '621B', ...
馃敆 tissue (17, bionty.Tissue): 'blood', 'spleen', 'liver', 'bone marrow', 'ileum', 'thoracic lymph node', 'omentum', 'duodenum', 'lung', 'sigmoid colon', ...
馃敆 cell_type (32, bionty.CellType): 'group 3 innate lymphoid cell', 'plasma cell', 'plasmacytoid dendritic cell', 'CD4-positive helper T cell', 'regulatory T cell', 'naive thymus-derived CD4-positive, alpha-beta T cell', 'megakaryocyte', 'dendritic cell, human', 'T follicular helper cell', 'effector memory CD4-positive, alpha-beta T cell', ...
馃敆 assay (3, bionty.ExperimentalFactor): '10x 5' v1', '10x 3' v3', '10x 5' v2'
Labels:
馃搸 tissues (17, bionty.Tissue): 'blood', 'spleen', 'liver', 'bone marrow', 'ileum', 'thoracic lymph node', 'omentum', 'duodenum', 'lung', 'sigmoid colon', ...
馃搸 cell_types (32, bionty.CellType): 'group 3 innate lymphoid cell', 'plasma cell', 'plasmacytoid dendritic cell', 'CD4-positive helper T cell', 'regulatory T cell', 'naive thymus-derived CD4-positive, alpha-beta T cell', 'megakaryocyte', 'dendritic cell, human', 'T follicular helper cell', 'effector memory CD4-positive, alpha-beta T cell', ...
馃搸 experimental_factors (3, bionty.ExperimentalFactor): '10x 5' v1', '10x 3' v3', '10x 5' v2'
馃搸 ulabels (12, core.ULabel): '637C', 'A35', 'A29', 'A37', '640C', 'A36', 'A52', '582C', 'D496', '621B', ...
artifact1.view_lineage()
artifact2.describe()
Artifact(uid='2rM782zVcyLx46qGM2EU', 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-04-22 10:42:32 UTC)
Provenance:
馃搸 storage: Storage(uid='KwQeXzq5', root='/home/runner/work/lamin-usecases/lamin-usecases/docs/test-scrna', type='local')
馃搸 transform: Transform(uid='ManDYgmftZ8C5zKv', name='Standardize and append a batch of data', key='scrna2', version='1', type='notebook')
馃搸 run: Run(uid='dB2PAgeaKiIqmwXpzyDG', started_at=2024-04-22 10:42:13 UTC, is_consecutive=True)
馃搸 created_by: User(uid='DzTjkKse', handle='testuser1', name='Test User1')
Features:
var: FeatureSet(uid='QTZfL7djujTuGfD3Kf5T', n=754, type='number', registry='bionty.Gene')
'IMPDH2', 'ILF3-DT', 'PMVK', 'LEPROTL1', 'MZB1', 'SPINT2', 'EVL', 'LY9', 'ELOVL5', 'OGG1', 'PAXX', 'CD33', 'IGLL1', 'EIF1B', 'TLN1', 'MYO5A', 'PPP2R5C', 'PBXIP1', 'GATA3', 'STMN1', ...
obs: FeatureSet(uid='8gZ1gzgpX0BJIpLsfG1a', n=1, registry='core.Feature')
馃敆 cell_type (9, bionty.CellType): 'CD8-positive, CD25-positive, alpha-beta regulatory T cell', 'CD38-positive naive B cell', 'effector memory CD4-positive, alpha-beta T cell, terminally differentiated', 'B cell, CD19-positive', 'CD16-positive, CD56-dim natural killer cell, human', 'CD4-positive, alpha-beta T cell', 'cytotoxic T cell', 'dendritic cell', 'CD14-positive, CD16-negative classical monocyte'
Labels:
馃搸 cell_types (9, bionty.CellType): 'CD8-positive, CD25-positive, alpha-beta regulatory T cell', 'CD38-positive naive B cell', 'effector memory CD4-positive, alpha-beta T cell, terminally differentiated', 'B cell, CD19-positive', 'CD16-positive, CD56-dim natural killer cell, human', 'CD4-positive, alpha-beta T cell', 'cytotoxic T cell', 'dendritic cell', 'CD14-positive, CD16-negative classical monocyte'
artifact2.view_lineage()
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)]