基因家族分析三把刀:hmmsearch&blast&orthofinder

我只是个搬运工,侵权请私信,速删

方法一:blast

数据准备:
下载NCBI 中相关蛋白序列,将所有的fa序列放在一起成all.pep
下载相关基因组的蛋白序列,eg:genome1.fa,genome2.fa。。。
数据分析:

#用makeblastdb建立blast数据库
makeblastdb -in ref.nbs.plant.fa -dbtype prot -out blastdb

#用blastp进行序列搜索,得到每个序列的相似序列
blastp -num_threads 20 -db blastdb -query Arabidopsis_thaliana.TAIR10.pep.all.fa -outfmt 7 -seg yes > blastp.out &

#筛选identity大于75%的序列
cat blastp.out |awk '$3>75' |cut -f1 |sort -u > blastp_result_id.list

方法二:hmm

1.准备数据
①下载拟南芥基因组fasta文件、注释文件gtf/gff3文件:
ftp://ftp.ensemblgenomes.org/pub/plants/release-36/fasta/arabidopsis_thaliana/

Arabidopsis_thaliana.TAIR10.gff3.gz
Arabidopsis_thaliana.TAIR10.cds.all.fa.gz
Arabidopsis_thaliana.TAIR10.dna.toplevel.fa.gz
Arabidopsis_thaliana.TAIR10.pep.all.fa.gz  

②下载 NBS-ARC基因家族的hmm模型:http://pfam.xfam.org/

NBS-ARC.hmm    #PF00931

2.目标基因家族搜索与筛选

source /data1/spider/miniconda3/bin/activate
conda activate bioinforspace

#目标基因家族搜索
hmmsearch --cut_tc --domtblout NBS-ABC.out NBS-ARC.hmm Arabidopsis_thaliana.TAIR10.pep.all.fa.gz

#过滤筛选得到E-value小于1*10-20,先拿到序列号
grep -v "#" NBS-ABC.out|awk '($7 + 0) < 1E-20'|cut -f1 -d  " "|sort -u > NBS-ARC_qua_id.txt
#再根据序列号,从Arabidopsis_thaliana.TAIR10.pep.all.fa.gz中提取序列
less Arabidopsis_thaliana.TAIR10.pep.all.fa.gz | /data1/spider/ytbiosoft/seqkit grep -f NBS-ARC_qua_id.txt > NBS-ARC_qua.fa

3.多序列比对,构建目标物种的NB-ARC基因家族的hmm模型

#对筛选出来的序列用clustalw进行多序列比对
/data/shaofeng/clustalw/clustalw
弹出clustalw的操作界面,以下展示具体输入过程:
选择1(输入待比对序列)→ 输入待比对序列的文件名:NBS-ARC_qua.fa → 选择2(开始进行序列比对)→选择9(选择输出比对结构的格式为aligned)→ 按enter键 → 选择1(选择比对模式为全局比对) → 指定输出的比对结果的文件名称:NBS-ARC_qua.aln → 回车后开始比对 → 输入一个树文件名(new GUIDE TREE file):NBS-ARC_qua.dnd (最后才能得到NBS-ARC.aln,否则NBS-ARC.aln为空)
#使用hmmbuild对这些置信的序列进行隐马尔可夫模型的构建,即构建更加准确的hmm模型来尽可能的预测目标物种中NBS-ARC基因家族中所有的成员。
hmmbuild NBS-ARC_qua.hmm  NBS-ARC_qua.aln

hmmsearch --cut_tc --domtblout NBS-ARC.second.out NBS-ARC_qua.hmm Arabidopsis_thaliana.TAIR10.pep.all.fa

4.利用目标物种的hmm模型再次筛选目标物种中符合要求的序列

#再次对这些基因进行过滤和提取
grep -v "#" NBS-ARC.second.out|awk '($7 + 0) < 1E-03' | cut -f1 -d " "|sort -u >final.NBS.list

