Skip to content

Marker-gene-guided dimensionality reduction (GDR)

GDR: marker Gene-guided Dimensionality Reduction

import scanpy as sc
import os
from matplotlib import rcParams
import time
import warnings
warnings.simplefilter(action='ignore', category=FutureWarning)
import piaso
import cosg
sc.set_figure_params(dpi=96,dpi_save=300, color_map='viridis',facecolor='white')
rcParams['figure.figsize'] = 4, 4
rcParams['font.sans-serif'] = "Arial"
rcParams['font.family'] = "Arial"
sc.settings.verbosity = 3
sc.logging.print_header()

Load the data

We will be using a Multiome RNA dataset obtained from cortex at P57.

adata = piaso.data.load_dataset("adult_cortex_multiome_rna")
adata
adata.X=adata.layers['log1p'].copy()

INFOG normalization

%%time
piaso.tl.infog(adata,
layer='raw',
n_top_genes=3000,)

Visualize with PCA-based UMAP

First, we will use a standard PCA-based UMAP to visualize the batches and cell types in the dataset. This helps in assessing the presence of batch effects.

sc.pp.neighbors(adata,
use_rep='X_pca',
n_neighbors=15,
random_state=10,
knn=True,
method="umap")
sc.tl.umap(adata)
sc.pl.umap(adata,
color=['Sample','CellTypes'],
palette=piaso.pl.color.d_color4,
cmap=piaso.pl.color.c_color4,
size=10,
ncols=1,
frameon=False)
output

The UMAP plot clearly shows batch effects in the dataset.

Dimensionality reduction with GDRParallel

In this turorial we will show how GDR works when only batch information is available and clusters or cell type informations isn’t available. In this case, runGDR clusters the data and infers the groups.

%%time
piaso.tl.runGDRParallel(adata,
batch_key='Sample',
groupby=None,
n_gene=20,
mu=10,
resolution=3.0,
layer='infog',
infog_layer='raw',
score_layer='infog',
scoring_method='piaso',
use_highly_variable=True,
n_highly_variable_genes=5000,
n_svd_dims=50,
key_added='X_gdr',
max_workers=32,
calculate_score_multiBatch=False,
verbosity=0)

Visualize GDR results with UMAPs

%%time
sc.pp.neighbors(adata,
use_rep='X_gdr',
n_neighbors=15,
random_state=10,
knn=True,
method="umap")
sc.tl.umap(adata)
sc.pl.umap(adata,
color=['Sample','CellTypes'],
palette=piaso.pl.color.d_color4,
cmap=piaso.pl.color.c_color4,
size=10,
ncols=1,
frameon=False)
output

GDR effectively integrates batches and separates cell types using only dimensionality reduction, without additional integration methods.