Analysis of spatial factors corresponding to endothelial subpopulations

[1]:
import pandas as pd
import numpy as np
import scanpy as sc
import anndata as ad
import matplotlib.pyplot as plt
import matplotlib as mpl
mpl.rcParams['pdf.fonttype'] = 42
mpl.rcParams['ps.fonttype'] = 42
import os
import sys

import warnings
warnings.filterwarnings("ignore")

Load results

[2]:
res_path = "/gpfs/gibbs/pi/zhao/jz874/project/jiazhao/inspire_revision/tutorials/new_examples/human_breast_cancer_xenium"
adata = sc.read_h5ad(res_path + "/adata_inspire.h5ad")
basis_df = pd.read_csv(res_path + "/basis_df_inspire.csv", index_col=0)
adata.obsm["factors"] = np.array(adata.obs[["Proportion of spatial factor "+str(j+1) for j in range(50)]].values)

Visualization of gene signatures

[3]:
topic_id = 36

topic_profile = np.array(basis_df.iloc[topic_id,:].values)
order = np.argsort(-topic_profile)
print(basis_df.columns[order])

potential_marker = list(basis_df.columns[order[:50]])
marker_ours = []
for i in range(len(potential_marker)):
    id_1 = np.argsort(-basis_df[potential_marker[i]])[0]
    id_2 = np.argsort(-basis_df[potential_marker[i]])[1]
    val_1 = basis_df[potential_marker[i]][id_1]
    val_2 = basis_df[potential_marker[i]][id_2]
    if (id_1 == topic_id) & (val_1 >= (val_2*1.5)):
        marker_ours.append(potential_marker[i])
print(marker_ours)
Index(['KDR', 'BTNL9', 'CLEC14A', 'RAMP2', 'ESM1', 'CD93', 'CAV1', 'SOX17',
       'EDNRB', 'HOXD9',
       ...
       'TACSTD2', 'SFRP1', 'CYTIP', 'KRT15', 'SFRP4', 'LYZ', 'SERPINA3',
       'PTPRC', 'ADH1B', 'IL7R'],
      dtype='object', length=313)
['KDR', 'BTNL9', 'CLEC14A', 'RAMP2', 'ESM1', 'SOX17', 'SOX18']
[4]:
topic_id = 40

topic_profile = np.array(basis_df.iloc[topic_id,:].values)
order = np.argsort(-topic_profile)
print(basis_df.columns[order])

potential_marker = list(basis_df.columns[order[:50]])
marker_ours = []
for i in range(len(potential_marker)):
    id_1 = np.argsort(-basis_df[potential_marker[i]])[0]
    id_2 = np.argsort(-basis_df[potential_marker[i]])[1]
    val_1 = basis_df[potential_marker[i]][id_1]
    val_2 = basis_df[potential_marker[i]][id_2]
    if (id_1 == topic_id) & (val_1 >= (val_2*1.5)):
        marker_ours.append(potential_marker[i])
print(marker_ours)
Index(['VWF', 'AQP1', 'PECAM1', 'MMRN2', 'CAVIN2', 'CD93', 'EDN1', 'NOSTRIN',
       'CLEC14A', 'ANGPT2',
       ...
       'KRT14', 'KRT6B', 'CYTIP', 'MS4A1', 'RUNX1', 'CD3E', 'KRT15', 'SFRP4',
       'ADH1B', 'PTPRC'],
      dtype='object', length=313)
['VWF', 'AQP1', 'PECAM1', 'MMRN2', 'CAVIN2', 'EDN1', 'NOSTRIN', 'CLDN5', 'RAPGEF3']
[5]:
gene_list = gene_list = ['KDR', 'BTNL9', 'ESM1', 'SOX17'] + ['VWF', 'AQP1', 'PECAM1', 'MMRN2', 'CAVIN2', 'EDN1', 'NOSTRIN']

n_factors = 2
gene_set = gene_list
profile = basis_df.iloc[[36,40], :]
profile = profile[gene_set]
factor_names = ["Factor: Endo 1", "Factor: Endo 2"]

f = plt.figure(figsize=(3.9,1.))
ax = f.add_subplot(111)
# ax.set_ylabel('Factor', fontsize=14)
im = ax.imshow(profile, cmap='viridis', interpolation='nearest', aspect='auto')
plt.yticks(np.arange(n_factors), factor_names, rotation=0, fontsize=14)
plt.xticks(np.arange(len(gene_set)), gene_set, rotation=90, fontsize=14, style="italic")
# plt.title("Gene signature of factors", fontsize=15)
plt.vlines(x=np.arange(len(gene_set))-0.5, ymin=-0.5, ymax=n_factors-0.5, color="gray", linewidth=1.5, alpha=0.2)
plt.hlines(y=np.arange(n_factors)-0.5, xmin=-0.5, xmax=len(gene_set)-0.5, color="gray", linewidth=1.5, alpha=0.2)
plt.vlines(x=-0.5, ymin=-0.5, ymax=n_factors-0.5, color="k", linewidth=2, alpha=1)
plt.vlines(x=len(gene_set)-0.5, ymin=-0.5, ymax=n_factors-0.5, color="k", linewidth=2, alpha=1)
plt.hlines(y=-0.5, xmin=-0.5, xmax=len(gene_set)-0.5, color="k", linewidth=2, alpha=1)
plt.hlines(y=n_factors-0.5, xmin=-0.5, xmax=len(gene_set)-0.5, color="k", linewidth=2, alpha=1)

plt.show()
../../_images/tutorials_human_breast_cancer_xenium_human_breast_cancer_endo_factors_7_0.png

Correlation analysis of spatial factors and their associated gene expression profiles

[8]:
factor_myoepi = np.array(adata.obs[["Proportion of spatial factor 37", "Proportion of spatial factor 41"]].values)
corr_factor = np.corrcoef(factor_myoepi.T)

import seaborn as sns

plt.figure(figsize = (2*0.8*0.65,1.6*0.9*0.65))
sns.heatmap(corr_factor, vmin=0., vmax=1.)
plt.yticks(ticks=[0.5,1.5], labels=["Factor: Endo 1", "Factor: Endo 2"], rotation=0, fontsize=11)
plt.xticks(ticks=[0.5,1.5], labels=["", ""])

plt.show()
../../_images/tutorials_human_breast_cancer_xenium_human_breast_cancer_endo_factors_12_0.png
[9]:
import seaborn as sns
corr_loading = basis_df.iloc[[36,40], :].T.corr()

import seaborn as sns

plt.figure(figsize = (2*0.8*0.65,1.6*0.9*0.65))
sns.heatmap(corr_loading, vmin=0., vmax=1., cmap="viridis")
plt.yticks(ticks=[0.5,1.5], labels=["Loadng for endo 1", "Loadng for endo 2"], rotation=0, fontsize=11)
plt.xticks(ticks=[0.5,1.5], labels=["", ""])

plt.show()
../../_images/tutorials_human_breast_cancer_xenium_human_breast_cancer_endo_factors_13_0.png