Stereo-seq
[27]:
import os
import pandas as pd
import numpy as np
import scanpy as sc
import anndata as ad
import matplotlib.pyplot as plt
import seaborn as sns
[28]:
import pysodb
[29]:
sc.set_figure_params(vector_friendly=False,format='pdf',transparent=True,dpi=50)
plt.rcParams["figure.figsize"] = (8, 8)
sns.set_style('white')
load data using pysodb
[30]:
sodb = pysodb.SODB() # Initialization
/home/yzy/anaconda3/envs/SODB/lib/python3.9/site-packages/urllib3-1.26.12-py3.9.egg/urllib3/connectionpool.py:1045: InsecureRequestWarning: Unverified HTTPS request is being made to host 'gene.ai.tencent.com'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#ssl-warnings
warnings.warn(
[ ]:
# this dataset is from publication "Spatiotemporal transcriptomic atlas of mouse organogenesis using DNA nanoball-patterned arrays"
[ ]:
# link in SODB: https://gene.ai.tencent.com/SpatialOmics/dataset?datasetID=82
[33]:
adata = sodb.load_experiment('chen2022spatiotemporal','E16.5_E1S3.MOSTA')
# the first parameter is the name of the dataset
# the second parameter is the name of one experiment in the dataset
load experiment[E16.5_E1S3.MOSTA] in dataset[chen2022spatiotemporal] from /home/yzy/anaconda3/envs/SODB/lib/python3.9/site-packages/pysodb-1.0.0-py3.9.egg/pysodb/cache/chen2022spatiotemporal/E16.5_E1S3.MOSTA.h5ad
identify clusters
[34]:
11510685/(155741*1000)
[34]:
0.07390915044850103
[35]:
adata.X = adata.X.astype('float')
[36]:
sc.pp.normalize_per_cell(adata)
sc.pp.log1p(adata)
[37]:
sc.pp.pca(adata)
sc.pp.neighbors(adata)
sc.tl.umap(adata)
sc.tl.leiden(adata, key_added="clusters")
[38]:
sc.pl.umap(adata, color=[ "clusters"], wspace=0.4,
add_outline=True,legend_fontsize=10, legend_fontoutline=2,
legend_loc='on data',
s=50
)
[39]:
# plt.rcParams["figure.figsize"] = (8, 8)
sc.pl.embedding(adata, basis='spatial', color=['clusters'],show=False,size=10,add_outline=True)
plt.gca().set_aspect('equal', adjustable='box')
marker gene detection
[40]:
sc.tl.rank_genes_groups(adata, "clusters", method="t-test")
sc.pl.rank_genes_groups_tracksplot(adata, n_genes=3, groupby="clusters")
WARNING: dendrogram data not found (using key=dendrogram_clusters). Running `sc.tl.dendrogram` with default parameters. For fine tuning it is recommended to run `sc.tl.dendrogram` independently.
/home/yzy/anaconda3/envs/SODB/lib/python3.9/site-packages/scanpy-1.9.1-py3.9.egg/scanpy/plotting/_anndata.py:2414: FutureWarning: iteritems is deprecated and will be removed in a future version. Use .items instead.
obs_tidy.index.value_counts(sort=False).iteritems()
[41]:
adata
[41]:
AnnData object with n_obs × n_vars = 155741 × 1000
obs: 'annotation', 'leiden', 'n_counts', 'clusters'
uns: 'annotation_colors', 'leiden', 'leiden_colors', 'moranI', 'neighbors', 'pca', 'spatial_neighbors', 'umap', 'log1p', 'clusters_colors', 'rank_genes_groups', 'dendrogram_clusters'
obsm: 'X_pca', 'X_umap', 'spatial'
varm: 'PCs'
obsp: 'connectivities', 'distances', 'spatial_connectivities', 'spatial_distances'
[42]:
marker_genes = adata.uns['rank_genes_groups']['names'][0]
[43]:
sc.pl.umap(adata, color=marker_genes, wspace=0.4,
add_outline=True,legend_fontsize=10, legend_fontoutline=2,
legend_loc='on data',
s=500
)
[44]:
# plt.rcParams["figure.figsize"] = (8, 8)
sc.pl.embedding(adata, basis='spatial', color=marker_genes,size=500,add_outline=True)
[ ]: