-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcombineboot.py
64 lines (53 loc) · 2.14 KB
/
combineboot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/python
#-----------------------------------------------------------------------------------------------
# HybPhyloMaker: combine bootstrap support values from two trees into one using p4 (Foster 2004)
# https://github.com/tomas-fer/HybPhyloMaker
# v.1.6.0
# Taken from http://p4.nhm.ac.uk/tutorial/combine_supports.html
# Modified for HybPhyloMaker
# Tomas Fer, 2018
# tomas.fer@natur.cuni.cz
#-----------------------------------------------------------------------------------------------
#Two trees and alignment named 'concatenated.phylip' must be in the same directory
#Output tree 'combinedSupportsTree.tre' is in Newick format
#Usage combineboot.py masterTree secondaryTree
import sys
tree1 = sys.argv[1]
tree2 = sys.argv[2]
#alignment = sys.argv[3]
#print 'Tree1:', tree1
#print 'Tree2:', tree2
#print 'Alignment:', alignment
import p4
from p4 import *
#Disable checking for undetermined positions
var.doCheckForAllGapColumns=False
#Get a valid list of taxnames from an alignment (must be named 'concatenated.phylip'):
a = func.readAndPop('concatenated.phylip')
#print a.taxNames
#Read in and name the two trees, and make sure they both have the same taxNames:
tMaster = p4.func.readAndPop(tree1)
tSecondary = p4.func.readAndPop(tree2)
tMaster.taxNames = a.taxNames
tSecondary.taxNames = a.taxNames
# Split keys are numerical versions of the 'dot-star' split notation.
# The same split on the two trees would have the same split key.
tMaster.makeSplitKeys()
tSecondary.makeSplitKeys()
# Make a dictionary, so that we can fish out nodes in the secondary tree
# given a split key. Split keys are found on node branches, here n.br.
myDict = {}
for n in tSecondary.iterInternalsNoRoot():
myDict[n.br.splitKey] = n
for nM in tMaster.iterInternalsNoRoot():
# Given a split key in the master tree, we can find the
# corresponding node in the secondary tree, using the split key with
# the dictionary.
nS = myDict.get(nM.br.splitKey)
# If there was none, then nS is None
if nS:
nM.name = '%s/%s' % (nM.name, nS.name)
else:
nM.name = '%s/-' % nM.name
#print nM.name
tMaster.writeNewick('combinedSupportsTree.tre')