我正在使用 ComplexHeatmap 中的 oncoprint() 函数,并且一直看到此警告:
“您cell_fun
为超过 100 行或列的热图定义,绘制起来可能非常慢。考虑使用矢量化版本
layer_fun
。”
根据作者的指南,cell_fun 和 layer_fun 与同一包中的 Heatmap() 函数相关(章节链接)。该指南没有提及关于 oncoprint() 的 layer_fun。
我浏览了 github,我看到当输入矩阵大于 100x100 时会发生此错误。我看到 layer_fun 也以某种方式参与了 oncoprint() 函数,但我不明白它是如何参与的文档在 oncoprint 中提到 layer_fun。显然,它与图形表示“函数列表”变量 alter_fun 相关联。
我不明白在 oncoprint() 函数中 alter_fun 和 layer_fun 是如何相互关联的。但是,我使用了热图注释(参见变量 ha_all)——这是否会导致 layer_fun 警告(我不这么认为)。
以下是我的问题:矢量化 alter_fun 是什么意思,我该怎么做?layer_fun 与这一切有关吗?将来,我的输入矩阵会更大,所以为了速度,我需要对这些变量进行向量化。
# Toy Example, Big Data ---------------------------------------
# Colors for Each Annotation (also used to randomly create toy data)
toy_gender <- c("Male" = "blue", "Female" = "pink")
toy_grade <- c("1" = "white", "2" = "gray", "3" = "dark gray", "4"="black")
toy_mol <- c("Glioma " = "yellow",
"Meningioma" = "black",
"Ependymoma" = "pink")
toy_col <- # alteration type
c(
"arm_level_gain" = "blue",
"wt" = "beige",
"missense" = "pink",
"arm_level_loss" = "red",
"damaging_mutation" = "purple"
)
toym <- #150 x 150
data.frame("genes" = c(1:150))
the_cols <- # each sample will be a column in matrix
rep("sample", 150) %>% paste(., c(1:150), sep="")
toym$genes <- paste("g", toym$genes, sep="")
for (i in the_cols){ #create cols: each is one sample
# fill with random alts data
toym[, i] <- sample( (names(toy_col)) , 150, replace = TRUE)
}
#label rows as gene name, then rm sample col
row.names(toym)<- toym$genes
toym <- toym[,2:length(toym)]
toym <- as.matrix(toym)
# Create Annotation Data Frame
toydf <- data.frame( "Samples" = colnames(toym) )
toydf$Molecular <- sample( names(toy_mol), 150, replace=TRUE )
toydf$Gender <- sample( names(toy_gender), 150, replace=TRUE )
toydf$Grade <- sample( names(toy_grade), 150, replace=TRUE )
row.names(toydf) <- toydf$Samples
toydf <- toydf[, 2:4]
ha_all = HeatmapAnnotation( #constructor function-- read complexheatmap documentation
df = toydf,
col = list(Molecular = toy_mol,
Grade = toy_grade,
Gender = toy_gender),
na_col = "grey"
)
# Create alter_fun list of functions
toy_alter_fun = list(
background = function(x, y, w, h) {
grid.rect(x, y, w-unit(0.5, "mm"), h-unit(0.5, "mm"),
gp = gpar(fill = "beige", col = NA))
},
"focal_gain" = function(x, y, w, h) {
grid.rect(x, y, w-unit(0.5, "mm"), h-unit(0.5, "mm"),
gp = gpar(fill = toy_col["focal_gain"], col = NA))
},
"damaging_mutation" = function(x, y, w, h) {
grid.rect(x, y, w-unit(0.5, "mm"), h-unit(0.5, "mm"),
gp = gpar(fill = toy_col["damaging_mutation"], col = NA))
},
# big blue
#"wt" = function(x, y, w, h) {
# grid.rect(x, y, w-unit(0.5, "mm"), h-unit(0.5, "mm"),
# gp = gpar(fill = "beige", col = NA))
#},
"missense" = function(x, y, w, h) {
grid.rect(x, y, w-unit(0.5, "mm"), h-unit(0.5, "mm"),
gp = gpar(fill = toy_col["missense"], col = NA))
},
# bug red
"rearrangement" = function(x, y, w, h) {
grid.rect(x, y, w-unit(0.5, "mm"), h-unit(0.5, "mm"),
gp = gpar(fill = toy_col["rearrangement"], col = NA))
},
# # small green
"focal_loss" = function(x, y, w, h) {grid.rect(x, y, w*0.9, h*0.4,
gp = gpar(fill = toy_col["focal_loss"], col = NA))
},
# # small green
"not_covered" = function(x, y, w, h) {
grid.rect(x, y, w-unit(0.5, "mm"), h-unit(0.5, "mm"),
gp = gpar(fill = toy_col["not_covered"], col = NA))
}, # small green
"arm_level_loss" = function(x, y, w, h) {grid.rect(x, y, w*0.9, h*0.4,
gp = gpar(fill = toy_col["arm_level_loss"], col = NA))
}, # small green
"arm_level_gain" = function(x, y, w, h) {grid.rect(x, y, w*0.9, h*0.4,
gp = gpar(fill = toy_col["arm_level_gain"], col = NA))
}, # small green
"wt" = function(x, y, w, h) {grid.rect(x, y, w*0.9, h*0.4,
gp = gpar(fill = toy_col["wt"], col = NA))
} # small green
)
#make sure toym and toydf are ordered by samples (and in same order as each other)
# call oncoprint function
pdf("Toy Oncoprint.pdf", width = 16, height = 8)
oncoPrint(
toym,
show_pct = FALSE,
alter_fun = toy_alter_fun,
alter_fun_is_vectorized = FALSE,
col = toy_col,
top_annotation = ha_all,
row_names_side = "left",
column_split = toydf$Molecular,
#heatmap_legend_param = heatmap_legend_param,
)
dev.off()