Palantir icon indicating copy to clipboard operation
Palantir copied to clipboard

plot_gene_trend_clusters

Open jieteliang opened this issue 5 months ago • 3 comments

Your plantir is very useful, but I wonder why there is no API for gene clustering heatmap. Maybe I am too lazy.

jieteliang avatar Jul 03 '25 08:07 jieteliang

Try seaborns clustermap, e.g., for the Monocyte branch of the tutorial notebook:

import seaborn as sns

mask = ad.varm["gene_trends_Mono"].var(axis=1) > 0.05

g = sns.clustermap(
    ad.varm["gene_trends_Mono"].loc[mask],
    cmap="Spectral_r",
    z_score=0,
    row_cluster=True,  # Cluster genes
    col_cluster=False,  # Don't cluster pseudotime
    figsize=(10, 8),
    cbar_kws={"label": "Expression"},
    xticklabels=False,  # Hide labels (too many)
    yticklabels=False,
)

g.ax_heatmap.set_xlabel("Pseudotime")
g.ax_heatmap.set_ylabel("Genes")
g.ax_heatmap.set_title("Monocyte Branch")

plt.show()
Image

katosh avatar Jul 05 '25 21:07 katosh

Thank you very much for your answer.At the same time, I have a confusion about gene trends when running the software.I have two ways of preprocessing input data. sc.pp.normalize_total(adata, target_sum=1e4) sc.pp.log1p(adata) sc.pp.scale(adata, max_value=10)

Image

sc.pp.normalize_total(adata, target_sum=1e4) sc.pp.log1p(adata)

Image

I want to know which result or process is accurate, or how to interpret these two results

jieteliang avatar Jul 06 '25 15:07 jieteliang

When plotting gene trends, only cells of specific branch are used. This is explained, e.g., in the tutorial notebook. The scaling you do in your first example, however, scales the gene expression to a specific variance across the whole dataset. This may have unexpected effects. E.g., if most of the gene's variability happens outside of the branch you are looking at, then it will appear flat within the branch.

I cannot give you an interpretation based on the information provided, and what is more accurate may depend on the question you want to answer. I would recommend visualizing stabilized/imputed expression across the whole dataset, and making sure the correct cells are selected for branch you are investigating.

katosh avatar Jul 07 '25 01:07 katosh