scverse / scanpy

Single-cell analysis in Python. Scales to >1M cells.
https://scanpy.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.87k stars 595 forks source link

Figures related to rankings and heatmap could be transposed. #349

Open Xparx opened 5 years ago

Xparx commented 5 years ago

These are some suggestions regarding visualization defaults.

Working with the ranknings plot i realized that it would be much easier to read if the figure where transposed/rotated so that gene names could be read per line rather than per columns. This would also scale better if one wishes to plot more than 10-30 genes. There is no inherent information on the y axis that could not be layed out on the x axis.

I also ran in to this format when using the heatmap plotting. Gene names are on the columns rather than rows resulting in a thin matrix and hard to read gene names. As the figure is constructed by using several axis one could transpose the figure having the gene names to the right colorbar on the right and groupings below or ontop of the heatmap. As one is most interested in a dendrogram on the cells (I think?) it could get a nice space on top.

falexwolf commented 5 years ago

@fidelram should be the expert for this... :smile:

fidelram commented 5 years ago

With respect to the heatmap, indeed it is possible to transpose the matrix. Currently, this option is only available for stacked_violin. I thought about adding this option to other plots like heatmap, matrixplot and dotplot but I have not find the time and it is always possible to save the figure and rotate it so it has low priority for me. The changes are not as trivial as simply rotating the matrix as all other elements need to be adjusted.

On Wed, Nov 7, 2018 at 3:03 AM Alex Wolf notifications@github.com wrote:

@fidelram https://github.com/fidelram should be the expert for this... 😄

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/theislab/scanpy/issues/349#issuecomment-436477272, or mute the thread https://github.com/notifications/unsubscribe-auth/AEu_1b_dlMN1mihuJIbXg2lPmMJvgqGgks5usj-FgaJpZM4YRQ7g .

Xparx commented 5 years ago

I made a hack solution for this to have something that would work for me. I put it here: https://gist.github.com/Xparx/33026da63dabb1c200b2602bbae0b95c

It's not defensively coded so it might bug out without proper input.

fidelram commented 5 years ago

Thanks! Can you post an image to get an idea of your solution?

Xparx commented 5 years ago

Sure. Here is one example of my output image

4hpf

fidelram commented 5 years ago

Thanks. I will do a PR soon which allows the heatmap and matrixplot functions to be rotated.

Xparx commented 5 years ago

As this issue is not closed I'll add a question here.

Is it possible, or if not could it be added, that the cells in the heatmaps are sorted within the groupby variables. Either by pseudotime if availible or just clustered simply by hierarchical clustering. This could add a more visually and intuitive pleasing ordering of cells.

For example as in my figure above the groupby miss some property of the data with pattern over cells. If the cell ordering was random or default this pattern could not be seen.

fidelram commented 5 years ago

Should be possible to do what you want.

sc.pl.heatmap basically plots a pandas DataFrame that has as columns the selected gene names, and as rows the cells with an index based on the categories.

You can modify this dataframe (called obs_tidy) to have the ordering that you want.

This is the line in the current code that returns the dataframe: https://github.com/theislab/scanpy/blob/master/scanpy/plotting/_anndata.py#L1098

Gpasquini commented 5 years ago

Again, as this issue is not closed,

is it possible to do hierarchical clustering on the genes while plotting the heamap? By grouping the genes according their expression in the clusters would be a lot informative.