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")
../_images/tutorials_Core_plots_7_0.png

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")
../_images/tutorials_Core_plots_9_0.png
[5]:
st.pl.gene_plot(adata, gene_symbols=["BRCA1","BRCA2"], method="NaiveMean")
../_images/tutorials_Core_plots_10_0.png

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)
../_images/tutorials_Core_plots_12_0.png

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)
../_images/tutorials_Core_plots_14_0.png

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")
../_images/tutorials_Core_plots_17_0.png
[9]:
st.pl.cluster_plot(adata_processed, use_label="louvain", show_cluster_labels=True, show_color_bar=False)
../_images/tutorials_Core_plots_18_0.png

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'])
../_images/tutorials_Core_plots_21_0.png
[11]:
st.pl.subcluster_plot(adata_processed, use_label="louvain", cluster = '6')
../_images/tutorials_Core_plots_22_0.png

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)
../_images/tutorials_Core_plots_25_0.png

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)
../_images/tutorials_Core_plots_27_0.png

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'])
../_images/tutorials_Core_plots_30_0.png
[16]:
st.pl.lr_result_plot(adata_processed, "GPC3_IGF1R", "-log10(p_adjs)")
../_images/tutorials_Core_plots_31_0.png
[17]:
st.pl.lr_result_plot(adata_processed, "GPC3_IGF1R", "lr_sig_scores")
../_images/tutorials_Core_plots_32_0.png

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))
../_images/tutorials_Core_plots_34_0.png
../_images/tutorials_Core_plots_34_1.png

For many more CCI visualisations, please see the stLearn CCI tutorial.