-
Notifications
You must be signed in to change notification settings - Fork 295
/
ec.py
executable file
·60 lines (42 loc) · 1.33 KB
/
ec.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
#! /usr/bin/env python2
#
# This file is part of khmer, http://github.com/ged-lab/khmer/, and is
# Copyright (C) Michigan State University, 2009-2013. It is licensed under
# the three-clause BSD license; see doc/LICENSE.txt.
# Contact: khmer-project@idyll.org
#
import screed
import khmer
import sys
import math
def main():
hash_filename = sys.argv[1]
input_filename = sys.argv[2]
output_filename = sys.argv[3]
max_error_region = int(sys.argv[4])
C = 20 # 20
corrected = 0
uncorrected = 0
outfp = open(output_filename, 'w')
ht = khmer.load_counting_hash(hash_filename)
aligner = khmer.new_readaligner(ht, 1, C, max_error_region)
K = ht.ksize()
for n, record in enumerate(screed.open(input_filename)):
if n % 1000 == 0:
print n
seq = record.sequence
seq_name = record.name
seq = seq.replace('N', 'A')
grXreAlign, reXgrAlign = aligner.align(seq)
if len(reXgrAlign) > 0:
graph_seq = grXreAlign.replace('-', '')
corrected += 1
outfp.write('>%s\n%s\n' % (seq_name, graph_seq))
else:
uncorrected += 1
outfp.write('>%s\n%s\n' % (seq_name, seq))
print 'corrected', corrected
print 'uncorrected', uncorrected
outfp.close()
if __name__ == '__main__':
main()