Core plotting functions

Here we want to introduce several visualization functions in stLearn.

Loading processed data

import stlearn as st
import scanpy as sc

# Ignore all warnings
import warnings
[ ]:
# 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]:, gene_symbols="BRCA1")

For multiple genes, you can combine multiple genes by 'CumSum'cummulative sum or 'NaiveMean'naive mean:

[4]:, gene_symbols=["BRCA1","BRCA2"], method="CumSum")
[5]:, gene_symbols=["BRCA1","BRCA2"], method="NaiveMean")

You also can plot genes with contour plot to see clearer about the distribution of genes:

[6]:, gene_symbols="GAPDH", contour=True,cell_alpha=0.5)

You can change the step_size to cut the range of display in contour

[7]:, 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]:, use_label="louvain")
[9]:, 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 or use to display subclusters within a cluster but with different color.

[10]:,use_label="louvain",show_subcluster=True,show_color_bar=False, list_clusters=['6','8'])
[11]:, use_label="louvain", cluster = '6')

Spatial trajectory plot

We provided to visualize PAGA graph that maps into spatial transcriptomics array.

[13]:, 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.

                   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 For many more visualisations, please see the stLearn Cell-cell interaction analysis tutorial.

[15]:, highlight_lrs=['GPC3_IGF1R'])
[16]:, "GPC3_IGF1R", "-log10(p_adjs)")
[17]:, "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

[18]:, use_label='cell_type'), 'cell_type', 'GPC3_IGF1R', figsize=(4,4))

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