-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeconcatenate_seed.py
executable file
·60 lines (46 loc) · 1.8 KB
/
deconcatenate_seed.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 python
"""
Created on Thu May 7 15:41:41 2015
@author: Sagar
"""
from optparse import OptionParser
def deconcatenate_seed_file(seed_file, folder):
with open(seed_file) as seed:
current_file = list()
current_pfam = ""
for line in seed:
current_file.append(line)
if line.startswith("#=GF AC"):
splitted_line = line.split(" ")
current_pfam = splitted_line[-1]
if line.startswith("//"):
file_name = folder + current_pfam.strip() + ".sto"
with open(file_name, 'w+') as fout:
for line in current_file:
fout.write(line)
# make the next file
current_file = list()
def check_folder_name(folder):
if folder.endswith("/"):
return folder
else:
return folder + "/"
def opt():
# Initiate a OptionParser Class
parser = OptionParser()
# Call add_options to the parser
parser.add_option("-i", dest="seed",
help="Seed file.", metavar="GLOB")
parser.add_option("-o", dest="folder",
help="Output folder where all Pfam files are written to.", metavar="FOLDER")
return parser
def main():
parser = opt()
# parse the the parser object and save the data into options and args
# opts contains all values received via command line
# argv contains a list of all commited argument
(options, argv) = parser.parse_args()
folder_name = check_folder_name(options.folder)
deconcatenate_seed_file(options.seed, folder_name)
if __name__ == "__main__":
main()