less Arabidopsis_thaliana.TAIR10.pep.all.fa.gz | /data1/spider/ytbiosoft/seqkit grep -f final.NBS.list > final_NBS-ARC_qua.fa

将上述两种方法得到gene id合并取交集,找出两种方法共有的基因家族成员,使结果更可信.

comm -12 blastp_result_id.list final.NBS.list > common.list

less Arabidopsis_thaliana.TAIR10.pep.all.fa.gz | /data1/spider/ytbiosoft/seqkit grep -f common.list > final_searh_NBS-ARC_qua.fa

方法三:orthofinder

1.数据准备
下载[「基因组学」使用OrthoFinder进行直系同源基因分析]准备的数据,总共有十二个物种的蛋白数据以及接下来会用到的Python脚本。

#解压缩
tar xf twelve_spp_proteins.tar.gz
for i in `ls -1 twelve_spp_proteins/*.tar.gz`; do tar xf $i -C twelve_spp_proteins; done
rm twelve_spp_proteins/*.tar.gz

3.识别基因家族:

①仅保留每个基因中有代表性的转录本,去除可变剪切和冗余基因;
②建立BLAST数据库,使用blastp进行 all-by-all 的比对;
③使用MCL基于blastp结果进行聚类,基因序列相似的通常是一个基因家族;
④解析MCL的输出结果,用作CAFE的输入。

①将所有最长的转录本合并成单个文件

#提取每个基因中最长的转录本
python python_scripts/cafetutorial_longest_iso.py -d twelve_spp_proteins/ 
#合并每个物种的最长转录本成为1个文件
cat twelve_spp_proteins/longest_*.fa | /data1/spider/ytbiosoft/seqkit rmdup - > makeblastdb_input.fa

②All-by-all BLAST

##我的blast工具安装在miniconda的一个子环境里面,首先需要激活这个环境
source/data1/spider/miniconda3/bin/activate
conda activate bioinforspace

##先用makeblastdb建立BLAST数据库
makeblastdb -in makeblastdb_input.fa -dbtype prot -out blastdb

##之后用blastp进行序列搜索,得到每个序列的相似序列
blastp -num_threads 20 -db blastdb -query makeblastdb_input.fa -outfmt 7 -seg yes > blast_output.txt &
#参数:
-seg参数过滤低复杂度的序列(即氨基酸编码为X)
-num_threads线程数,此处设置为20

③使用MCL进行序列聚类
根据BLAST输出中序列相似性信息寻找聚类,这些聚类将用于后续CAFE分析的基因家族。

##使用shell命令将BLAST转成MCL能够识别的ABC格式
grep -v "#"  blast_output.txt | cut -f 1,2,11 > blast_output.abc
##创建网络文件(.mci)和字典文件(.tab),然后进行聚类
source /data1/spider/miniconda3/bin/activateconda activate orthofinder     
#mcxload安装在orthofinder环境中
mcxload -abc blast_output.abc --stream-mirror --stream-neg-log10 -stream-tf 'ceil(200)' -o blast_output.mci -write-tab blast_output.tab &
#参数:--stream-mirror: 为输入创建镜像,即每一个X-Y都有一个Y-X--stream-neg-log10: 对输入的数值做-log10 转换-stream-tf: 对输入的数值进行一元函数转换,这里用到的是ceil(200)
#根据mci文件进行聚类, 其中主要调整的参数是-I,它决定了聚类的粒度,值越小那么聚类密度越大。一般设置为3。
mcl blast_output.mci -I 3
mcxdump -icl out.blast_output.mci.I30 -tabr blast_output.tab -o dump.blast_output.mci.I30

④整理MCL的输出结果
上一步MCL的输出还不能直接用于CAFE,还需要对其进行解析并过滤。

##1.将原来的mcl格式转成CAFE能用的格式
python python_scripts/cafetutorial_mcl2rawcafe.py -i dump.blast_output.mci.I30 -o unfiltered_cafe_input.txt -sp "ENSG00 ENSPTR ENSPPY ENSPAN ENSNLE ENSMMU ENSCJA ENSRNO ENSMUS ENSFCA ENSECA ENSBTA"
##2.将那些基因拷贝数变异特别大的基因家族剔除掉,因为它会造成参数预测出错。以下脚本是过滤掉一个或多个物种有超过100个基因拷贝的基因家族。
python python_scripts/cafetutorial_clade_and_size_filter.py -i unfiltered_cafe_input.txt -o filtered_cafe_input.txt -s
##3.将原本的编号替换成有意义的物种名
sed  -i -e 's/ENSPAN/baboon/' -e 's/ENSFCA/cat/' -e 's/ENSBTA/cow/' -e 's/ENSNLE/gibbon/' -e 's/ENSECA/horse/' -e 's/ENSG00/human/' -e 's/ENSMMU/macaque/' -e 's/ENSCJA/marmoset/' -e 's/ENSMUS/mouse/' -e 's/ENSPPY/orang/' -e 's/ENSRNO/rat/' -e 's/ENSPTR/chimp/' filtered_cafe_input.txt
sed  -i -e 's/ENSPAN/baboon/' -e 's/ENSFCA/cat/' -e 's/ENSBTA/cow/' -e 's/ENSNLE/gibbon/' -e 's/ENSECA/horse/' -e 's/ENSG00/human/' -e 's/ENSMMU/macaque/' -e 's/ENSCJA/marmoset/' -e 's/ENSMUS/mouse/' -e 's/ENSPPY/orang/' -e 's/ENSRNO/rat/' -e 's/ENSPTR/chimp/' large_filtered_cafe_input.txt

4.物种树推断

构建物种树主要分为多序列联配和系统发育树两步,随后,在已有进化树的基础上构建超度量树用作CAFE的输入。
①多序列联配一般用的是单拷贝的直系同源基因,分别进行多序列联配,然后合并成单个文件;
②使用系统发育树推测软件进行建树(软件: RAxML, PhyML, FastTree; MrBayes),生成的系统发育树用NEWICK格式保存为twelve_spp_raxml_cat_tree_midpoint_rooted.txt;

cat twelve_spp_raxml_cat_tree_midpoint_rooted.txt
(((cow:0.09289 ,(cat:0.07151,horse:0.05727):0.00398):0.02355,((((orang:0.01034,(chimp:0.00440,human:0.00396):0.00587):0.00184,gibbon:0.01331):0.00573,(macaque:0.00443,baboon:0.00422):0.01431):0.01097,marmoset:0.03886):0.04239):0.03383,(rat:0.04110,mouse:0.03854):0.10918);

③推断超度量树
超度量树(ultrametric tree)也叫时间树,就是将系统发育树的标度改成时间,从根到所有物种的距离都相同。构建方法有很多,比较常用的就是r8s。

#使用cafetutorial_prep_r8s.py构建r8s的批量运行脚本,然后提取超度量树
python python_scripts/cafetutorial_prep_r8s.py -i twelve_spp_raxml_cat_tree_midpoint_rooted.txt -o r8s_ctl_file.txt -s 35157236 -p 'human,cat' -c '94'
/data1/spider/liupiao/biosoft/r8s1.81/src/r8s -b -f r8s_ctl_file.txt > r8s_tmp.txt &
tail -n 1 r8s_tmp.txt | cut -c 16- > twelve_spp_r8s_ultrametric.txt

5.运行CAFE

估计出生-死亡参数λ
CAFE的主要功能是根据给定的进化树和基因家族数估计一个或多个λ参数。λ参数描述的是出现或消失的概率。
①为整个树估计单个λ

##编辑脚本cafetutorial_run1.sh。注意:以下脚本的括号中不能出现任何空格。

#!cafe
load -i filtered_cafe_input.txt -t 4 -l reports/log_run1.txt
tree ((((cat:68.710507,horse:68.710507):4.566782,cow:73.277289):20.722711,(((((chimp:4.444172,human:4.444172):6.682678,orang:11.126850):2.285855,gibbon:13.412706):7.211527,(macaque:4.567240,baboon:4.567240):16.056992):16.060702,marmoset:36.684935):57.315065):38.738021,(rat:36.302445,mouse:36.302445):96.435575)
lambda -s -t ((((1,1)1,1)1,(((((1,1)1,1)1,1)1,(1,1)1)1,1)1)1,(1,1)1)
report reports/report_run1
mkdir -p reports
/data/biosoft/cafe cafetutorial_run1.sh   ##运行脚本
##结果统计
#上一步运行结束后的报告文件存放在reports/reportrun1.cafe,可以用已有的脚本分析哪些基因家族发生了扩张或进行搜索
python  python_scripts/cafetutorial_report_analysis.py -i reports/report_run1.cafe -o reports/summary_run1

#在reports文件夹下会出现如下文件
summary_run1_node.txt: 统计每个节点中扩张,收缩的基因家族数
summary_run1_fams.txt: 具体发生变化的基因家族

②为高基因拷贝数的基因家族预测λ
之前过滤掉的高拷贝数变异的基因家族可以进行单独的分析,运行命令如下:

#!cafe
load -i large_filtered_cafe_input.txt -t 4 -l reports/log_run2.txt
tree ((((cat:68.710507,horse:68.710507):4.566782,cow:73.277289):20.722711,(((((chimp:4.444172,human:4.444172):6.682678,orang:11.126850):2.285855,gibbon:13.412706):7.211527,(macaque:4.567240,baboon:4.567240):16.056992):16.060702,marmoset:36.684935):57.315065):38.738021,(rat:36.302445,mouse:36.302445):96.435575)
lambda -l 0.00265952 -t ((((1,1)1,1)1,(((((1,1)1,1)1,1)1,(1,1)1)1,1)1)1,(1,1)1)
report reports/report_run2

#运行脚本
/data/biosoft/cafe cafetutorial_run2.sh

③为树的不同部分预测多个λ
如果你认为不同物种或者不同分支的基因家族进化速率不同,那么可以让CAFE预测多个值. 对lambda部分进行调整, 相同数字表示相同,不同数字表示不同。

#!cafe
load -i filtered_cafe_input.txt -t 4 -l reports/log_run3.txt
tree ((((cat:68.710507,horse:68.710507):4.566782,cow:73.277289):20.722711,(((((chimp:4.444172,human:4.444172):6.682678,orang:11.126850):2.285855,gibbon:13.412706):7.211527,(macaque:4.567240,baboon:4.567240):16.056992):16.060702,marmoset:36.684935):57.315065):38.738021,(rat:36.302445,mouse:36.302445):96.435575)
lambda -s -t ((((3,3)3,3)3,(((((1,1)1,2)2,2)2,(2,2)2)2,3)3)3,(3,3)3)
report reports/report_run3

#运行脚本
/data/biosoft/cafe cafetutorial_run3.sh

CAFE主要输出文件格式

Lambda是整个进化树的预测值
IDs of nodes表示不同节点的编号,这里cat为0,horse为2,cat和horse所在的节点是1
最后是每个基因家族的结果。以最开始的表示行为例,第一列对应输入基因家族的编号;第二列是Newick的进化树,cat_59中的59表示该基因家族在cat里有59个基因;第三列是Family-wide P-value,用于表明该基因家族是否是显著性的扩张或是收缩,这里是0.438,说明变化不明显。在第三列的p值小于0.01时,第四列表明哪个分支的基因家族发生了变化,上图中只有ID 11的基因家族有变化, 但是0,1,2,4分支并没有变化。

你可能感兴趣的:(基因家族分析三把刀:hmmsearch&blast&orthofinder)