pheatmap 畫NA值熱圖與 image 畫三角統(tǒng)計分析圖

前言:生物信息工作中各種熱圖層出不窮,介紹兩種特殊的熱圖畫法
1.含有NA數(shù)據(jù)的熱圖


image.png

數(shù)據(jù)格式如上圖所示
python 中用pandas 處理一下數(shù)據(jù)

import pandas as pd
import numpy as np
pd.read_excel('./GI50.xlsx',encode='tuf-8',index_col=0).replace('-',np.nan).to_csv('GI50.csv')   ###第一種用NA替換,但是這樣熱圖就失去了聚類
a.replace('-',0).astype('float').replace(np.inf,-8).to_csv('result.csv') ### 第二種用一個偏離很大的值替換,這樣結(jié)果就會聚類在一起

熱圖用R pheatmap

library(pheatmap)
a=read.csv('result.csv',row.names = 1,header = T)
pheatmap(a, cluster_col = FALSE,legend_breaks = c( -8,seq(from=-0.2, to=max(a), by=2)),legend_labels = c("NA",seq(from=0, to=8, by=2)),legend = TRUE,fontsize = 8,filename = 'pheatmaps.pdf')#,breaks = c(-15,seq(from=-8, to=0, by=2)), color = c(colorRampPalette(colors = c("blue","white"))(100)))
image.png
image.png

在使用maftools中有個一個互斥圖非常好看,而且在圖中表示了一部分F檢驗的內(nèi)容
下面就用image畫一個類似的圖形分別用T檢驗和Pearson檢驗來畫
原始數(shù)據(jù)是這樣的


image.png

用pandas 處理數(shù)據(jù)
數(shù)據(jù)兩兩計算形成一個對稱的矩陣
在將重復部分用np.nan填充


image.png

使用R image 來畫一個

#注釋部分是上面的圖的內(nèi)容
###  主要圖形
    m <- nrow(tdata)
    n <- ncol(tdata) 
    par(bty="n", mgp = c(2,.5,0), mar = c(2, 4, 3, 5)+.1, las=2, tcl=-.33)
    image(1:n, 1:m,  as.matrix(tdata),col=RColorBrewer::brewer.pal(9,'Blues'),
          xaxt="n", yaxt="n",
          xlab="",ylab="", xlim=c(0, n+4), ylim=c(0, n+4))
    abline(h=0:n+.5, col="white", lwd=.5)
    abline(v=0:n+.5, col="white", lwd=.5)
    mtext(side = 2, at = 1:m, text = colnames(tdata), cex = 0.8, font = 3)
    mtext(side = 3, at = 1:n, text = colnames(tdata), las = 2, line = -2, cex = 0.8, font = 3)

####  Pvalue中的點
#     w = arrayInd(which(pdata< 0.01), rep(m,2))
#     points(w, pch="*", col="black")
#     w = arrayInd(which(pdata< 0.05), rep(m,2))
#     points(w, pch=".", col="black")
    #image(y = 1:8 +6, x=rep(n,2)+c(2,2.5)+1, z=matrix(c(1:8), nrow=1), col=brewer.pal(8,"PiYG"), add=TRUE)
###圖例部分
    image(y = seq(0.5*nrow(tdata), 0.9*nrow(tdata), length.out = 8), x=rep(n,2)+c(2,2.5)+1, z=matrix(c(1:8), nrow=1), col = RColorBrewer::brewer.pal(8,'Blues'), add=TRUE)
    #axis(side = 4, at = seq(1,7) + 6.5,  tcl=-.15, label=seq(-3, 3), las=1, lwd=.5)
    atLims = seq(0.5*nrow(tdata), 0.9*nrow(tdata), length.out = 5)
    axis(side = 4, at = atLims,  tcl=-.15, labels =seq(from=0, to=300, length.out=5), las=1, lwd=.5)
    mtext(side=4, at = median(atLims), "Student's t test -log10", las=3, cex = 0.9, line = 3, font = 2)
    par(xpd=NA)
### 文字部分
#     text(x=n+2.2, y= max(atLims)+1.2, "Co-occurance", pos=4, cex = 0.9, font = 2)
#     text(x=n+2.2, y = min(atLims)-1.2, "Exclusive", pos=4, cex = 0.9, font = 2)

#     points(x = n+1, y = 0.2*n, pch = "*", cex = 2)
#     text(x = n+1, y = 0.2*n, paste0(" p < ",0.01), pos=4, cex = 0.9, font = 2)
#     points(x = n+1, y = 0.1*n, pch = ".", cex = 2)
#     text(x = n+1, y = 0.1*n, paste0("p < ", 0.05), pos=4, cex = 0.9)
image.png
image.png
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容