-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOrthoMCL.find.Single.Copy.py
executable file
·70 lines (50 loc) · 1.77 KB
/
OrthoMCL.find.Single.Copy.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
#! /usr/bin/env python3
import argparse
def mcl_parse(mcl_groups):
group_count = {}
with open (mcl_groups) as file:
for line in file:
line = line.strip()
group_id = line.split(":")[0].strip()
group_terms = line.split(":")[1].strip()
#print(group_terms.split(" "))
group_count[group_id] = [i.split("|")[0] for i in group_terms.split(" ")]
return group_count
def stdout(group_count):
colnames = []
for value in group_count.values():
colnames+=value
colnames = set(colnames)
print("groups" + "\t" + "\t".join(colnames))
for key, value in group_count.items():
print("%s" %key, end = "")
for i in colnames:
print(" %s" %(value.count(i)), end = "")
print("\n")
def stdout_single(group_count):
colnames = []
for value in group_count.values():
colnames+=value
colnames = set(colnames)
print("groups" + "\t" + "\t".join(colnames))
for key, value in group_count.items():
single_copy = []
for i in colnames:
single_copy.append(value.count(i))
if list(set(single_copy))[0] == 1 and len(set(single_copy)) == 1:
print("%s " %key, end = "")
print(" ".join([str(i) for i in single_copy]))
def main():
parse = argparse.ArgumentParser()
parse.add_argument("-i", "--input", help = "input file")
parse.add_argument("-s", "--single", action="store_true", help = "weather or not print single copy groups")
args = parse.parse_args()
single = args.single
mcl_groups = args.input
group_count = mcl_parse(mcl_groups)
if single:
stdout_single(group_count)
else:
stdout(group_count)
if __name__ == "__main__":
main()