学习ComplexHeatmap复杂热图

2023-11-25 23:15

本文主要是介绍学习ComplexHeatmap复杂热图,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

iMeta | 复杂热图(ComplexHeatmap)可视化文章最新版,画热图就引它_生信宝典的博客-CSDN博客

作者贡献

顾祖光:研究课题的提出和设计, 软件编写,可视化,数据分析,论文编写,修订和审阅。

代码和数据可用性

ComplexHeatmap 的稳定版本发布在 https://bioconductor.org/packages/ComplexHeatmap/

开发者版本发布在https://github.com/jokergoo/ComplexHeatmap,

文档发布在

https://jokergoo.github.io/ComplexHeatmap-reference/book/

论文中绘制图1到图6的代码发布在

https://github.com/jokergoo/ComplexHeatmap_v2_paper_code

数据下载

作图

数据
##有9块数据
rm(list = ls())
library(ComplexHeatmap)
library(circlize)
library(RColorBrewer)
# 载入示例数据
res_list = readRDS("meth.rds")
str(res_list)##查看数据格式,便于数据提取#进行数据提取:共有9大块数据类型
type = res_list$type
mat_meth = res_list$mat_meth
mat_expr = res_list$mat_expr
direction = res_list$direction
cor_pvalue = res_list$cor_pvalue
gene_type = res_list$gene_type
anno_gene = res_list$anno_gene
dist = res_list$dist
anno_enhancer = res_list$anno_enhancer
List of 9$ type         : chr [1:20] "Tumor" "Tumor" "Tumor" "Tumor" ...$ mat_meth     : num [1:1000, 1:20] 0.0951 0.1789 0.1988 0.3331 0.3731 .....- attr(*, "dimnames")=List of 2.. ..$ : NULL.. ..$ : chr [1:20] "sample1" "sample2" "sample3" "sample4" ...$ mat_expr     : num [1:1000, 1:20] 1.2638 -0.6938 0.5577 0.0853 -0.2573 .....- attr(*, "dimnames")=List of 2.. ..$ : NULL.. ..$ : chr [1:20] "sample1" "sample2" "sample3" "sample4" ...$ direction    : chr [1:1000] "hypo" "hypo" "hypo" "hyper" ...$ cor_pvalue   : num [1:1000] 0.656 0.5782 0.3495 0.0287 1.2388 ...$ gene_type    : chr [1:1000] "protein_coding" "psedo-gene" "psedo-gene" "lincRNA" ...$ anno_gene    : chr [1:1000] "intergenic" "intergenic" "intergenic" "intergenic" ...$ dist         : num [1:1000] 388737 97280 36426 420011 355666 ...$ anno_enhancer: num [1:1000, 1:3] 0.072 0.758 0 0 0.571 .....- attr(*, "dimnames")=List of 2.. ..$ : NULL.. ..$ : chr [1:3] "enhancer_1" "enhancer_2" "enhancer_3"
图探索
颜色及注释
column_tree = hclust(dist(t(mat_meth)))#根据mat_meth 列(样本)进行聚类
column_order = column_tree$order#为了后面统一mat_expr 矩阵的顺序
##根据type数据显示前10个为肿瘤,后10个为对照(聚类癌与癌旁结果区分明确)
#[1]  8  6  5  7  4 10  3  9  1  2 | 12 18 15 19 13 14 16 17 11 20#颜色设置
library(RColorBrewer)
meth_col_fun = colorRamp2(c(0, 0.5, 1), c("blue", "white", "red"))
direction_col = c("hyper" = "red", "hypo" = "blue")
expr_col_fun = colorRamp2(c(-2, 0, 2), c("green", "white", "red"))
pvalue_col_fun = colorRamp2(c(0, 2, 4), c("white", "white", "red"))
gene_type_col = structure(brewer.pal(length(unique(gene_type)), "Set3"), names = unique(gene_type))
anno_gene_col = structure(brewer.pal(length(unique(anno_gene)), "Set1"), names = unique(anno_gene))
dist_col_fun = colorRamp2(c(0, 10000), c("black", "white"))
enhancer_col_fun = colorRamp2(c(0, 1), c("white", "orange"))#We first define two column annotations and then make the complex heatmaps.
#ht_opt(
#  legend_title_gp = gpar(fontsize = 8, fontface = "bold"), 
#  legend_labels_gp = gpar(fontsize = 8), 
#  heatmap_column_names_gp = gpar(fontsize = 8),
#  heatmap_column_title_gp = gpar(fontsize = 10),
#  heatmap_row_title_gp = gpar(fontsize = 8)
#)#列注释信息
ha = HeatmapAnnotation(type = type, col = list(type = c("Tumor" = "pink", "Control" = "royalblue")),annotation_name_side = "left")#注释名左侧
ha2 = HeatmapAnnotation(type = type, col = list(type = c("Tumor" = "pink", "Control" = "royalblue")), show_legend = FALSE)#不在显示图例(与第一个重复)
出图代码
##绘图:Heatmap+Heatmap的方式进行合并
p <- draw(Heatmap(mat_meth, name = "methylation", col = meth_col_fun,column_order= column_order,top_annotation = ha, column_title = "Methylation")+Heatmap(direction, name = "direction", col = direction_col) +Heatmap(mat_expr[, column_tree$order], name = "expression", col = expr_col_fun, column_order = column_order, top_annotation = ha2, column_title = "Expression"),row_km = 2, #对两个部分进行行聚类row_split = direction)#根据direction对行切分

绘制原图
ht_list = Heatmap(mat_meth, name = "methylation", col = meth_col_fun,column_order= column_order,top_annotation = ha, column_title = "Methylation") +Heatmap(direction, name = "direction", col = direction_col) +Heatmap(mat_expr[, column_tree$order], name = "expression", col = expr_col_fun, column_order = column_order, top_annotation = ha2, column_title = "Expression") +Heatmap(cor_pvalue, name = "-log10(cor_p)", col = pvalue_col_fun) +Heatmap(gene_type, name = "gene type", col = gene_type_col) +Heatmap(anno_gene, name = "anno_gene", col = anno_gene_col) +Heatmap(dist, name = "dist_tss", col = dist_col_fun) +Heatmap(anno_enhancer, name = "anno_enhancer", col = enhancer_col_fun, cluster_columns = FALSE, column_title = "Enhancer")
#pdf('complex_heatmap.pdf',width = 12,height = 8)
draw(ht_list, row_km = 2, row_split = direction,column_title = "Comprehensive correspondence between methylation, expression and other genomic features", column_title_gp = gpar(fontsize = 12, fontface = "bold"), merge_legends = TRUE, heatmap_legend_side = "bottom")
dev.off()

R实战 | 复杂热图3.0(ComplexHeatmap) (qq.com)

快速入门ComplexHeatmap包:理解绘制复杂热图的多种参数设置 (qq.com)

tidyHeatmap使用长数据绘制热图 (qq.com)

这篇关于学习ComplexHeatmap复杂热图的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/424780

相关文章

Java实现复杂查询优化的7个技巧小结

《Java实现复杂查询优化的7个技巧小结》在Java项目中,复杂查询是开发者面临的“硬骨头”,本文将通过7个实战技巧,结合代码示例和性能对比,手把手教你如何让复杂查询变得优雅,大家可以根据需求进行选择... 目录一、复杂查询的痛点:为何你的代码“又臭又长”1.1冗余变量与中间状态1.2重复查询与性能陷阱1.

Unity新手入门学习殿堂级知识详细讲解(图文)

《Unity新手入门学习殿堂级知识详细讲解(图文)》Unity是一款跨平台游戏引擎,支持2D/3D及VR/AR开发,核心功能模块包括图形、音频、物理等,通过可视化编辑器与脚本扩展实现开发,项目结构含A... 目录入门概述什么是 UnityUnity引擎基础认知编辑器核心操作Unity 编辑器项目模式分类工程

Python学习笔记之getattr和hasattr用法示例详解

《Python学习笔记之getattr和hasattr用法示例详解》在Python中,hasattr()、getattr()和setattr()是一组内置函数,用于对对象的属性进行操作和查询,这篇文章... 目录1.getattr用法详解1.1 基本作用1.2 示例1.3 原理2.hasattr用法详解2.

SpringBoot+EasyExcel实现自定义复杂样式导入导出

《SpringBoot+EasyExcel实现自定义复杂样式导入导出》这篇文章主要为大家详细介绍了SpringBoot如何结果EasyExcel实现自定义复杂样式导入导出功能,文中的示例代码讲解详细,... 目录安装处理自定义导出复杂场景1、列不固定,动态列2、动态下拉3、自定义锁定行/列,添加密码4、合并

Go学习记录之runtime包深入解析

《Go学习记录之runtime包深入解析》Go语言runtime包管理运行时环境,涵盖goroutine调度、内存分配、垃圾回收、类型信息等核心功能,:本文主要介绍Go学习记录之runtime包的... 目录前言:一、runtime包内容学习1、作用:① Goroutine和并发控制:② 垃圾回收:③ 栈和

MySQL复杂SQL之多表联查/子查询详细介绍(最新整理)

《MySQL复杂SQL之多表联查/子查询详细介绍(最新整理)》掌握多表联查(INNERJOIN,LEFTJOIN,RIGHTJOIN,FULLJOIN)和子查询(标量、列、行、表子查询、相关/非相关、... 目录第一部分:多表联查 (JOIN Operations)1. 连接的类型 (JOIN Types)

Android学习总结之Java和kotlin区别超详细分析

《Android学习总结之Java和kotlin区别超详细分析》Java和Kotlin都是用于Android开发的编程语言,它们各自具有独特的特点和优势,:本文主要介绍Android学习总结之Ja... 目录一、空安全机制真题 1:Kotlin 如何解决 Java 的 NullPointerExceptio

重新对Java的类加载器的学习方式

《重新对Java的类加载器的学习方式》:本文主要介绍重新对Java的类加载器的学习方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1、介绍1.1、简介1.2、符号引用和直接引用1、符号引用2、直接引用3、符号转直接的过程2、加载流程3、类加载的分类3.1、显示

Java学习手册之Filter和Listener使用方法

《Java学习手册之Filter和Listener使用方法》:本文主要介绍Java学习手册之Filter和Listener使用方法的相关资料,Filter是一种拦截器,可以在请求到达Servl... 目录一、Filter(过滤器)1. Filter 的工作原理2. Filter 的配置与使用二、Listen

resultMap如何处理复杂映射问题

《resultMap如何处理复杂映射问题》:本文主要介绍resultMap如何处理复杂映射问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录resultMap复杂映射问题Ⅰ 多对一查询:学生——老师Ⅱ 一对多查询:老师——学生总结resultMap复杂映射问题