-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextractRules_rpSBML.py
59 lines (48 loc) · 1.64 KB
/
extractRules_rpSBML.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
#!/usr/bin/env python3
import libsbml
import argparse
import sys #exit using sys exit if any error is encountered
import os
import zipfile
import io
sys.path.insert(0, '/home/src/')
import rpFBA
##
#
#
def extractRules(rpsbml_paths):
#loop through all the rp_pathway reaction members and return the rules
allRules = {}
for rpsbml_name in rpsbml_paths:
allRules = {**allRules, **rpsbml_paths[rpsbml_name].readRPrules()}
return allRules
##
#
#
def readrpSBMLzip(inputZip):
input_zip = zipfile.ZipFile(inputZip)
rpsbml_paths = {}
for name in input_zip.namelist():
rpsbml_paths[name] = rpFBA.rpSBML(name, libsbml.readSBMLFromString(input_zip.read(name).decode("utf-8")))
return rpsbml_paths
##
#
#
if __name__ == "__main__":
parser = argparse.ArgumentParser('Given an SBML model and the generated SBML heterologous pathway by RetroPath2.0, merge the two')
parser.add_argument('-inSBMLzip', type=str)
parser.add_argument('-outRPrules', type=str)
params = parser.parse_args()
#sbml read the different mode
allRules = readrpSBMLzip(readrpSBMLzip(params.inSBMLzip))
merged_rpsbml = {}
for rpsbml_name in rpsbml_paths:
#read the input sbml model
input_rpsbml = rpFBA.rpSBML('inputMergeModel')
input_rpsbml.readSBML(params.inModel)
#merge the heterologous pathway to it
#TODO: reverse the merge such that the target SBML is merged into the rpsbml object and not vice-versa
rpsbml_paths[rpsbml_name].mergeModels(input_rpsbml.model)
merged_rpsbml[rpsbml_name] = input_rpsbml
writerpSBMLzip(merged_rpsbml, params.outSBMLzip)
exit(0)