-
Notifications
You must be signed in to change notification settings - Fork 2
/
Subsystems_simplifier.py
52 lines (42 loc) · 1.35 KB
/
Subsystems_simplifier.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
#!/usr/lib/python2.6
# Subsystems_simplifier.py
# created 12/22/16, Sam Westreich
# Purpose: The subsystems.complex database is not organized well for searches. This script tries to make it a little more useful as an annotation database.
import sys, re
if len(sys.argv) != 2:
sys.exit("Need to specify database file as ARGV1.")
infile = open(sys.argv[1], "r")
outfile = open(sys.argv[1] + ".modified", "w")
line_counter = 0
prev_line_protein = True
for line in infile:
line_counter += 1
if line_counter % 100000 == 0:
print str(line_counter)[:-3] + "k lines processed so far."
if re.match("\d", line[0]):
continue # removes lines starting with numbers
elif re.match("^fig", line):
continue # removes lines starting with "fig"
elif re.match("^//", line):
continue # removes the double slashes, //
elif "All" in line:
continue # removes where it says "All" for some reason
elif line[0] == "#":
continue # removes the ######## dividers
# The following are just for debug purposes:
elif line[0] == ">":
if prev_line_protein == True:
if line_counter == 1:
outfile.write(line)
else:
outfile.write("\n" + line)
prev_line_protein = False
continue
else:
continue
elif len(re.sub("[A-Zx]", "", line.strip())) == 0:
outfile.write(line.strip())
prev_line_protein = True
continue
else:
continue