MatrixEQTL是一個快速有效的cis/trans eQTL mapping分析工具,被The Genotype-Tissue Expression (GTEx)數據庫用於eQTL mapping分析。使用MatrixEQTL進行eQTL mapping需要五個輸入文件,即SNP.txt(snpmatrix文件,行名為樣本名稱,列名為snpid), GE.txt(基因表達量文件,行名為樣本名稱,列名為基因或者轉錄本名稱), Covariates.txt(協變量文件,行名為樣本名稱,列名為協變量名稱),geneloc.txt(基因位置文件,各列的含義分別是基因名稱、基因所在染色體編號、基因起始位置和基因結束位置),snpsloc.txt(snp的物理位置文件,各列含義分別為snpid、所在染色體名稱、物理位置)。
SNP.txt文件的准備
需要准備的數據:.vcf.gz或者.vcf文件。
第一步:獲取重復snpid
由於第七版的GTEx基因型數據存在snpid重復的情況,為了准確計算maf,所以需要去重。
具體方法一:
① vcf文件轉化為ped和map文件
plink --vcf file.vcf --recode --out file
或者
plink --vcf file.vcf --recode --out file
輸出:file.ped file.map
②基於得到的file.map文件,得到重復的snpid,存儲到plink.dupvar文件
cut -f 2 file.map | sort | uniq -d > plink.dupvar
具體方法二:
plink --file file.vcf --list-duplicate-vars ids-only suppress-first
輸入:file.vcf
輸出:plink.dupvar(重復的snpid文件)
注:方法一和方法二的區別是方法二更准確,其對於每一個重復的項保留了一項(suppress-first),而方法一刪除了全部重復項。
第二步:過濾snpid和樣本id
plink --vcf .vcf.gz --recode --out .name --keep .sampleid --missing --freq --maf 0.02 --exclude plink.dupvar
輸入:
.vcf.gz,原始vcf文件;
.sampleid,用戶想保留的sampleid;
plink.dupvar,用戶想過濾掉的snpid。
輸出:
.name.frq, 所有snpid的等位基因(A1,A2)以及MAF;
.name.lmiss, 所選樣本的snpid確實情況;
.name.imiss, 每個樣本基因型缺失情況;
.name.ped,更新后的ped文件;
.name.map,更新后的map文件。
第三步:計算snp矩陣
vcftools --gzvcf .vcf.gz --012 --out .name --keep .sampleid --maf 0.02 --exclude plink.dupvar
輸入:
.vcf.gz,原始vcf文件;
.sampid,用戶想保留的樣品id;
plink.dupvar,用戶想過濾掉的snpid。
輸出:
name.012,snpmatrix(樣本數*snpid數),純數字矩陣,只有行索引(是樣本id在原始.vcf.gz文件中的索引號),沒有列索引。與MatrixEQTL要求的輸入文件SNP.txt正好相反,所以后面需要轉置;
name.012.pos,snpid 所在的染色體及物理位置;
name.012.indv,樣本id。
第四步:snp矩陣轉置
因為SNP.tx有格式要求,所以行名必須是snpid,列名必須是樣本名稱。因此需要刪除name.012的第一列(即索引號),然后轉置。
① 快速刪除第一列Index
awk '{ $1=null;print }' name.012 > name_del0.012
②添加sampleid
paste name.012.indv name_del0.012 > name_del0.012_indv.txt
③ 快速添加行snpid
首先從.map文件中獲得snpid
cat file | awk '{print $2}' > snpid.txt
echo "ID" > snpid1.txt ; cat snpid.txt >> snpid1.txt
注:snpid.txt即為去除重復后的snpid,從name.map中獲得。
④合並多行為一行
可以用很多方法實現該目的,在此以python腳本sipid_2_oneline.py為例,輸入文件為上述snpid1.txt,輸出文件為一行snpid,以tab符分隔:
from sys import argv
script,input,output = argv
with open(output,"w") as f:
with open(input) as f1:
for line in f1.readlines():
f.write(line.strip()+"\t")
f.write("\n")
python sipid_2_oneline.py input output
⑤添加snpid並轉置
cat snpid1.txt name_del0.012_indv.txt> genotype.txt
awk '{i=1;while(i <= NF){col[i]=col[i] $i " ";i=i+1}} END {i=1;while(i<=NF){print col[i];i=i+1}}' genotype.txt | sed 's/[ \t]*$//g' > genotype_transpose.txt
snp_loc.txt准備和gene_loc.txt准備
1)snp位置(snp position)
從.map中獲得,只需調換位置即可。
2)基因或者轉錄本位置(gene position)
從ensembl網站下載。
GE.txt文件准備和Covariate.txt文件准備
根據實際情況准備GE.txt,協變量文件非必需。
運行MatrixEQTL
將上述五個(或者四個,不需要covariate.txt文件)准備好后,直接使用MatrixEQTL的示例代碼進行eQTL分析。
參考資料:
R語言實現eQTL分析