-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorigin2
More file actions
48 lines (40 loc) · 1.07 KB
/
Copy pathorigin2
File metadata and controls
48 lines (40 loc) · 1.07 KB
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
from math import ceil
def reader(f):
while True:
line = f.readline()
if line == "":
break
elif line[0] != ">":
yield line[:-1].upper()
def origin_line(chars, pos):
length = len(chars)
parts = int(ceil(float(length)/10))
lijst = [chars[x:x + 10] for x in range(0, length, 10)]
out = (((" %s" % str((pos*60)+1))[-10:]) +
((" %s" * parts) % tuple(lijst)) + "\n")
return out
def writer(f, save):
lines = reader(f)
print "generator made"
chars = ""
print "reading lines"
num = 0
pos = 0
for x in lines:
num += 1
if num % 1000 == 0:
print "writing", num
chars += x
while len(chars) >= 60:
save.write(origin_line(chars[:60], pos))
chars = chars[60:]
pos += 1
if chars != "":
save.write(origin_line(chars, pos))
print "done"
if __name__ == "__main__":
f = open("carp_pbjelly.fa", "r")
save = open("save.temp", "w")
writer(f, save)
f.close()
save.close()