forked from fjruizruano/ngs-protocols
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextract_member_reads_rexp.py
executable file
·55 lines (43 loc) · 1.01 KB
/
extract_member_reads_rexp.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
#!/usr/bin/python
import sys
try:
members = sys.argv[1]
except:
members = raw_input("Introduce clusterMembership file: ")
try:
file = sys.argv[2]
except:
file = raw_input("Introduce index.tab file: ")
try:
tag_len = sys.argv[3]
tag_len = int(tag_len)
except:
tag_len = raw_input("Introduce tag length (integer): ")
tag_len = int(tag_len)
# load index.tab file
def load_index(file):
dictio = {}
for line in file:
line = line.split()
num = line[1]
dictio[line[1][tag_len:]] = line[0]
return dictio
def load_members(members):
lis = []
for line in members:
line = line.split()
lis.append(line[0])
return lis
# open files
members = open(members).readlines()
file = open(file).readlines()
# load data
index = load_index(file)
membs = load_members(members)
final_set = set()
for memb in membs:
if memb in index:
final_set.add(index[memb][tag_len:-2])
w = open("member_reads.txt","w")
w.write("\n".join(final_set))
w.close()