scverse / scanpy

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

[Proposal] Integrate Marsilea to visualize AnnData #2444

Open Mr-Milk opened 1 year ago

Mr-Milk commented 1 year ago

Hi, thanks for developing such a fantastic framework for analyzing single-cell data, it really helps a lot in my research. I'm the developer of Heatgraphy, which is a python package to visualize multi-dimensional data using the x-layout system. You may think of it as python's version of complexHeatmap, but Heatgraphy can do much more.

Personally, I think Heatgraphy can help visualize the AnnData intuitively. Here is an example of visualization of the PBMC3K dataset using Heatgraphy. The structure of AnnData fits the structure of this visualization quite well. We can plot the .X as the heatmap, and other attributes in .obs/.var or .obsm/.varm as side plots.

Therefore, I propose adding a new API using Heatgraphy to help visualize AnnData.

If adding to sc.pl, the API may look like this:

sc.pl.heatgraphy(adata, left=[("cell_type", "color"), ("cell_type", "label")], right=[("gene_name", "label")])

If added as an extra class, the API can be more flexible and offer much more customization. It may look like this:

viz = AnnDataViz(adata)
viz.add_left(key="cell_type", plot="color", cmap="Set2")  # use a key from .obs and plot as color strip
viz.add_left(key="cell_type", plot="label")
viz.render()

It can also be applied to specific visualization for analysis.

Zethson commented 1 year ago

This sounds great! Please go for it and submit a minimal draft PR. Then we can iterate over it

ivirshup commented 4 months ago

Example of creating dot plot, which to my mind was a main missing feature. This should go great with sc.get.aggregate: https://github.com/Marsilea-viz/marsilea/issues/27#issuecomment-2022353426

Ideally, I think we could switch to marsilea for many plots for scanpy 2.0, replacing our existing BasePlot subclasses. This definitely requires more exploration first though.

@Mr-Milk, wdyt about including a how-to example in scanpy for Marsilea?

cc: @grst

Mr-Milk commented 4 months ago

It's great! Please let me know what to do from my side.

ivirshup commented 4 months ago

If you open a PR with a short notebook in https://github.com/scverse/scanpy-tutorials that would be a great place to start.

Mr-Milk commented 3 months ago

Hi, I've now implemented many scanpy plots using Marsilea in the notebook. Please let me know what you think of it and if you have any further questions or requests that could be useful for the community. Looking forward to integrating this!