Closed JesseRop closed 2 years ago
Hi @JesseRop ,
you can use g.compute_drivers(..., use_raw=True)
and it will use adata.raw
for the driver computation - you shouldn't really pass the .raw
object to the kernel, as adata.raw
usually contains filtered/normalized, but not scaled (or otherwise further processed) data; please see an example snippet below.
Furthermore, scv.pp.filter_genes_dispersion expects not log-normalized data, scv.pp.filter_and_normalize is what I usually prefer for quick filtering/normalization.
import scanpy as sc
import scvelo as scv
import cellrank as cr
from cellrank.tl.kernels import VelocityKernel, ConnectivityKernel
from cellrank.tl.estimators import GPCCA
adata = cr.datasets.pancreas()
scv.pp.filter_and_normalize(adata, min_shared_counts=20, n_top_genes=2000, subset_highly_variable=False)
adata.raw = adata.copy()
adata[:, adata.var['highly_variable']].copy()
sc.tl.pca(adata)
sc.pp.neighbors(adata, n_pcs=30, n_neighbors=30)
scv.pp.moments(adata, n_pcs=None, n_neighbors=None)
scv.tl.velocity(adata, mode="stochastic")
scv.tl.velocity_graph(adata)
vk = VelocityKernel(adata).compute_transition_matrix()
ck = ConnectivityKernel(adata).compute_transition_matrix()
combined_kernel = 0.8 * vk + 0.2 * ck
g = GPCCA(combined_kernel)
g.compute_schur()
g.compute_macrostates(n_states=3, cluster_key="clusters")
g.set_terminal_states_from_macrostates()
g.compute_absorption_probabilities()
# important: `use_raw=True`
df = g.compute_lineage_drivers(lineages="Alpha", use_raw=True)
# `df` is also present in `adata.raw.varm['terminal_lineage_drivers']`
g.plot_lineage_drivers("Alpha", use_raw=True)
Thanks @michalk8, I assume this is solved and I'm closing the issue.
Yess! this is solved. Thanks @Marius1311 and @michalk8
Kindly advise on how to include all high quality genes i.e those in adata.raw.X for the estimation of driver genes or include a feature to support this.
In the workflow below, I'm not able to include all genes in the estimation of driver genes when I use adata.raw.to_adata() as the expression matrix.
I have tried the following work flow but it seems to error out at the
ck_raw = ConnectivityKernel(adata.raw.to_adata()).compute_transition_matrix()
probably due to adata.raw.to_adata() throwing out the .obsp slotKindly advice on the best way to include all the genes in detections of drivers. Thanks