Spatial#
Note
Please see:
This page is for now just a stub.
!lamin init --storage ./test-spatial --schema bionty
Show code cell output
💡 connected lamindb: testuser1/test-spatial
import lamindb as ln
import bionty as bt
import matplotlib.pyplot as plt
import scanpy as sc
Show code cell output
💡 connected lamindb: testuser1/test-spatial
ln.settings.transform.stem_uid = "daeFs3PkquDW"
ln.settings.transform.version = "draft"
ln.track()
💡 notebook imports: bionty==0.42.7 lamindb==0.69.9 matplotlib==3.8.4 scanpy==1.10.1
💡 saved: Transform(uid='daeFs3PkquDW7a3V', name='Spatial', key='spatial', version='draft', type='notebook', updated_at=2024-04-10 17:55:06 UTC, created_by_id=1)
💡 saved: Run(uid='Fp4mRCBaCFAPRhMivbjG', transform_id=1, created_by_id=1)
Access #
Here, we have a spatial gene expression dataset measured using Visium from Suo22.
This collection contains two parts:
a high-res image of a slice of fetal liver
a single cell expression dataset in .h5ad
img_path = ln.core.datasets.file_tiff_suo22()
img = plt.imread(img_path)
plt.imshow(img)
plt.show()
adata = ln.core.datasets.anndata_suo22_Visium10X()
# subset to the same image
adata = adata[adata.obs["img_id"] == "F121_LP1_4LIV"].copy()
adata
AnnData object with n_obs × n_vars = 3027 × 191
obs: 'in_tissue', 'array_row', 'array_col', 'sample', 'n_genes_by_counts', 'log1p_n_genes_by_counts', 'total_counts', 'log1p_total_counts', 'pct_counts_in_top_50_genes', 'pct_counts_in_top_100_genes', 'pct_counts_in_top_200_genes', 'pct_counts_in_top_500_genes', 'mt_frac', 'img_id', 'EXP_id', 'Organ', 'Fetal_id', 'SN', 'Visium_Area_id', 'Age_PCW', 'Digestion time', 'paths', 'sample_id', '_scvi_batch', '_scvi_labels', '_indices', 'total_cell_abundance'
var: 'feature_types', 'genome', 'SYMBOL', 'mt'
obsm: 'NMF', 'means_cell_abundance_w_sf', 'q05_cell_abundance_w_sf', 'q95_cell_abundance_w_sf', 'spatial', 'stds_cell_abundance_w_sf'
# plot where CD45+ leukocytes are in the slice
sc.pl.scatter(adata, "array_row", "array_col", color="ENSG00000081237")
Register #
We’ll register the single-cell data and the image as a Collection
.
file_ad = ln.Artifact.from_anndata(
adata,
description="Suo22 Visium10X image F121_LP1_4LIV"
)
file_ad.save()
file_ad.features.add_from_anndata(var_field=bt.Gene.ensembl_gene_id, organism="human")
Show code cell output
❗ 191 terms (100.00%) are not validated for ensembl_gene_id: ENSG00000002586, ENSG00000004468, ENSG00000004897, ENSG00000007312, ENSG00000008086, ENSG00000008128, ENSG00000010278, ENSG00000010610, ENSG00000012124, ENSG00000013725, ENSG00000019582, ENSG00000026508, ENSG00000039068, ENSG00000059758, ENSG00000062038, ENSG00000065883, ENSG00000066294, ENSG00000070831, ENSG00000071991, ENSG00000073754, ...
❗ skip linking features to artifact in slot 'var'
❗ 27 terms (100.00%) are not validated for name: in_tissue, array_row, array_col, sample, n_genes_by_counts, log1p_n_genes_by_counts, total_counts, log1p_total_counts, pct_counts_in_top_50_genes, pct_counts_in_top_100_genes, pct_counts_in_top_200_genes, pct_counts_in_top_500_genes, mt_frac, img_id, EXP_id, Organ, Fetal_id, SN, Visium_Area_id, Age_PCW, ...
❗ skip linking features to artifact in slot 'obs'
file_img = ln.Artifact(img_path, description="Suo22 image F121_LP1_4LIV")
file_img.save()
collection = ln.Collection([file_ad, file_img], name="Suo22")
collection.save()
# clean up test instance
!lamin delete --force test-spatial
!rm -r test-flow
Show code cell output
💡 deleting instance testuser1/test-spatial
❗ manually delete your stored data: /home/runner/work/lamin-usecases/lamin-usecases/docs/test-spatial
rm: cannot remove 'test-flow': No such file or directory