Core plotting functions¶
Here we want to introduce several visualization functions in stLearn.
Loading processed data¶
[1]:
import stlearn as st
import scanpy as sc
st.settings.set_figure_params(dpi=120)
# Ignore all warnings
import warnings
warnings.filterwarnings("ignore")
[ ]:
# Read raw data
adata = sc.datasets.visium_sge()
adata = st.convert_scanpy(adata)
# Read processed data
adata_processed = st.datasets.example_bcba()
Gene plot¶
Here is the standard plot for gene expression, we provide 2 options for single genes and multiple genes:
[3]:
st.pl.gene_plot(adata, gene_symbols="BRCA1")

For multiple genes, you can combine multiple genes by 'CumSum'
cummulative sum or 'NaiveMean'
naive mean:
[4]:
st.pl.gene_plot(adata, gene_symbols=["BRCA1","BRCA2"], method="CumSum")

[5]:
st.pl.gene_plot(adata, gene_symbols=["BRCA1","BRCA2"], method="NaiveMean")

You also can plot genes with contour plot to see clearer about the distribution of genes:
[6]:
st.pl.gene_plot(adata, gene_symbols="GAPDH", contour=True,cell_alpha=0.5)

You can change the step_size
to cut the range of display in contour
[7]:
st.pl.gene_plot(adata, gene_symbols="GAPDH", contour=True,cell_alpha=0.5, step_size=200)

Cluster plot¶
We provide different options for display clustering results. Several show_*
options that user can control to display different parts of the figure:
[8]:
st.pl.cluster_plot(adata_processed, use_label="louvain")

[9]:
st.pl.cluster_plot(adata_processed, use_label="louvain", show_cluster_labels=True, show_color_bar=False)

Subcluster plot¶
We also provide option to plot spatial subclusters based on the spatial location within a cluster.
You have two options here, display subclusters for multiple clusters using show_subcluster
in st.pl.cluster_plot
or use st.pl.subcluster_plot
to display subclusters within a cluster but with different color.
[10]:
st.pl.cluster_plot(adata_processed,use_label="louvain",show_subcluster=True,show_color_bar=False, list_clusters=['6','8'])

[11]:
st.pl.subcluster_plot(adata_processed, use_label="louvain", cluster = '6')

Spatial trajectory plot¶
We provided st.pl.trajectory.pseudotime_plot
to visualize PAGA graph that maps into spatial transcriptomics array.
[13]:
st.pl.trajectory.pseudotime_plot(adata_processed, use_label="louvain", pseudotime_key="dpt_pseudotime", list_clusters=['6','8'], show_node=True)

You can plot spatial trajectory analysis results with the node in each subcluster by show_trajectories
and show_node
parameters.
[14]:
st.pl.cluster_plot(adata_processed,use_label="louvain",show_trajectories=True,
show_color_bar=True, list_clusters=['6','8'], show_node=True)

Ligand-receptor interaction plots¶
For the stLearn ligand-receptor cell-cell interaction analysis, you can display basic results for LRs using st.pl.lr_result_plot
. For many more visualisations, please see the stLearn Cell-cell interaction analysis tutorial.
[15]:
st.pl.lr_summary(adata_processed, highlight_lrs=['GPC3_IGF1R'])

[16]:
st.pl.lr_result_plot(adata_processed, "GPC3_IGF1R", "-log10(p_adjs)")

[17]:
st.pl.lr_result_plot(adata_processed, "GPC3_IGF1R", "lr_sig_scores")

Cell-cell interaction plots¶
For the stLearn cell-cell interaction analysis, you can display the celltype-celltype interactions between cell types using st.pl.lr_chord_plot
.
[18]:
st.pl.cluster_plot(adata_processed, use_label='cell_type')
st.pl.lr_chord_plot(adata_processed, 'cell_type', 'GPC3_IGF1R', figsize=(4,4))

