ComplexHeatmap复杂热图绘制学习——7.OncoPrint

OncoPrint

OncoPrint是一种通过热图可视化多个基因组变化的方法。这里的 ComplexHeatmap包提供了一个制作 oncoPrints的函数oncoPrint()。除了cBioPortal提供的默认样式外,热图两侧还有额外的条形图,显示每个样本和每个基因的不同改变的数量。此外,借助ComplexHeatmap的功能 ,您可以将 oncoPrints 与其他热图和注释连接起来,以对应更多类型的信息。

7.1 常规设置

7.1.1 输入数据格式

输入数据有两种不同的格式。第一个表示为一个矩阵,其中每个值都可以包含复杂字符串形式的多个更改。在下面的例子中,'s1' 中的 'g1' 有两种类型的改变,分别是 'snv' 和 'indel'。

mat = read.table(textConnection(
"s1,s2,s3
g1,snv;indel,snv,indel
g2,,snv;indel,snv
g3,snv,,indel;snv"), row.names = 1, header = TRUE, sep = ",", stringsAsFactors = FALSE)
mat = as.matrix(mat)
mat
##    s1          s2          s3         
## g1 "snv;indel" "snv"       "indel"    
## g2 ""          "snv;indel" "snv"      
## g3 "snv"       ""          "indel;snv"

在这种情况下,我们需要定义一个函数来从这些长字符串中提取不同的更改类型。这种函数的定义总是很简单,它接受复杂的字符串并返回一个改变类型的向量。

对于mat,我们可以将函数定义为:

get_type_fun = function(x) strsplit(x, ";")[[1]]
get_type_fun(mat[1, 1])
## [1] "snv"   "indel"
get_type_fun(mat[1, 2])
## [1] "snv"

因此,如果更改编码为snv|indel,则可以将函数定义为function(x) strsplit(x, "|")[[1]]。这个自定义函数被分配给oncoPrint()中的get_type参数。

由于在大多数情况下,分隔符只是单个字符,如果分隔符在 中;:,|,则oncoPrint()自动吐出更改字符串,这样您就不需要get_typeoncoPrint()函数中明确指定。

对于一个样本中的一个基因,由于不同的变异类型可能会被绘制到热图中的同一个网格中,我们需要通过向alter_fun参数提供自定义函数列表来定义如何添加图形。这里如果图形没有透明度,添加图形的顺序很重要。在以下示例中,先绘制 snv,然后绘制 indel。您可以看到 indels的矩形(0.4*h)实际上比snvs 的矩形(0.9*h)小,因此如果它们在同一网格中,您可以可视化 snvs 和 indels。函数列表的名称应对应于更改类型(此处为snvindel)。

对于自定义图形函数( alter_fun中的函数,应该有四个参数,分别是oncoPrint上网格的位置(xy),以及网格的宽度和高度(wh,以npc单位测量)。四个参数的值从oncoPrint()自动发送到这些函数。

更改不同的颜色在col中定义。它应该是一个命名向量,其名称对应于更改类型。它用于生成条形图。

col = c(snv = "red", indel = "blue")
oncoPrint(mat,
    alter_fun = list(
        snv = function(x, y, w, h) grid.rect(x, y, w*0.9, h*0.9, 
            gp = gpar(fill = col["snv"], col = NA)),
        indel = function(x, y, w, h) grid.rect(x, y, w*0.9, h*0.4, 
            gp = gpar(fill = col["indel"], col = NA))
    ), col = col)
image

您可以看到条形图中的顺序也对应于alter_fun中定义的顺序 。图例中的图形基于alter_fun中定义的函数。

如果您对如何生成矩阵感到困惑,还有第二种方法。第二种类型的输入数据是一个矩阵列表,其中每个矩阵都包含表示更改是否不存在或存在的二进制值。该列表应具有与更改类型相对应的名称。

mat_list = list(snv = matrix(c(1, 0, 1, 1, 1, 0, 0, 1, 1), nrow = 3),
                indel = matrix(c(1, 0, 0, 0, 1, 0, 1, 0, 0), nrow = 3))
rownames(mat_list$snv) = rownames(mat_list$indel) = c("g1", "g2", "g3")
colnames(mat_list$snv) = colnames(mat_list$indel) = c("s1", "s2", "s3")
mat_list
## $snv
##    s1 s2 s3
## g1  1  1  0
## g2  0  1  1
## g3  1  0  1
## 
## $indel
##    s1 s2 s3
## g1  1  0  1
## g2  0  1  0
## g3  0  0  0

oncoPrint()期望所有矩阵mat_list具有相同的行名和列名。

传递mat_listoncoPrint()

# now you don't need `get_type`
oncoPrint(mat_list,
    alter_fun = list(
        snv = function(x, y, w, h) grid.rect(x, y, w*0.9, h*0.9, 
            gp = gpar(fill = col["snv"], col = NA)),
        indel = function(x, y, w, h) grid.rect(x, y, w*0.9, h*0.4, 
            gp = gpar(fill = col["indel"], col = NA))
    ), col = col)
image

在本章的后续部分,我们仍然使用单矩阵形式mat 来指定输入数据。

7.1.2 定义alter_fun()

alter_fun是一个逐层添加图形的函数列表(即首先绘制 snv,然后绘制indel)。也可以通过指定alter_fun为单个函数以逐个网格样式添加图形。与函数列表的不同之处在于现在alter_fun应该接受第五个参数,它是一个逻辑向量。该逻辑向量显示当前样本中的当前基因是否存在不同的改变。

让我们假设在一个网格中只有 snv 事件,那么对于这个网格v是:

##   snv indel 
##  TRUE FALSE
oncoPrint(mat,
    alter_fun = function(x, y, w, h, v) {
        if(v["snv"]) grid.rect(x, y, w*0.9, h*0.9, # v["snv"] is a logical value
            gp = gpar(fill = col["snv"], col = NA))
        if(v["indel"]) grid.rect(x, y, w*0.9, h*0.4, # v["indel"] is a logical value
            gp = gpar(fill = col["indel"], col = NA))
    }, col = col)
image

如果alter_fun设置为单一功能,定制可以更加灵活。在下面的例子中,蓝色矩形在不同的网格中可以有不同的高度。

oncoPrint(mat,
    alter_fun = function(x, y, w, h, v) {
        n = sum(v)  # how many alterations for current gene in current sample
        h = h*0.9
        # use `names(which(v))` to correctly map between `v` and `col`
        if(n) grid.rect(x, y - h*0.5 + 1:n/n*h, w*0.9, 1/n*h, 
            gp = gpar(fill = col[names(which(v))], col = NA), just = "top")
    }, col = col)
image

以下是alter_fun使用三角形的复杂示例:

oncoPrint(mat,
    alter_fun = list(
        background = function(x, y, w, h) {
            grid.polygon(
                unit.c(x - 0.5*w, x - 0.5*w, x + 0.5*w), 
                unit.c(y - 0.5*h, y + 0.5*h, y - 0.5*h),
                gp = gpar(fill = "grey", col = "white"))
            grid.polygon(
                unit.c(x + 0.5*w, x + 0.5*w, x - 0.5*w), 
                unit.c(y + 0.5*h, y - 0.5*h, y + 0.5*h),
                gp = gpar(fill = "grey", col = "white"))
        },
        snv = function(x, y, w, h) {
            grid.polygon(
                unit.c(x - 0.5*w, x - 0.5*w, x + 0.5*w), 
                unit.c(y - 0.5*h, y + 0.5*h, y - 0.5*h),
                gp = gpar(fill = col["snv"], col = "white"))
        },
        indel = function(x, y, w, h) {
            grid.polygon(
                unit.c(x + 0.5*w, x + 0.5*w, x - 0.5*w), 
                unit.c(y + 0.5*h, y - 0.5*h, y + 0.5*h),
                gp = gpar(fill = col["indel"], col = "white"))
        }
    ), col = col)
image

在某些情况下,您可能需要alter_fun定义许多不同类型。如果你不知道你的视觉效果alter_fun,您可以使用 test_alter_fun()来测试你的alter_fun。在以下示例中,我们定义了七个更改函数:

alter_fun = list(
    mut1 = function(x, y, w, h) 
        grid.rect(x, y, w, h, gp = gpar(fill = "red", col = NA)),
    mut2 = function(x, y, w, h) 
        grid.rect(x, y, w, h, gp = gpar(fill = "blue", col = NA)),
    mut3 = function(x, y, w, h) 
        grid.rect(x, y, w, h, gp = gpar(fill = "yellow", col = NA)),
    mut4 = function(x, y, w, h) 
        grid.rect(x, y, w, h, gp = gpar(fill = "purple", col = NA)),
    mut5 = function(x, y, w, h) 
        grid.rect(x, y, w, h, gp = gpar(fill = NA, lwd = 2)),
    mut6 = function(x, y, w, h) 
        grid.points(x, y, pch = 16),
    mut7 = function(x, y, w, h) 
        grid.segments(x - w*0.5, y - h*0.5, x + w*0.5, y + h*0.5, gp = gpar(lwd = 2))
)
test_alter_fun(alter_fun)
## `alter_fun` is defined as a list of functions.
## Functions are defined for following alteration types:
##   mut1, mut2, mut3, mut4, mut5, mut6, mut7
image

对于变异类型的组合,test_alter_fun()随机抽取其中的一些。

test_alter_fun()既可用作alter_fun列表,也可用作单个函数。

7.1.3 背景

如果alter_fun指定为列表,则元素的顺序控制添加图形的顺序。有一个特殊元素称为background定义如何绘制背景,它应该始终作为alter_fun列表中的第一个元素。在以下示例中,背景颜色更改为带边框的浅绿色。

oncoPrint(mat,
    alter_fun = list(
        background = function(x, y, w, h) grid.rect(x, y, w, h, 
            gp = gpar(fill = "#00FF0020")),
        snv = function(x, y, w, h) grid.rect(x, y, w*0.9, h*0.9, 
            gp = gpar(fill = col["snv"], col = NA)),
        indel = function(x, y, w, h) grid.rect(x, y, w*0.9, h*0.4, 
            gp = gpar(fill = col["indel"], col = NA))
    ), col = col)
image

或者只是删除背景(不要将其设置为NULLbackground 直接设置为NULL意味着使用默认的背景样式为灰色):

oncoPrint(mat,
    alter_fun = list(
        background = function(...) NULL,
        snv = function(x, y, w, h) grid.rect(x, y, w*0.9, h*0.9, 
            gp = gpar(fill = col["snv"], col = NA)),
        indel = function(x, y, w, h) grid.rect(x, y, w*0.9, h*0.4, 
            gp = gpar(fill = col["indel"], col = NA))
    ), col = col)
image

7.1.4 复杂可变类型

当整合来自多个分析结果的信息时,很容易有更多不同的变更类型。有时很难设计图形并为其分配不同的颜色(例如, 请参阅此链接中的绘图. 另一方面,在这些蚀变类型中,有更重要的蚀变类型的主要类别,而次要类别则不太重要。例如,我们可能有“intronic snv”、“exonic snv”、“intronic indel”和“exonic indel”的改变类型。实际上我们可以将它们分为两类,其中“snv/indel”更重要,属于一级类,“intronic/exonic”不太重要,属于二级类。回顾 oncoPrint,对于“intronic snv”和“exonic snv”,我们希望使用相似的图形,因为它们是 snv,我们希望它们在视觉上相似,我们添加了略微不同的符号来表示“intronic”和“exonic”,例如,我们可以将红色矩形和红色矩形上方表示snv,我们用点代表“内含子”,用交叉线代表“外显子”。在总结不同变化类型数量的条形图注释上,我们不想将“intronic snv”和“exonic snv”分开,直接获取 snv 的总数以摆脱条形图中的太多类别.

让我们通过以下模拟数据来演示这个场景。为了简化示例,我们假设对于单个样本中的单个基因,它只有 snv 或 indel,并且只能是内含子或外显子。如果基因上没有“内含子”或“外显子”,这基本上意味着我们没有这个基因相关的信息(可能是基因间的snv/indel)。

set.seed(123)
x1 = sample(c("", "snv"), 100, replace = TRUE, prob = c(8, 2))
x2 = sample(c("", "indel"), 100, replace = TRUE, prob = c(8, 2))
x2[x1 == "snv"] = ""
x3 = sample(c("", "intronic"), 100, replace = TRUE, prob = c(5, 5))
x4 = sample(c("", "exonic"), 100, replace = TRUE, prob = c(5, 5))
x3[x1 == "" & x2 == ""] = ""
x4[x1 == "" & x2 == ""] = ""
x4[x3 == "intronic"] = ""
x = apply(cbind(x1, x2, x3, x4), 1, function(x) {
    x = x[x != ""]
    paste(x, collapse = ";")
})
m = matrix(x, nrow = 10, ncol = 10, dimnames = list(paste0("g", 1:10), paste0("s", 1:10)))
m[1:4, 1:4]
##    s1    s2             s3             s4            
## g1 ""    "snv;intronic" "snv;intronic" "snv"         
## g2 ""    ""             ""             "snv;intronic"
## g3 ""    ""             ""             ""            
## g4 "snv" "indel;exonic" "snv"          ""

现在m,有四种不同的蚀变类型:snvindelintronicexonic。接下来我们定义alter_fun四种变化。

alter_fun = list(
    background = function(x, y, w, h) 
        grid.rect(x, y, w*0.9, h*0.9, gp = gpar(fill = "#CCCCCC", col = NA)),
    # red rectangles
    snv = function(x, y, w, h) 
        grid.rect(x, y, w*0.9, h*0.9, gp = gpar(fill = "red", col = NA)),
    # blue rectangles
    indel = function(x, y, w, h) 
        grid.rect(x, y, w*0.9, h*0.9, gp = gpar(fill = "blue", col = NA)),
    # dots
    intronic = function(x, y, w, h) 
        grid.points(x, y, pch = 16),
    # crossed lines
    exonic = function(x, y, w, h) {
        grid.segments(x - w*0.4, y - h*0.4, x + w*0.4, y + h*0.4, gp = gpar(lwd = 2))
        grid.segments(x + w*0.4, y - h*0.4, x - w*0.4, y + h*0.4, gp = gpar(lwd = 2))
    }
)

对于一级类(snvindel)中的变更类型,我们使用彩色矩形来表示它们,因为矩形在视觉上很明显,而对于二级类(intronicexonic)中的变更类型,我们只使用简单的符号(点表示intronic和交叉对角线表示exonic)。由于intronicexonic没有对应的颜色,我们不需要为这两种类型定义颜色,在基因和样本的barplot注解上,只有snvindel 被可视化(所以snv条形图中的高度对应内含子snv的数量加上外显子snv的数量)。

# we only define color for snv and indel, so barplot annotations only show snv and indel
oncoPrint(m, alter_fun = alter_fun, col = c(snv = "red", indel = "blue"))
image

7.1.5 简化alter_fun

如果图形只是简单的图形,例如矩形、点,则可以通过alter_graphic()函数自动生成图形函数。前面的示例之一可以简化为:

oncoPrint(mat,
    alter_fun = list(
        snv = alter_graphic("rect", width = 0.9, height = 0.9, fill = col["snv"]),
        indel = alter_graphic("rect", width = 0.9, height = 0.4, fill = col["indel"])
    ), col = col)
image

7.1.6 其它热图相关设置

默认情况下,列名不在图中绘制。可以通过设置开启show_column_names = TRUE

alter_fun = list(
    snv = function(x, y, w, h) grid.rect(x, y, w*0.9, h*0.9, 
        gp = gpar(fill = col["snv"], col = NA)),
    indel = function(x, y, w, h) grid.rect(x, y, w*0.9, h*0.4, 
        gp = gpar(fill = col["indel"], col = NA))
)
oncoPrint(mat, alter_fun = alter_fun, col = col, show_column_names = TRUE)
image

可以通过设置show_row_namesshow_pct来打开/关闭行名称和百分比文本。根据 oncoPrint 的两侧由pct_side和控制row_names_side。百分比值的数字由pct_digits控制。

oncoPrint(mat, alter_fun = alter_fun, col = col, 
    row_names_side = "left", pct_side = "right", pct_digits = 2)
image

两边的barplot注释由anno_oncoprint_barplot()注释函数控制 。尺寸和轴等自定义可以直接在anno_oncoprint_barplot(). 更多设置示例anno_oncoprint_barplot()可在oncoprint-annotations中找到。

oncoPrint(mat, alter_fun = alter_fun, col = col, 
    top_annotation = HeatmapAnnotation(
        cbar = anno_oncoprint_barplot(height = unit(1, "cm"))),
    right_annotation = rowAnnotation(
        rbar = anno_oncoprint_barplot(
            width = unit(4, "cm"),
            axis_param = list(at = c(0, 2, 4), 
                labels = c("zero", "two", "four"),
                side = "top",
                labels_rot = 0))),
    )
image

有些人可能想将右侧的条形图移动到 oncoPrint 的左侧:

oncoPrint(mat, alter_fun = alter_fun, col = col, 
    left_annotation =  rowAnnotation(
        rbar = anno_oncoprint_barplot(
            axis_param = list(direction = "reverse")
    )),
    right_annotation = NULL)
image

OncoPrints 本质上是热图,因此, Heatmap()oncoPrint(). 在下面讲解中,将使用真实的世界数据集来演示oncoPrint()函数的更多使用。

7.2 应用于cBioPortal数据集

我们使用真实世界的数据集来演示oncoPrint(). 从cBioPortal检索数据。获取数据的步骤如下:

  1. 去http://www.cbioportal.org,
  2. 搜索癌症研究:“ Lung Adenocarcinoma Carcinoma ”并选择:“ Lung Adenocarcinoma Carcinoma (TCGA, Provisinal)
  3. 在“输入基因集”字段中,选择:“常规:Ras-Raf-MEK-Erk/JNK 信号(26 个基因) ”,
  4. 提交表格。

在结果页面中,

  1. 转到“下载”选项卡,下载“所有案例中的遗传改变类型”中的文本。

样品的顺序也可以从结果页面下载,

  1. 转到“ OncoPrint ”选项卡,将鼠标移到绘图上方,单击“下载”图标,然后单击“样品订单”

数据已经在ComplexHeatmap包中。首先我们读取数据并进行一些预处理。

mat = read.table(system.file("extdata", package = "ComplexHeatmap", 
    "tcga_lung_adenocarcinoma_provisional_ras_raf_mek_jnk_signalling.txt"), 
    header = TRUE, stringsAsFactors = FALSE, sep = "\t")
mat[is.na(mat)] = ""
rownames(mat) = mat[, 1]
mat = mat[, -1]
mat=  mat[, -ncol(mat)]
mat = t(as.matrix(mat))
mat[1:3, 1:3]
##      TCGA-05-4384-01 TCGA-05-4390-01 TCGA-05-4425-01
## KRAS "  "            "MUT;"          "  "           
## HRAS "  "            "  "            "  "           
## BRAF "  "            "  "            "  "

mat有 3 种不同的变化:HOMDELAMPMUT。我们首先定义如何为不同的改动添加图形。

col = c("HOMDEL" = "blue", "AMP" = "red", "MUT" = "#008000")
alter_fun = list(
    background = function(x, y, w, h) {
        grid.rect(x, y, w-unit(2, "pt"), h-unit(2, "pt"), 
            gp = gpar(fill = "#CCCCCC", col = NA))
    },
    # big blue
    HOMDEL = function(x, y, w, h) {
        grid.rect(x, y, w-unit(2, "pt"), h-unit(2, "pt"), 
            gp = gpar(fill = col["HOMDEL"], col = NA))
    },
    # big red
    AMP = function(x, y, w, h) {
        grid.rect(x, y, w-unit(2, "pt"), h-unit(2, "pt"), 
            gp = gpar(fill = col["AMP"], col = NA))
    },
    # small green
    MUT = function(x, y, w, h) {
        grid.rect(x, y, w-unit(2, "pt"), h*0.33, 
            gp = gpar(fill = col["MUT"], col = NA))
    }
)

请注意,由于图形都是矩形,因此可以通过以下方式生成alter_graphic()

# just for demonstration
alter_fun = list(
    background = alter_graphic("rect", fill = "#CCCCCC"),   
    HOMDEL = alter_graphic("rect", fill = col["HOMDEL"]),
    AMP = alter_graphic("rect", fill = col["AMP"]),
    MUT = alter_graphic("rect", height = 0.33, fill = col["MUT"])
)

现在我们制作 oncoPrint。我们将column_titleheatmap_legend_param 保存为变量,因为它们在以下代码块中被多次使用。

column_title = "OncoPrint for TCGA Lung Adenocarcinoma, genes in Ras Raf MEK JNK signalling"
heatmap_legend_param = list(title = "Alternations", at = c("HOMDEL", "AMP", "MUT"), 
        labels = c("Deep deletion", "Amplification", "Mutation"))
oncoPrint(mat,
    alter_fun = alter_fun, col = col, 
    column_title = column_title, heatmap_legend_param = heatmap_legend_param)
image

如您所见,基因和样本会自动重新排序。行根据所有样本中的更改频率进行排序,列重新排序以可视化样本之间的互斥性。列重新排序基于“备忘录排序”方法,改编自 https://gist.github.com/armish/564a65ab874a770e2c26。

7.2.1 删除空行和列

默认情况下,如果样品或基因没有改变,他们仍然会留在热图,但您可以设置remove_empty_columnsremove_empty_rowsTRUE将其删除:

oncoPrint(mat,
    alter_fun = alter_fun, col = col, 
    remove_empty_columns = TRUE, remove_empty_rows = TRUE,
    column_title = column_title, heatmap_legend_param = heatmap_legend_param)
image

删除空行和列后,行和列的数量可能会减少。oncoPrint 的所有组件都进行了相应的调整。当 oncoPrint 与其他热图和注释串联时,这可能会导致热图列表中的行数或列数不完全相同的问题。因此,如果您将 oncoPrint 放入热图列表并且不想看到空行或列,则需要在发送到oncoPrint()函数之前手动删除它们(这个预处理对您来说应该很容易!)。

7.2.2 oncoPrint重排

作为普通Heatmap()函数,row_order或者column_order可以用一个向量命令赋值(数字或字符)。在下面的例子中,样本的顺序也是从 cBio 收集的。您可以看到“备忘录排序”和 cBio 使用的方法之间的样本顺序差异。

sample_order = scan(paste0(system.file("extdata", package = "ComplexHeatmap"), 
    "/sample_order.txt"), what = "character")
oncoPrint(mat,
    alter_fun = alter_fun, col = col, 
    row_order = 1:nrow(mat), column_order = sample_order,
    remove_empty_columns = TRUE, remove_empty_rows = TRUE,
    column_title = column_title, heatmap_legend_param = heatmap_legend_param)
image

同样,如果remove_empty_rowsremove_empty_columns设置为TRUErow_ordercolumn_order会自动调整 。

7.2.3 OncoPrint 注释

oncoPrint 有几个预定义的注释。

在 oncoPrint 的顶部和右侧,有条形图显示每个基因或每个样本的不同改变的数量,oncoPrint 的左侧是一个文本注释,显示每个基因发生改变的样本百分比。

barplot 注释由anno_oncoprint_barplot()实现,您可以在其中设置注释的位置。默认情况下为所有更改类型绘制条形图,但您也可以通过设置anno_oncoprint_barplot()来选择更改子集以放置在条形图上。anno_oncoprint_barplot()是一个简单的包装器,围绕anno_barplot()其中的频率矩阵进行内部计算。请参阅以下示例:

oncoPrint(mat,
    alter_fun = alter_fun, col = col, 
    top_annotation = HeatmapAnnotation(
        column_barplot = anno_oncoprint_barplot("MUT", border = TRUE, # only MUT
            height = unit(4, "cm"))
    ),
    right_annotation = rowAnnotation(
        row_barplot = anno_oncoprint_barplot(c("AMP", "HOMDEL"),  # only AMP and HOMDEL
            border = TRUE, height = unit(4, "cm"), 
            axis_param = list(side = "bottom", labels_rot = 90))
    ),
    remove_empty_columns = TRUE, remove_empty_rows = TRUE,
    column_title = column_title, heatmap_legend_param = heatmap_legend_param)
image

默认情况下,条形图注释显示频率。这些值可以通过设置来改变,在anno_oncoprint_barplot()设置显示分数show_fraction = TRUE

oncoPrint(mat,
    alter_fun = alter_fun, col = col, 
    top_annotation = HeatmapAnnotation(
        column_barplot = anno_oncoprint_barplot(show_fraction = TRUE)
    ),
    right_annotation = rowAnnotation(
        row_barplot = anno_oncoprint_barplot(show_fraction = TRUE)
    ),
    remove_empty_columns = TRUE, remove_empty_rows = TRUE,
    column_title = column_title, heatmap_legend_param = heatmap_legend_param)
image

将百分比值和行名称在内部构造为文本注释。通过设置show_pctshow_row_names打开或关闭它们。pct_siderow_names_side控制放置它们的侧面。

oncoPrint(mat,
    alter_fun = alter_fun, col = col, 
    remove_empty_columns = TRUE, remove_empty_rows = TRUE,
    pct_side = "right", row_names_side = "left",
    column_title = column_title, heatmap_legend_param = heatmap_legend_param)
image

oncoPrint 的 barplot 注释本质上是正常的注释,您可以通过HeatmapAnnotation()rowAnnotation()添加更多的注释:

oncoPrint(mat,
    alter_fun = alter_fun, col = col, 
    remove_empty_columns = TRUE, remove_empty_rows = TRUE,
    top_annotation = HeatmapAnnotation(cbar = anno_oncoprint_barplot(),
        foo1 = 1:172,
        bar1 = anno_points(1:172)
    ),
    left_annotation = rowAnnotation(foo2 = 1:26),
    right_annotation = rowAnnotation(bar2 = anno_barplot(1:26)),
    column_title = column_title, heatmap_legend_param = heatmap_legend_param)
image

如您所见,百分比注释、行名称注释和 oncoPrint 注释默认附加到用户指定的注释中。如果remove_empty_columnsremove_empty_rows设置为TRUE,注释也会自动调整。

7.2.4 oncoPrint 作为热图

oncoPrint()实际上返回一个Heatmap对象,因此您可以水平或垂直添加更多热图和注释,从而可视化复杂的关联。

以下示例水平添加热图。请记住,您始终可以向热图列表添加行注释。

ht_list = oncoPrint(mat,
    alter_fun = alter_fun, col = col, 
    column_title = column_title, heatmap_legend_param = heatmap_legend_param) +
Heatmap(matrix(rnorm(nrow(mat)*10), ncol = 10), name = "expr", width = unit(4, "cm"))
draw(ht_list)
image

或垂直添加:

ht_list = oncoPrint(mat,
    alter_fun = alter_fun, col = col, 
    column_title = column_title, heatmap_legend_param = heatmap_legend_param) %v%
Heatmap(matrix(rnorm(ncol(mat)*10), nrow = 10), name = "expr", height = unit(4, "cm"))
draw(ht_list)
image

与普通热图列表类似,您可以拆分热图列表:

ht_list = oncoPrint(mat,
    alter_fun = alter_fun, col = col, 
    column_title = column_title, heatmap_legend_param = heatmap_legend_param) +
Heatmap(matrix(rnorm(nrow(mat)*10), ncol = 10), name = "expr", width = unit(4, "cm"))
draw(ht_list, row_split = sample(c("a", "b"), nrow(mat), replace = TRUE))
image

remove_empty_columnsremove_empty_rows设置为TRUE时,基因数或样本数可能不是原来的数。如果原始矩阵有行名和列名。可以得到行和列的子集如下:

ht = oncoPrint(mat,
    alter_fun = alter_fun, col = col, 
    remove_empty_columns = TRUE, remove_empty_rows = TRUE,
    column_title = column_title, heatmap_legend_param = heatmap_legend_param)
rownames(ht@matrix)
##  [1] "KRAS"   "HRAS"   "BRAF"   "RAF1"   "MAP3K1" "MAP3K2" "MAP3K3" "MAP3K4"
##  [9] "MAP3K5" "MAP2K1" "MAP2K2" "MAP2K3" "MAP2K4" "MAPK3"  "MAPK4"  "MAPK7" 
## [17] "MAPK8"  "MAPK9"  "MAPK12" "MAPK14" "DAB2"   "RAB25"
colnames(ht@matrix)
##   [1] "TCGA-05-4390-01" "TCGA-38-4631-01" "TCGA-44-6144-01" "TCGA-44-6145-01"
##   [5] "TCGA-44-6146-01" "TCGA-49-4488-01" "TCGA-50-5930-01" "TCGA-50-5931-01"
##   [9] "TCGA-50-5932-01" "TCGA-50-5933-01" "TCGA-50-5941-01" "TCGA-50-5942-01"
##  [13] "TCGA-50-5944-01" "TCGA-50-5946-01" "TCGA-50-6591-01" "TCGA-50-6592-01"
##  [17] "TCGA-50-6594-01" "TCGA-67-4679-01" "TCGA-67-6215-01" "TCGA-73-4658-01"
##  [21] "TCGA-73-4676-01" "TCGA-75-5122-01" "TCGA-75-5125-01" "TCGA-75-5126-01"
##  [25] "TCGA-75-6206-01" "TCGA-75-6211-01" "TCGA-86-6562-01" "TCGA-05-4396-01"
##  [29] "TCGA-05-4405-01" "TCGA-05-4410-01" "TCGA-05-4415-01" "TCGA-05-4417-01"
##  [33] "TCGA-05-4424-01" "TCGA-05-4427-01" "TCGA-05-4433-01" "TCGA-44-6774-01"
##  [37] "TCGA-44-6775-01" "TCGA-44-6776-01" "TCGA-44-6777-01" "TCGA-44-6778-01"
##  [41] "TCGA-49-4487-01" "TCGA-49-4490-01" "TCGA-49-6744-01" "TCGA-49-6745-01"
##  [45] "TCGA-49-6767-01" "TCGA-50-5044-01" "TCGA-50-5051-01" "TCGA-50-5072-01"
##  [49] "TCGA-50-6590-01" "TCGA-55-6642-01" "TCGA-55-6712-01" "TCGA-71-6725-01"
##  [53] "TCGA-91-6828-01" "TCGA-91-6829-01" "TCGA-91-6835-01" "TCGA-91-6836-01"
##  [57] "TCGA-35-3615-01" "TCGA-44-2655-01" "TCGA-44-2656-01" "TCGA-44-2662-01"
##  [61] "TCGA-44-2666-01" "TCGA-44-2668-01" "TCGA-55-1592-01" "TCGA-55-1594-01"
##  [65] "TCGA-55-1595-01" "TCGA-64-1676-01" "TCGA-64-1677-01" "TCGA-64-1678-01"
##  [69] "TCGA-64-1680-01" "TCGA-67-3771-01" "TCGA-67-3773-01" "TCGA-67-3774-01"
##  [73] "TCGA-05-4244-01" "TCGA-05-4249-01" "TCGA-05-4250-01" "TCGA-35-4122-01"
##  [77] "TCGA-35-4123-01" "TCGA-44-2657-01" "TCGA-44-3398-01" "TCGA-44-3918-01"
##  [81] "TCGA-05-4382-01" "TCGA-05-4389-01" "TCGA-05-4395-01" "TCGA-05-4397-01"
##  [85] "TCGA-05-4398-01" "TCGA-05-4402-01" "TCGA-05-4403-01" "TCGA-05-4418-01"
##  [89] "TCGA-05-4420-01" "TCGA-05-4422-01" "TCGA-05-4426-01" "TCGA-05-4430-01"
##  [93] "TCGA-05-4434-01" "TCGA-38-4625-01" "TCGA-38-4626-01" "TCGA-38-4628-01"
##  [97] "TCGA-38-4630-01" "TCGA-44-3396-01" "TCGA-49-4486-01" "TCGA-49-4505-01"
## [101] "TCGA-49-4506-01" "TCGA-49-4507-01" "TCGA-49-4510-01" "TCGA-73-4659-01"
## [105] "TCGA-73-4662-01" "TCGA-73-4668-01" "TCGA-73-4670-01" "TCGA-73-4677-01"
## [109] "TCGA-05-5428-01" "TCGA-05-5715-01" "TCGA-50-5045-01" "TCGA-50-5049-01"
## [113] "TCGA-50-5936-01" "TCGA-55-5899-01" "TCGA-64-5774-01" "TCGA-64-5775-01"
## [117] "TCGA-64-5778-01" "TCGA-64-5815-01" "TCGA-75-5146-01" "TCGA-75-5147-01"
## [121] "TCGA-80-5611-01"

你可能感兴趣的:(ComplexHeatmap复杂热图绘制学习——7.OncoPrint)