dtm2451 / dittoSeq

Color blindness friendly visualization of single-cell and bulk RNA-sequencing data
MIT License
190 stars 18 forks source link

Consider using `anno_mark` when `complex=TRUE` and `highlight.features` used in dittoHeatmap #101

Open j-andrews7 opened 2 years ago

j-andrews7 commented 2 years ago

This prevents labels from overlapping but would require a bit of re-working how the pheatmap call is made.

https://jokergoo.github.io/ComplexHeatmap-reference/book/heatmap-annotations.html#mark-annotation

Dragonmasterx87 commented 1 year ago

Hi guys is this implemented in dittoHeatmap ? if not @j-andrews7 do you have a workable example, using a pseudobulk object? I am having a bit of trouble with how the genes are being called on the y-axis.

j-andrews7 commented 1 year ago

I don't believe this has been implemented, but you can do it manually:

library(dittoSeq)

example(importDittoBulk, echo = FALSE)
scRNA <- setBulk(myRNA, FALSE)

# Pick a set of genes
genes <- getGenes(myRNA)[1:30]

# Get the genes we want to label.
label_genes <- c("gene1", "gene23", "gene12")

# Get the indices of said genes in the original object
locs <- match(label_genes, rownames(myRNA[genes,]))

# Make heatmap, be sure not to label rows (or columns, if doing it on those instead)
ht <- dittoHeatmap(myRNA, genes, show_rownames = FALSE, show_colnames = FALSE, complex = TRUE)

# Add the new annotation.
ht + rowAnnotation(mark = anno_mark(at = locs, labels = label_genes, which = "row"))
dtm2451 commented 1 year ago

Hey, it's not implemented, no. I'd also love to see a workable example if @j-andrews7 can share one. I've not used the feature before, so seeing an example would help me a lot for (potentially) building the implementation!

dtm2451 commented 1 year ago

crossed paths =)

j-andrews7 commented 1 year ago

I looked at the internals for this when I originally opened the issue, and I don't think it was too tough an addition, but it required more effort/time than I had.

Dragonmasterx87 commented 1 year ago

Gorgeous. Works great. Thanks Jared! Btw any easy way of controlling the font size of the genes? also guys I have a bit of a different issue as well.....sorry should probably make another issue but anyway.....

The way I am calling out gaps is using the gaps_col func...which is fine, but it feels a bit manual, there should be a way where we can extract metadata from the original object and use it to set boundaries or atleast locs like Jared outlines.....also the gaps_row func doesnt work appropriately for me, im still trying to figure out why. Will update you later.

Heres my code FYI:

# Mark genes
label_genes <- c("INS", "SST", "GCG")

dittoHeatmap(
  object = combined_processed_rna,#(subset(combined_processed_rna, idents = c("alpha"))),
  genes = allgenes_unique,
  # metas = NULL,
  # cells.use = NULL,
  annot.by = c("ancestry", "sex", "source", "disease", "celltype"),
  #annot.by = c("lib", "sex", "source"),
  order.by = c("celltype"),
  # main = NA,
  # cell.names.meta = NULL,
  # assay = .default_assay(object),
  # slot = .default_slot(object),
  # swap.rownames = NULL,
  heatmap.colors = colorRampPalette(c("dodgerblue", "white", "red3"))(50),
  # scaled.to.max = FALSE,
  # heatmap.colors.max.scaled = colorRampPalette(c("white", "red"))(25),
  # annot.colors = c(dittoColors(), dittoColors(1)[seq_len(7)]),
  # annotation_col = NULL,
  annotation_colors = complexAnolist,
  # data.out = FALSE,
  #right_annotations = rowAnnotation(foo = anno_mark(at = c(1), labels = c("HHEX"))),
  # show_colnames = isBulk(object),
  # show_rownames = TRUE,
  # scale = "row",
  cluster_row = FALSE,
  # cluster_cols = FALSE,
  # border_color = NA,
  # legend_breaks = NA,
  # drop_levels = FALSE,
  breaks=seq(-2, 2, length.out=50),
  complex = TRUE,
  #column_km = 1,
  use_raster = TRUE,
  #column_split = combined_processed_rna$celltype,
  #border_color = "black",
  gaps_col = c(52, 104, 156, 208, 260, 311, 343, 379, 431, 483, 535, 587, 640, 690, 742, 793),
  #gaps_row = c(10, 46, 198)
) + rowAnnotation(mark = anno_mark(at = match(label_genes, rownames(combined_processed_rna[genes,])), labels = label_genes, which = "row"))

#Output

image

j-andrews7 commented 1 year ago

@Dragonmasterx87 You can change the font size with the labels_gp param in the anno_mark function, e.g:

ht + rowAnnotation(mark = anno_mark(at = locs, labels = label_genes, which = "row", labels_gp = list(cex=0.7)))

Dragonmasterx87 commented 1 year ago

haha...I was about to message, I figured it out as well. Thanks, a lot @j-andrews7 .....I was calling it incorrectly in rowAnnotation..... it's been a long day. Thank you again!

#Also for those who want to edit the links:
dittoHeatmap() + rowAnnotation(mark = anno_mark(at = match(label_genes, 
                                              rownames(combined_processed_rna[genes,])), 
                                   labels = label_genes, 
                                   which = "row",
                                   labels_gp = list(cex=0.3),
                                   link_width = unit(4, "mm"), link_height = unit(4, "mm"),
                                   padding = 0.1))

fyi I figured out my gaps issue, it was actually a raster res issue. Cheers!

🐉