Skip to content

Commit

Permalink
feat: custom colors for heatmap annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
escauley committed Feb 21, 2024
1 parent 058c5e5 commit 5a17b9f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
31 changes: 29 additions & 2 deletions R/heatmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
#' @param heatmap.color Colors of heatmap to match breaks above
#' (Default: colorRampPalette(
#' c("blue", "white", "red"))(120))
#' @param anno.colors A list of named vectors that assigns the levels of each
#' annotation to a specific color
#'
#' @importFrom NanoStringNCTools assayDataApply
#' @importFrom Biobase assayDataElement
Expand All @@ -74,7 +76,8 @@ heatMap <- function(
clustering.distance.cols = "correlation",
annotation.row = NA,
breaks.by.values = seq(-3, 3, 0.05),
heatmap.color = colorRampPalette(c("blue", "white", "red"))(120)) {
heatmap.color = colorRampPalette(c("blue", "white", "red"))(120),
annotation.colors = NULL) {

# norm.method must be either quant or neg
if((norm.method != "quant") && (norm.method != "neg")){
Expand Down Expand Up @@ -119,6 +122,9 @@ heatMap <- function(
anno.col <-
pData(object)[, annotation.col]

# annotation colors
anno.colors <- annotation.colors

# make plot
p <- pheatmap(
plot.genes[1:ngenes, ],
Expand All @@ -134,9 +140,30 @@ heatMap <- function(
clustering_distance_cols = clustering.distance.cols,
breaks = breaks.by.values,
color = col.palette,
annotation_col = anno.col
annotation_col = anno.col,
annotation_colors = anno.colors
)

p <- pheatmap(
plot.genes[1:ngenes, ],
main = "Clustering high CV genes",
scale = scale.by.row.or.col,
show_rownames = show.rownames,
show_colnames = show.colnames,
border_color = NA,
clustering_method = clustering.method,
cluster_rows = cluster.rows,
cluster_cols = cluster.cols,
clustering_distance_rows = clustering.distance.rows,
clustering_distance_cols = clustering.distance.cols,
breaks = breaks.by.values,
color = col.palette,
annotation_col = anno.col,
annotation_colors = anno.colors
)



## gene.df converts to data frame
gene.df <- as.data.frame(plot.genes)

Expand Down
2 changes: 2 additions & 0 deletions R/qc_preprocessing.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ qcProc <- function(object,
## settings ####
## shift counts (useDALogic=TRUE adds 1 only to 0s)
object <- shiftCountsOne(object, useDALogic = shift.counts.zero)


## list of user-defined segment QC params for annotations and variables
## expected to be always present in the input object
qc.params <-
Expand Down
9 changes: 8 additions & 1 deletion vignettes/Integration_Test_Kidney.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@ qc.output <- qcProc(object = sdesign.list$object,

```{r Clustering high CV Genes, echo=TRUE}
anno.colors = list(
class = c(DKD = "yellow", normal = "orange"),
region = c(glomerulus = "purple", tubule = "red"),
segment = c(GeometricSegment = "blue", neg = "coral", PanCK = "green")
)
heatmap.output <- heatMap(object = unsupervised.output$object,
ngenes = 200,
scale.by.row.or.col = "row",
Expand All @@ -209,7 +215,8 @@ qc.output <- qcProc(object = sdesign.list$object,
annotation.col = c("class", "segment", "region"),
breaks.by.values = seq(-3, 3, 0.05),
heatmap.color = colorRampPalette(c("blue", "white", "red"))(120),
norm.method = "quant")
norm.method = "quant",
annotation.colors = anno.colors)
print(heatmap.output$plot)
Expand Down

0 comments on commit 5a17b9f

Please sign in to comment.