forked from Axolotl233/Simple_Script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
z.ETE3_class.py
65 lines (51 loc) · 1.5 KB
/
z.ETE3_class.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
65
#! python3
import sys
import ete3
import re
import os
def judge_tree(children,num1,num2,r):
regex1 = re.compile(r'^W')
regex2 = re.compile(r'^E')
pop1_max = num1 * r
pop1_min = num1 * (1 - r)
pop2_max = num2 * r
pop2_min = num2 * (1 - r)
num = 0;
for clade in children:
array = []
n_t1 = 0
n_t2 = 0
num += 1
for node in clade.traverse():
if node.is_leaf():
array.append(node.name)
for ele in array:
if regex1.match(ele):
n_t1 += 1
elif regex2.match(ele):
n_t2 += 1
#print (n_t1)
if n_t1 > pop1_max and n_t2 < pop2_min :
return num,"\tok"
break
elif n_t2 > pop2_max and n_t1 < pop1_min:
return num,"\tok"
break
if len(clade) > pop1_max or len(clade) > pop2_min:
temp_child = clade.get_children()
for ele in temp_child:
children.append(ele)
return num,"\twrong"
t = ete3.Tree(sys.argv[1])
root_point = t.get_midpoint_outgroup()
t.set_outgroup(root_point)
rate=float(sys.argv[2])
children = t.get_children()
m=judge_tree(children,num1=43,num2=18,r=rate)
path_name = (os.path.dirname(sys.argv[1]) + "/")
file_name = ("process_" + str(rate) + ".txt")
print (path_name)
with open(path_name+'process.txt','w') as f:
f.write(str(m[0]))
f.write(m[1] + "\n")
f.close()