Tips:
https://deeptools.readthedocs.io/en/develop/content/tools/plotCorrelation.html
我們比較樣本的重復(fù)性,一般都是用deeptools
中 plotCorrelation
畫散點(diǎn)圖祟身。比如下面類似的命令.
### Step1 multiBamSummary
$ multiBamSummary bins
--bamfiles *.uniq.bam
--minMappingQuality 30
-out scores_per_transcript.npz
--outRawCount scores_per_transcript.tab
### Step2 plotCorrelation
$ deepTools2.0/bin/plotCorrelation \
-in scores_per_transcript.npz \
--corMethod pearson --skipZeros \
--plotTitle "Pearson Correlation of Average Scores Per Transcript" \
--whatToPlot scatterplot \
-o scatterplot_PearsonCorr_bigwigScores.png \
--outFileCorMatrix PearsonCorr_bigwigScores.tab
得到圖:
image.png
假設(shè)只有tab
文件诈闺,但plotCorrelation
只能識別npz
格式(numpy
存儲的格式。類似R
里面.RData
一樣,存儲特定數(shù)據(jù)結(jié)構(gòu)),要怎么才可以畫圖?
也就是說tab
格式如何轉(zhuǎn)化成npz
格式呢?
查看npz 里面是什么東西 讀取npz 的方法:菜鳥教程
image.png
類似字典巢寡,有l(wèi)abels 和matrix 兩個鍵。我們將tab整理成這個格式就可以了椰苟。
實(shí)踐:
1. 下載文章數(shù)據(jù) 41556_2019_383_MOESM9_ESM.xlsx 抑月,發(fā)現(xiàn)數(shù)據(jù)都是excel 格式保存的。如下圖:
image.png
需要讀取excel 的sheet 里面的數(shù)據(jù)舆蝴,保存為fig1b_scatterplot.csv谦絮。
R代碼:
########################
rm(list=ls())
options(warn = -1)
options(stringsAsFactors = F)
setwd("C:/Users/16926/Desktop/2020-1/單細(xì)胞/sc-ChIP")
##############
## 1.加載包,讀取xlsx(最新格式)
## 參考:
## 1.不同R包比較 http://www.reibang.com/p/5ed6e4b5d181
## 2.openxlsx::read.xlsx 參數(shù)介紹 :https://blog.csdn.net/zyunnketsu/article/details/78053179
##############
library(openxlsx)
a<-read.xlsx("41556_2019_383_MOESM9_ESM.xlsx",
sheet=1,startRow = 14)#文件名+sheet的序號,簡單粗暴
head(a)
s1 <- object.size(a)
print(sl, units = "auto", standard = "SI")
write.csv(a,file = "./fig1/fig1b_scatterplot.csv",row.names = F)
提取到fig1b_scatterplot.csv 內(nèi)容如下:
image.png
2.將fig1b_scatterplot.csv 轉(zhuǎn)換成npz 格式
####################
## time:2020/3/23 10:27
## author: caokai
## email:1692679247@qq.com
## aim : convert csv format to npz format to use deeptools software
####################
####################
## 1.加載模塊
import os
import numpy as np
import pandas as pd
os.chdir("C:/Users/16926/Desktop/2020-1/單細(xì)胞/sc-ChIP/fig1")
os.listdir(".")
####################
## 2.讀取及其保存格式
## 參考:np:https://www.runoob.com/numpy/numpy-io.html
## pd: https://blog.csdn.net/xidianbaby/article/details/88831145
## mian:https://blog.csdn.net/yuzhihuan1224/article/details/99634355?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task
dat = pd.read_csv("fig1b_scatterplot.csv")
labels = np.array(dat.columns[3:], dtype="|S22") # 去除前三列,labels轉(zhuǎn)換成np np.array([bytes(c, encoding='utf8') for c in dat.columns])
matrix = dat.iloc[:,3:].values # 去除前三列,value轉(zhuǎn)換成np np.array(dat[dat.columns[3:]])
## 計(jì)算log10(FPM)
matrix = np.log10(matrix+1)
## 保存為npz 格式
np.savez(r"fig1.scatterplot.npz",
labels = labels,
matrix = matrix)
data_z = np.load("fig1.scatterplot.npz")
print(data_z.files) # 查看各個數(shù)組名稱
print(data_z["labels"]) # 數(shù)組 labels
print(data_z["matrix"]) # 數(shù)組 matrix
所以我們得到了fig1.scatterplot.npz 數(shù)據(jù)洁仗,可以直接畫圖了层皱。
3.deeptools 畫圖
plotCorrelation -in fig1.scatterplot.npz
--corMethod pearson
--skipZeros --plotTitle 'Pearson Correlation'
--whatToPlot scatterplot
--removeOutliers
-o fig1_scatterplot_PearsonCorr.png
--outFileCorMatrix fig1_scatterplot_PearsonCorr.tab
散點(diǎn)圖如下圖:
2020年3月23日15:20:23
總結(jié)思考:
- 讀取Excel 的包推薦
openxlsx
- 了解
npy
和npz
差別,及其numpy修改數(shù)據(jù)格式的方式赠潦。
np.array(dat.columns[3:], dtype="|S22")
奶甘,將字符串轉(zhuǎn)換成bite 類型。 -
deeptoools
無法對數(shù)據(jù)進(jìn)行log10 scale
(只提供--log1p
:自然對數(shù)e
)
顏色deeptools --colorMap
參數(shù)祭椰,畫散點(diǎn)圖沒有用.
歡迎大家討論~