dpeerlab / Palantir

Single cell trajectory detection
https://palantir.readthedocs.io
GNU General Public License v2.0
203 stars 45 forks source link

Adjust x-axis for pseudotime gene expression plots #134

Closed andrewsong777 closed 5 months ago

andrewsong777 commented 5 months ago

Hello, I am trying to adjust the x-axis for the gene expression plots across pseudotimes: genes = ['BASP1', 'CD9', 'DLG2', 'FNBP1', 'FRMD3', 'IL11RA', 'IQCE', 'KCNQ3', 'TOX2', 'BSG', 'CCDC125', 'GABRB3', 'GNB2L1', 'HAPLN4', 'HEBP2', 'HSD17B12']

ISGF10

fig, ax = palantir.plot.plot_gene_trends(ad, genes) ax.set_xlabel('Pseudotime') # Set the x-axis label ax.set_xlim([0, 0.45]) # Set the desired x-axis limits plt.show()

Screenshot 2024-02-20 at 2 49 30 PM

My error message is pasted.

katosh commented 5 months ago

Hello @andrewsong777,

Thank you for bringing this to our attention. The plot.plot_gene_trends function indeed returns a figure object, and the axes within it are generated iteratively in a loop. Consequently, direct access to the axes for modifications like setting the x-axis label isn't provided in a straightforward manner. However, you can still access and manipulate the axes by using the fig.get_axes() method on the returned figure object. Here's how you can set the x-axis label to "Pseudotime" for each subplot:

import matplotlib.pyplot as plt
import palantir

fig = palantir.plot.plot_gene_trends(ad, genes)
for ax in fig.get_axes():
    ax.set_xlabel("Pseudotime")

# Adjust the layout to prevent any overlap
plt.tight_layout()

plt.show()

This approach ensures that each subplot within the figure has its x-axis labeled as "Pseudotime", and plt.tight_layout() adjusts the spacing to make the plot more readable. Let me know if you have any further questions or issues!

andrewsong777 commented 5 months ago

Thank you! What are the units for the y-axis? Is it average read counts?

katosh commented 4 months ago

I would just refer to it as a gene-expression level. Its values can be compared within a gene but its unit is hard to pin down and depends a lot on its processing, e.g., the normalization strategy, and the pseudo-count in the log-transformtion.

To compute the trend line we use a Gaussian Process to find the "best" smooth function that could have generated the measured gene-expression levels under some assumptions about the noise of these measurements sigma and the smoothness of this function ls. We use Mellon's FunctionEstimator to find this function (also s. this tutorial). Unlike simple moving averages, this approach can predict values outside the observed range, accommodating for potential peaks between data points.