-
Notifications
You must be signed in to change notification settings - Fork 0
/
debdec_run.py
executable file
·51 lines (38 loc) · 1.25 KB
/
debdec_run.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
#!/usr/bin/env python3
import sys
import os
from debdec import sliding_windows
from debdec_create import get_db
def readfile(k, fhd):
p = True
d = get_db(k)
print(d)
table = {base:idx for idx, base in enumerate("ACGT")}
table_inv = [c for c, i in sorted(table.items(), key=lambda x:x[1])]
for rownum, line in enumerate(fhd):
i = [table[c] for c in line.rstrip()]
kmers = sliding_windows(i, k)
print(f"{' '*18}{line.strip()}")
for knum, kmer in enumerate(kmers):
v = d(kmer)
dna = "".join([table_inv[i] for i in kmer]) if p else ""
print(f"{rownum:5d} {knum:5d} {v:5d} {' '*knum}{dna}")
if __name__ == '__main__':
if len(sys.argv) < 2:
print("usage: {} <k-mer length> [<filename>]".format(sys.argv[0]))
exit(1)
try:
k = int(sys.argv[1])
except:
print("usage: {} <k-mer length> [<filename>]".format(sys.argv[0]))
exit(1)
if k < 1:
print("k-mer length must be at least 1.")
fhd = sys.stdin
if len(sys.argv) == 3:
filename = sys.argv[2]
assert os.path.exists(filename)
fhd = open(filename, 'r')
readfile(k, fhd)
if len(sys.argv) == 3:
fhd.close()