Tutorial 3 - plot examples

Demo data for the tutorial can be downloaded from Zenodo.

import numpy as np
from matplotlib import pyplot as plt

import SplIsoFind
/athena/tilgnerlab/scratch/lim4020/2024_12_20_stereoseq_mousebrain/Reproducibility/SplIsoFind_GitHub/2022_08_15_PSIprediction/envs/SplIsoFind_test/lib/python3.9/site-packages/tqdm_joblib/__init__.py:4: TqdmExperimentalWarning: Using `tqdm.autonotebook.tqdm` in notebook mode. Use `tqdm.tqdm` instead to force console mode (e.g. in jupyter console)
  from tqdm.autonotebook import tqdm

Construct isoform matrix with relative expression

The create isoform matrix saves a sparse matrix, and corresponding index and column labels to the output folder.

NOTE: this is the same step as we do before calculating Moran’s I.

fn_allinfo = 'data/allinfo_ds.filtered.labeled.gz'
fn_CIDmap = 'data/sample1_barcodeToPos.CellID_ds.tsv.gz'
fn_adata = 'data/sample1_cellbin_adjusted.h5ad'
output = 'data/isoform_matrix'

SplIsoFind.pp.create_isoform_matrix(fn_allinfo,
                      fn_CIDmap,
                      fn_adata,
                      output)
Potentially interesting isoforms (total): 145
Potentially interesting isoforms (novel): 44

We read this sparse matrix to a dense dataframe so we can plot some examples

x_sparse, labels, isoforms = SplIsoFind.pp.load_sparse(input_dir = output)

Plot some examples

We can make a general plot

isoform = 'ENSMUST00000075316.10'

SplIsoFind.pl.spatial_hexplot_sparse(x_sparse, 
                                     labels, 
                                     isoforms,
                                     varName=isoform,
                                     imarray=None,
                                     celltype='', 
                                     hexsize=350)
plt.show()
../_images/5c56c04c0dd3bfc14081128173716874fced984a485f9dbda2714a8fa9345ea0.png

We can also plot the staining in the background

from PIL import Image
Image.MAX_IMAGE_PIXELS = 553190400

im_reg = Image.open('data/Sample1_ssDNA_regist.tif')
imarray = np.array(im_reg)
isoform = 'ENSMUST00000075316.10'

SplIsoFind.pl.spatial_hexplot_sparse(x_sparse, 
                                     labels, 
                                     isoforms,
                                     varName=isoform,
                                     imarray=imarray,
                                     celltype='', 
                                     hexsize=350)

plt.show()
../_images/17401efaf93c4c874d4ae95e2b8b51cf62c31206f7a9bbb3cdd1e48b0e04c7d5.png

Or we can zoom in a specific region (e.g. the hippocampus)

xlim1=8300
xlim2=14100
ylim1=4450
ylim2=14400

SplIsoFind.pl.spatial_hexplot_sparse(x_sparse, 
                                     labels, 
                                     isoforms,
                                     varName=isoform,
                                     imarray=imarray,
                                     celltype='', 
                                     hexsize=350,
                                     plot_lim=[xlim1, xlim2, ylim1, ylim2])

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

And focus on a specific cell type

SplIsoFind.pl.spatial_hexplot_sparse(x_sparse, 
                                     labels, 
                                     isoforms,
                                     varName=isoform,
                                     imarray=imarray,
                                     hexsize=350,
                                     plot_lim=[xlim1, xlim2, ylim1, ylim2],
                                     celltype='ExciteNeuron')
plt.show()
../_images/c5ccb00956d8e7241e3cae26c9aea0e6f864f282de9bab801f99caa26ae7814d.png

And we can even plot specific regions separately as in Figure 3h.

NOTE: these plots look slightly different from the paper since we downsampled the 4K dataset and not the AE dataset

SplIsoFind.pl.spatial_hexplot_sparse(x_sparse[(labels['subregion'] == 'DG_ML')], 
                                     labels[(labels['subregion'] == 'DG_ML')], 
                                     isoforms,
                                     varName=isoform,
                                     imarray=imarray,
                                     hexsize=350,
                                     plot_lim=[xlim1, xlim2, ylim1, ylim2],
                                     celltype='ExciteNeuron')
plt.show()

SplIsoFind.pl.spatial_hexplot_sparse(x_sparse[(labels['subregion'] == 'CA1_ML')], 
                                     labels[(labels['subregion'] == 'CA1_ML')], 
                                     isoforms,
                                     varName=isoform,
                                     imarray=imarray,
                                     hexsize=350,
                                     plot_lim=[xlim1, xlim2, ylim1, ylim2],
                                     celltype='ExciteNeuron')
plt.show()

SplIsoFind.pl.spatial_hexplot_sparse(x_sparse[(labels['subregion'] == 'CA3_ML')], 
                                     labels[(labels['subregion'] == 'CA3_ML')], 
                                     isoforms,
                                     varName=isoform,
                                     imarray=imarray,
                                     hexsize=350,
                                     plot_lim=[xlim1, xlim2, ylim1, ylim2],
                                     celltype='ExciteNeuron')
plt.show()
../_images/028b303a2fa90d2b9b8427a46e70d44fc6d15eadf5f10f5e703a8334ef97f4c7.png ../_images/ca3257292613a8cb1daeb3cc114c4934b51c3e7b63f7de352e790b9e0a7354cd.png ../_images/10f3be797aab7fe1aa11228bba655b32e57e9d9722678c8f71c65781fb68cf52.png