bimberlabinternal / CellMembrane

An R package with wrappers and pipelines for single cell RNA-seq analysis
10 stars 3 forks source link

Add ClusteredDotPlot #264

Closed GWMcElfresh closed 1 month ago

GWMcElfresh commented 1 month ago

Hi all,

Greg solved a problem a while ago about the question "How do we cluster features in dot plots according to expression" for RIRA. This function is intended to be a post-FindMarkers() + marker triage step where you have a small-ish set of marker genes that discriminate your populations.

A full usage looks something like this:

Idents(seuratObj) <- "ClusterNames_0.2"
markers <- FindAllMarkers(seuratObj)

strong_markers <- markers[abs(markers$avg_log2FC) > 3 & abs(markers$pct.1 - markers$pct.2) > 0.25, "gene"]

ClusteredDotPlot(seuratObj, strong_markers, groupFields = "ClusterNames_0.2")

and yields:

image

I'm not sold on the color scheme by way of ComplexHeatmap, so I baked in a ggplotify() step, allowing posthoc color scaling to your satisfaction.

GWMcElfresh commented 1 month ago

I had the transpose ordering wrong, so this was scaling according to the count matrix, rather than the plot. I fixed that and added some verbosity to the figure legend since we can return several kinds of scaling:

scaling == 'column' : image scaling == 'row' : image scaling == 'none' & layer == 'data' : image AverageSeurat does some automatic transforms depending on which layer is requested (however, it always averages the counts slot, so we're good there). Since we probably want to support any layer, I think it's worth reporting.

Additionally, I supported the scale.data layer more completely. There are details in the comments, but AverageSeurat() won't include features in its scale.data layer simply because they're in the features argument: it looks for the features within the scale.data layer itself. So, one option is to re-call Seurat::ScaleData(), but I added a few checks to allow someone to encounter that issue semi-naturally and opt-in to that without immediately calling Seurat::ScaleData() on their object in memory.