-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathfind_exclusive_kmers.py
executable file
·58 lines (42 loc) · 1.25 KB
/
find_exclusive_kmers.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
#!/usr/bin/python
import operator
import sys
from subprocess import call
print "Usage: find_exclusive_kmers.py query(cov=50) subject(cov=1)"
#interest C=50
query = sys.argv[1]
#database C=1
sbjct = sys.argv[2]
#interest kmer-counting
call("jellyfish count -m 25 -s 100M -t 10 -C %s" % (query), shell=True)
call("jellyfish dump -L 50 -c mer_counts.jf > %s" % (query+".50.txt"), shell=True)
#database kmer-counting
call("jellyfish count -m 25 -s 100M -t 10 -C %s" % (sbjct), shell=True)
call("jellyfish dump -L 1 -c mer_counts.jf > %s" % (sbjct+".50.txt"), shell=True)
call("rm mer_counts.jf", shell=True)
dict_q = {}
dict_s = {}
select = {}
list_q = open(query+".50.txt").readlines()
list_s = open(sbjct+".50.txt").readlines()
for x in list_q:
x = x.split()
dict_q[x[0]] = int(x[1])
for x in list_s:
x = x.split()
dict_s[x[0]] = int(x[1])
for el in dict_q:
look = el in dict_s
if look == False:
select[el] = dict_q[el]
select_sorted = sorted(select.iteritems(), key=operator.itemgetter(1))
select_sorted.reverse()
w = open(query+".excl.txt", "w")
ww = open(query+".excl.fas", "w")
i = 0
for el in select_sorted:
i += 1
w.write("%s\t%s\n" % (el[0], str(el[1])))
ww.write(">%s\n%s\n" % (str(i), el[0]))
w.close()
ww.close()