This repository has been archived by the owner on Apr 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
71 lines (66 loc) · 2.31 KB
/
main.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
61
62
63
64
65
66
67
68
69
70
71
import os
class fastaReader:
def __init__(self, fileName, start=0, end=1):
self.fileIn = open(fileName)
self.fileOut = open(fileName+".out", "w+")
self.start = start
self.end = end
self.count = 0
self.total = 0
def copy(self, tar, s, e):
result = ""
for i in range(s, e):
result += tar[i]
return result
def cut(self):
print("Cuting....")
while 1:
name = ""
line = self.fileIn.readline()
if not line:
break
elif(line[0] == '>'):
# print(line,end="")
string = ""
name = line
# self.fileOut.write(line)
line = self.fileIn.readline()
self.total += 1
while 1:
if(line != "\n"):
string += line
line = self.fileIn.readline()
else:
string.replace('\n', '')
length = len(string)
s = length * self.start
e = length * self.end
if len(string) <= 8:
string += '\n'
self.fileOut.write(name)
self.fileOut.write(string)
self.count += 1
elif len(string) > 8:
temp = self.copy(string, int(s), int(e))
if len(temp) < 8:
string += '\n'
self.fileOut.write(name)
self.fileOut.write(string)
break
temp += '\n'
self.fileOut.write(name)
self.fileOut.write(temp)
self.count += 1
break
self.fileIn.close()
self.fileOut.close()
os.rename(fileName+".out", fileName+"["+str(self.count)+"/"+str(self.total)+"]"+".out")
print("Over")
fileName = raw_input("fileLocated:")
start = float(input("start:"))
end = float(input("end:"))
# fileName="D:\H3B-1-pnovo-11-value.fasta"
# start=0
# end=0.2
tar = fastaReader(fileName, start, end)
tar.cut()