CODEX

[1]:
import os
import pandas as pd
import numpy as np
import scanpy as sc
import squidpy as sq
import anndata as ad

import matplotlib.pyplot as plt
import seaborn as sns
[2]:
import pysodb
[3]:
sc.set_figure_params(vector_friendly=False,format='pdf',transparent=True,dpi=50)
plt.rcParams["figure.figsize"] = (8, 8)

sns.set_style('white')

load a data using pysodb

[4]:
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(
[5]:
# this dataset is from publication "Deep Profiling of Mouse Splenic Architecture with CODEX Multiplexed Imaging"
[6]:
# link in SODB: https://gene.ai.tencent.com/SpatialOmics/dataset?datasetID=59
[7]:
adata = sodb.load_experiment('Goltsev2028deep','MRL-5')
# the first parameter is the name of the dataset
# the second parameter is the name of one experiment in the dataset
load experiment[MRL-5] in dataset[Goltsev2028deep] from /home/yzy/anaconda3/envs/SODB/lib/python3.9/site-packages/pysodb-1.0.0-py3.9.egg/pysodb/cache/Goltsev2028deep/MRL-5.h5ad
[8]:
adata
[8]:
AnnData object with n_obs × n_vars = 73427 × 30
    obs: 'Imaging phenotype cluster ID', 'X.X', 'Y.Y', 'Z.Z', 'blank_Cy3_cyc15', 'blank_Cy5_cyc15', 'sample_Xtile_Ytile', 'niche cluster ID', 'Xtile', 'Ytile', 'sample', 'condition', 'ct', 'leiden'
    uns: 'leiden', 'leiden_colors', 'moranI', 'neighbors', 'pca', 'spatial_neighbors', 'umap'
    obsm: 'X_pca', 'X_umap', 'spatial', 'spatial_global'
    varm: 'PCs'
    obsp: 'connectivities', 'distances', 'spatial_connectivities', 'spatial_distances'

display clusters

[9]:
sc.pl.embedding(adata,basis='spatial',color='ct',s=30)
../_images/squidpy_pysodb_squidpy_CODEX_11_0.png

Neighborhood enrichment

[10]:
sq.gr.spatial_neighbors(adata)
sq.gr.nhood_enrichment(adata, cluster_key="ct")
sq.pl.nhood_enrichment(adata, cluster_key="ct")
/home/yzy/anaconda3/envs/SODB/lib/python3.9/site-packages/tqdm-4.64.1-py3.9.egg/tqdm/auto.py:22: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html
  from .autonotebook import tqdm as notebook_tqdm
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1000/1000 [00:05<00:00, 196.62/s]
/home/yzy/anaconda3/envs/SODB/lib/python3.9/site-packages/squidpy-1.1.2-py3.9.egg/squidpy/pl/_graph.py:239: FutureWarning: X.dtype being converted to np.float32 from float64. In the next version of anndata (0.9) conversion will not be automatic. Pass dtype explicitly to avoid this warning. Pass `AnnData(X, dtype=X.dtype, ...)` to get the future behavour.
  ad = AnnData(X=array, obs={cluster_key: pd.Categorical(adata.obs[cluster_key].cat.categories)})
../_images/squidpy_pysodb_squidpy_CODEX_13_1.png

Interaction matrix and network centralities

[11]:
sq.gr.interaction_matrix(adata, cluster_key="ct")
sq.pl.interaction_matrix(adata, cluster_key="ct")
/home/yzy/anaconda3/envs/SODB/lib/python3.9/site-packages/squidpy-1.1.2-py3.9.egg/squidpy/pl/_graph.py:176: FutureWarning: X.dtype being converted to np.float32 from float64. In the next version of anndata (0.9) conversion will not be automatic. Pass dtype explicitly to avoid this warning. Pass `AnnData(X, dtype=X.dtype, ...)` to get the future behavour.
  ad = AnnData(X=array, obs={cluster_key: pd.Categorical(adata.obs[cluster_key].cat.categories)})
../_images/squidpy_pysodb_squidpy_CODEX_15_1.png

centrality score analysis

[12]:
sq.gr.centrality_scores(
    adata,
    cluster_key="ct",
)
sq.pl.centrality_scores(adata, cluster_key="ct", figsize=(20, 5), s=500)
/home/yzy/anaconda3/envs/SODB/lib/python3.9/site-packages/IPython/core/pylabtools.py:151: UserWarning: constrained_layout not applied because axes sizes collapsed to zero.  Try making figure larger or axes decorations smaller.
  fig.canvas.print_figure(bytes_io, **kw)
../_images/squidpy_pysodb_squidpy_CODEX_17_1.png