forked from RuleWorld/mcellRules
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsplit_bngxml.py
32 lines (22 loc) · 868 Bytes
/
split_bngxml.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
import argparse
def defineConsole():
"""
input console options
"""
parser = argparse.ArgumentParser(description='SBML to BNGL translator')
parser.add_argument('-i', '--input', type=str, help='input MDLr file', required=True)
return parser
def extractSeedBNG(xmlname):
with open(xmlname, 'r') as f:
bngxml = f.read()
start = bngxml.find('<ListOfSpecies>')
end = bngxml.find('</ListOfSpecies>') + len('</ListOfSpecies>')
seedxml = '<Model>\n' + bngxml[start:end] + '</Model>\n'
restxml = bngxml[:start] + '<ListOfSpecies>\n</ListOfSpecies>' + bngxml[end:]
return seedxml, restxml
if __name__ == "__main__":
parser = defineConsole()
namespace = parser.parse_args()
seed, rest = extractSeedBNG(namespace.input)
with open(namespace.input + '_total.xml','w') as f:
f.write(rest)