###首先下载ete3工具包 from ete3 import Tree for i inrange(7121): #提前创建7122个文件,用于写入定根后的树文件,修改为基因的数量减一 f = open('./%s'%i + '.txt',"a") f.write("")
n=0 withopen('alltree.txt','r') as f: for line in f: t = Tree(line) t.set_outgroup(t&"mcap") #设置外群,修改双引号之间的物种名即可,若歪群为两个物种则改为t.set_outgroup("mcap1"&"mcap2") t.write(outfile=str(n)+".txt") #将每一行的树定根后写入到每一个文件中 n=n+1
写为python脚本并运行,然后将其合并方便后续分析。
1
sed '' *.txt > alltree.rooted.txt
检测单系性
1 2 3 4 5
from ete3 import Tree withopen('alltree.rooted.txt','r') as f: #此处alltree.rooted.txt为包含所有基因树的文件,每行一个基因树 for line in f: t = Tree(line) print(t.check_monophyly(values=["aawi", "asub", "aflo", "agem", "aint", "apal", "adig", "alor", "aacu", "anas", "amic", "amil", "asel", "acyt", "ahya", "amur", "aech"], target_attr="name")) #利用check_monophyly函数检测单系性,修改方括号内的物种名即可