-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfill_quartets.py
executable file
·71 lines (61 loc) · 1.3 KB
/
fill_quartets.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
66
67
68
69
70
71
#!/usr/bin/python
import os
import sys
import itertools
import collections
if len(sys.argv) < 3:
print("Usage: fill_quartets.py <CF_file> <taxon list>")
CF=sys.argv[1]
all=sys.argv[2]
spoof=True #hard coded option
#list of lists, capturing sampled quartets
sampled = list()
with open(CF, 'r') as fh:
try:
seen = list()
for line in fh:
if not line:
continue
else:
stuff = line.split(",")
seen = sorted(stuff[0:4])
sampled.append(seen)
except IOError:
print("Could not read file ",CF)
sys.exit(1)
finally:
fh.close()
all_quartets=list()
all_tax = list()
with open(all, 'r') as fh:
try:
all = list()
for line in fh:
line=line.strip()
if not line:
continue
else:
all_tax.append(line)
except IOError:
print("Could not read file ",CF)
sys.exit(1)
finally:
fh.close()
all_comb = list(itertools.combinations(all_tax,4))
for comb in all_comb:
all_quartets.append(sorted(list(comb)))
#print("Writing all missing quartets to stdout...")
for quartet in all_quartets:
miss=True
for sample in sampled:
if set(quartet) == set(sample):
miss=False
if miss==True:
if spoof:
oline = "";
for tax in quartet:
oline = oline + str(tax) + ","
oline = oline + "0.333333333333334,0.333333333333333,0.333333333333333"
print(oline)
else:
print(quartet)