如何使ComplexHeatMap接受具有对数刻度的NA数据?

时间:2019-06-18 15:42:35

标签: r matrix bioinformatics heatmap

我有一个基因表达q值的数据集,我试图在一个热图中绘制,并缩放数据记录并接受图中的NA。

ComplexHeatMap库具有一个选项,可以接受图中的NA,如果我事先不对数据应用log(),则可以使用该选项,但是我需要应用此选项。

我想做的是这样:

mat <- log10(df)
mat <- as.matrix(mat)
mat[is.infinite(mat)] <- NA                 
mat_with_na = mat
na_index = sample(c(TRUE, FALSE), nrow(mat)*ncol(mat), replace = TRUE, prob = c(1, 9))
mat_with_na[na_index] = NA
Heatmap(mat_with_na, name = "Q-value Log-10", na_col = "black", col=colorRamp2(c(-0.5, 0, 0.5), c("blue", "white", "red")))

我应用日志,并给出-Inf值,我将其替换为NA(因为complexheatmap具有处理此问题的代码:https://jokergoo.github.io/ComplexHeatmap-reference/book/a-single-heatmap.html

但是我的代码仍然显示错误:

Error in hclust(get_dist(submat, distance), method = method) : 
  NA/NaN/Inf in foreign function call (arg 11)

我还需要添加其他代码吗?

作为示例,我的数据如下所示:

gene        Atria  Left Ventricle   Coronary Artery
HLA-DQA1    1.17E-16    1.55E-15    0.00206
CCDC77      2.53E-09    0.00854     0.181
CCBL2       5.52E-17                1.95E-13
MAP2K2      0.0282      0.159       0.0106
PHACTR4                 0.0464      0.145
STEAP2      2.45E-13    6.73E-10    1.26E-10

或者这个:

dput(mat[1:10,1:10])
structure(c(1.17e-16, 2.53e-09, 5.52e-17, 0.0282, 2.5e-09, 2.45e-13, 
3.4e-15, 0.244, 0.000743, 0.00163, 1.55e-15, 0.00854, 2.32e-05, 
0.159, 0.0464, 6.73e-10, 3.51e-09, 0.12, 0.0502, 0.00254, 0.00206, 
0.181, 1.95e-13, 0.0106, 0.145, 1.26e-10, 0.269, 0.337, 0.292, 
2.86e-07, 3.57e-12, 8.25e-10, 3.05e-14, 0.195, 7.91e-15, 7.81e-21, 
9.81e-12, 0.00293, 1.27e-10, 0.000624, 6.28e-22, 5.25e-25, 2.19e-32, 
1.41e-05, 4.27e-46, 2.93e-29, 0.000443, 6.46e-08, 4.91e-08, 0.00131, 
2.35e-29, 7.73e-09, 1.13e-18, 0.0107, 3.53e-12, 0, 0.373, 1.19e-11, 
0.0129, 7.7e-18, 4.07e-06, 4.26e-05, 2.27e-05, 0.43, 1.05e-05, 
9.14e-06, 0.000225, 0.131, 0.294, 0.0254, 3.54e-55, 6.37e-12, 
1.42e-15, 0.00676186, 0.00011566, 6.42e-09, 0.0649816, 7.51e-11, 
8.11e-10, 2.08e-20, 9.46e-13, 2.59e-11, 3.2e-28, 0.0853035, 1.65e-22, 
1.47e-13, 0.244667, 5.82e-06, 2.53e-08, 1.04e-13, 2.85e-16, 2.02e-08, 
2.39e-22, 0.36304, 3.17e-13, 2.46e-11, 0.0167479, 1.16e-05, 4e-07, 
4.95e-05), .Dim = c(10L, 10L), .Dimnames = list(c("HLA-DQA1", 
"CCDC77", "CCBL2", "MAP2K2", "PHACTR4", "STEAP2", "CCDC181", 
"MPI", "TMCO6", "RP11-890B15.3"), c("Atria", "Left.Ventricle", 
"Adrenal.Gland", "Aorta", "Tibial.Artery", "Blood", "Coronary.Artery", 
"Lung", "Adipose..sub.", "Adipose..visc.")))

0 个答案:

没有答案