Debian Codegraph @

metastudentPkg/lib/groupA/parser/group2_goParserSwissprot.py

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 #!/usr/bin/python
2
3
4 import sys
5
6 def main():
7 "the main function"
8 progname = sys.argv[0]
9 try:
10 infileName, outfileName = sys.argv[1:]
11 except ValueError:
12 sys.exit( "usage: %s INFILE OUTFILE" % progname)
13
14 # open infile
15 infile = open(infileName, 'r')
16
17 # open outfile
18 outfile = open(outfileName, 'w')
19
20 sqCounter = 0
21 go = ""
22 sq = ""
23 for line in infile:
24 # serach for GO
25 if line.startswith('DR GO'):
26 tmpline = line.split(';',2)
27 if go == '':
28 go = '>' + tmpline[1].lstrip()[4:]
29 else:
30 go = go + ',' + tmpline[1].lstrip()[4:]
31 # search for SQ
32 elif line.startswith('SQ'):
33 for line in infile:
34 if line.startswith('//'):
35 # if GO and SQ has been found in one block (separated by '//') the GOs and SQ is written into the outfile
36 if go != '':
37 outfile.write(go+'\n'+sq+'\n')
38 sqCounter+=1
39 if (sqCounter%50000 == 0 and sqCounter!=0):
40 print("%(sqCounter)d Sequences written into %(outfile)s" % {
41 'sqCounter': sqCounter,
42 'outfile': outfileName})
43 go = ''
44 sq = ''
45 break
46 else:
47 sq = sq + line.lstrip()
48 print("%(sqCounter)d Sequences written into %(outfile)s\nfinished" % {
49 'sqCounter': sqCounter,
50 'outfile': outfileName})
51 # close outfile
52 outfile.close()
53
54 # close infile
55 infile.close()
56
57 if __name__ == "__main__":
58 try:
59 main()
60 except KeyboardInterrupt:
61 pass