美文网首页群体遗传学
orthmcl 物种进化树建树实战

orthmcl 物种进化树建树实战

作者: 代表群众 | 来源:发表于2020-04-25 14:29 被阅读0次

从orthomcl结果中挑选出单拷贝基因,并建立一个单拷贝文件

python pick_single_gene.py groups.txt

pick_single_gene.py

# 2020.0425
# @zlk
# 从orthomcl中挑选出单拷贝基因

import sys

file1=open(sys.argv[1],'r')
file2=open(sys.argv[1]+'_single','w')
species_num=int(sys.argv[2])

for line in file1:
    line_list=line.strip().split(' ')[1:]

    if len(line_list)==species_num:
        single_dict={}
        flag=0
        for i in line_list:
            i_list=i.split('|')
            if i_list[0] in single_dict.keys():
                flag=1
                break
            else:
                single_dict[i_list[0]] = i_list[1]
        if flag==1:
            continue
        else:
            for key in sorted(single_dict):
                file2.write(single_dict[key]+'\t')
            file2.write('\n')

每一列为一个物种(groups.txt_single)

1.png

三个参数分别为单拷贝文件、所有物种的蛋白文件和物种名文件(每一行一个物种的名)

python bulit_ML_tree.py groups.txt_single all_pep.fa ./species.txt 

species.txt

2.png

bulit_ML_tree.py

# -*- coding=utf-8 -*-
# 2020.0425
# @zlk
# 构建距离树
import sys
import os

#需要安装三个软件,将路径放进脚本
# conda 都可以安装
mafft = '/public/zhanglk/anaconda3/envs/orthofinder2/bin/mafft'
raxml = '/public/zhanglk/anaconda3/envs/orthofinder2/bin/raxmlHPC-PTHREADS'
trimal = '/public/zhanglk/anaconda3/envs/orthofinder2/bin/trimal'


# 每行是一组需要建树的的基因ID,各物种用制表符隔开

def get_pep_dict(file2):
    pep_dict = {}
    for line in file2:
        if line.startswith('>'):
            name = line.strip()[1:]
            pep_dict[name] = ''
        else:
            pep_dict[name] += line
    return (pep_dict)


def get_orth_gene(file1,pep_dict):
    total_gene_list = []
    for line in file1:
        line_list = line.strip().split('\t')
        total_gene_list.append(line_list)
    os.mkdir("SingleGene")
    os.chdir("SingleGene")
    index = 0
    for gene_list in total_gene_list:
        index += 1
        write_file = open('zlk' + str(index) + '.fa', 'w')
        for i in gene_list:
            write_file.write('>' + i + '\n' + pep_dict[i])
        write_file.close()
        
def cal_msa(fold):
    file_list = os.listdir(fold)
    for fa_file in file_list:
        seq_aln_file = fa_file + "_aln.fa"
        seq_aln_trimed_file = fa_file + "_trimed.fa"  
        cmd1 = mafft + ' ' + fa_file + ' >' + seq_aln_file
        os.system(cmd1)
        cmd2 = trimal + ' -in ' + seq_aln_file + ' -out ' + seq_aln_trimed_file + ' -automated1'
        os.system(cmd2)


def combine_seq(fold,species_list):
    file_list = os.listdir(fold)
    for trim_file in file_list:
        if trim_file.endswith('_trimed.fa'):
            opfile=open(trim_file,'r')
            index=-1
            for line1 in opfile:
                if line1.startswith('>'):
                    index+=1
                else:
                    species_list[index][1]+=line1.strip()
            opfile.close()
    out_file=open('combine.fa','w')
    for fa in species_list:
        out_file.write('>%s\n%s\n'%(fa[0],fa[1]))
        
def bulit_tree(thread,nb,model):
    cmd = raxml + ' -T ' + thread + ' -f a -N ' + nb + ' -m ' + model + ' -x 123456 -p 123456 -s combine.fa -n concatenation_out.nwk'
    os.system(cmd)

# 单拷贝基因文件
file1 = open(sys.argv[1], 'r')
#所有蛋白文件
file2 = open(sys.argv[2], 'r')
# 物种名文件
file3 = open(sys.argv[3], 'r')
species_list=[]
for line in file3:
    species_list.append([line.strip(),''])
use_dict=get_pep_dict(file2)
get_orth_gene(file1,use_dict)
cal_msa('./')
# os.chdir("SingleGene")
combine_seq('./',species_list)
# 40线程, bootstrap 100 ,model PROTGAMMAJTT
bulit_tree('40','100',"PROTGAMMAJTT")

RAxML_bipartitionsBranchLabels.concatenation_out.nwk为最终树文件

FigTree可视化结果

3.png

相关文章

  • orthmcl 物种进化树建树实战

    从orthomcl结果中挑选出单拷贝基因,并建立一个单拷贝文件 pick_single_gene.py 每一列为一...

  • ggplot2版聚类物种丰度堆叠图

    在准备绘制不一样的物种丰度bar图在网上发现的一种可以绘制带有进化树,以及物种丰度的堆叠图 带有进化树物种丰度的堆...

  • 物种进化树构建

    使用单拷贝基因画物种进化树 所需软件: 步骤: python 脚本更改物种蛋白序列的ID 2)更改各个物种蛋白库文...

  • mcmctree估算物种分歧时间

    推断物种系统发育关系以及分歧时间对探讨物种起源与演化具有重要意义。通过最大似然法(ML)构建物种进化树以及估算物种...

  • 使用NCBI lifetree 查看所研究物种的分类

    进化树:进化树在生物学中,用来表示 物种 之间的 进化 关系。. 生物分类学家和进化论者根据各类生物间的亲缘关系的...

  • 单拷贝直系同源基因构建物种进化树

    最近用Orthofinder做物种进化树,最后出来的物种树的结构跟已发表研究的结果差距较大,在我的印象里Ortho...

  • R与进化树(前言)

    R与进化树 1. problems and issues 进化领域中树这个文件结构是比较复杂的,构建树的过程就是把...

  • R可视化:ggtree进化树

    ggtree较为完美展示物种进化树图。更多知识分享请到 https://zouhua.top/[https://z...

  • NCBI查询物种所在分支进化树

    进化树:进化树在生物学中,用来表示物种之间的进化关系。生物分类学家和进化论者根据各类生物间的亲缘关系的远近,把各类...

  • 在R中利用fasta序列构建进化树

    “进化树的构建怎么操作?”“那肯定是用MEGA啊!” 可是真的好麻烦啊,要先比对再建树,然后再进行各种美化,习惯了...

网友评论

    本文标题:orthmcl 物种进化树建树实战

    本文链接:https://www.haomeiwen.com/subject/xeqkwhtx.html