12
12
import sys
13
13
14
14
15
- def defineConsole ():
15
+ def define_console ():
16
16
parser = argparse .ArgumentParser (description = 'SBML to BNGL translator' )
17
17
parser .add_argument (
18
18
'-i' , '--input' , type = str , help = 'input MDLr file' , required = True )
@@ -25,7 +25,7 @@ def defineConsole():
25
25
return parser
26
26
27
27
28
- def getScriptPath ():
28
+ def get_script_path ():
29
29
return os .path .dirname (os .path .realpath (sys .argv [0 ]))
30
30
31
31
@@ -45,13 +45,13 @@ def __init__(self, configpath):
45
45
"mcellr.yaml" )
46
46
sys .exit (0 )
47
47
48
- def processMDLR (self , mdlrPath ):
48
+ def process_mdlr (self , mdlrPath ):
49
49
'''
50
50
main method. extracts species definition, creates bng-xml, creates mdl
51
51
definitions
52
52
'''
53
53
try :
54
- nautyDict = self .xml2HNautySpeciesDefinitions (mdlrPath )
54
+ nauty_dict = self .xml2hnauty_species_definitions (mdlrPath )
55
55
except OSError :
56
56
print ("Cannot open BNG2.pl. Please check bionetgen in mcellr.yaml" )
57
57
sys .exit (0 )
@@ -65,11 +65,11 @@ def processMDLR(self, mdlrPath):
65
65
66
66
xmlspec = read_bngxml .parseFullXML (namespace .input + '.xml' )
67
67
# write out the equivalent plain mdl stuffs
68
- mdlDict = write_mdl .constructMCell (
69
- xmlspec , namespace .input , finalName .split (os .sep )[- 1 ], nautyDict )
70
- write_mdl .writeMDL (mdlDict , finalName )
68
+ mdlDict = write_mdl .construct_mcell (
69
+ xmlspec , namespace .input , finalName .split (os .sep )[- 1 ], nauty_dict )
70
+ write_mdl .write_mdl (mdlDict , finalName )
71
71
72
- def tokenizeSeedElements (self , seed ):
72
+ def tokenize_seed_elements (self , seed ):
73
73
# extract species names
74
74
seedKeys = re .findall (
75
75
'concentration="[0-9a-zA-Z_]+" name="[_0-9a-zA-Z@:(~!),.]+"' , seed )
@@ -88,11 +88,11 @@ def tokenizeSeedElements(self, seed):
88
88
# print '---', seedDict.keys()
89
89
return seedDict
90
90
91
- def getNamesFromDefinitionString (self , defStr ):
91
+ def get_names_from_definition_string (self , defStr ):
92
92
speciesNames = re .findall ('[0-9a-zA-Z_]+\(' , defStr )
93
93
return [x [:- 1 ] for x in speciesNames ]
94
94
95
- def xml2HNautySpeciesDefinitions (self , inputMDLRFile ):
95
+ def xml2hnauty_species_definitions (self , inputMDLRFile ):
96
96
"""
97
97
Temporary function for translating xml bng definitions to nautty
98
98
species definition strings
@@ -117,36 +117,36 @@ def xml2HNautySpeciesDefinitions(self, inputMDLRFile):
117
117
with open (namespace .input + '_total.xml' , 'w' ) as f :
118
118
f .write (rest )
119
119
# load up nfsim library
120
- self .nfsim .initNFsim (namespace .input + '_total.xml' , 0 )
120
+ self .nfsim .init_nfsim (namespace .input + '_total.xml' , 0 )
121
121
122
122
# remove encapsulating tags
123
123
seed = seed [30 :- 30 ]
124
124
# get the seed species definitions as a list
125
- seedDict = self .tokenizeSeedElements (seed )
125
+ seedDict = self .tokenize_seed_elements (seed )
126
126
127
- nautyDict = {}
127
+ nauty_dict = {}
128
128
for seed in seedDict :
129
129
# initialize nfsim with each species definition and get back a
130
130
# dirty list where one of the entries is the one we want
131
131
#
132
132
# XXX: i think i've solved it on the nfsim side, double check
133
- tmpList = self .getNautyString (seedDict [seed ])
133
+ tmpList = self .get_nauty_string (seedDict [seed ])
134
134
# and now filter it out...
135
135
# get species names from species definition string
136
- speciesNames = self .getNamesFromDefinitionString (seed )
137
- nautyDict [seed ] = [x for x in tmpList if all (y in x for y in speciesNames )][0 ]
136
+ speciesNames = self .get_names_from_definition_string (seed )
137
+ nauty_dict [seed ] = [x for x in tmpList if all (y in x for y in speciesNames )][0 ]
138
138
139
- return nautyDict
139
+ return nauty_dict
140
140
141
- def getNautyString (self , xmlSpeciesDefinition ):
142
- self .nfsim .resetSystem ()
143
- self .nfsim .initSystemXML (xmlSpeciesDefinition )
141
+ def get_nauty_string (self , xmlSpeciesDefinition ):
142
+ self .nfsim .reset_system ()
143
+ self .nfsim .init_system_xml (xmlSpeciesDefinition )
144
144
result = self .nfsim .querySystemStatus ("complex" )
145
145
return result
146
146
147
147
148
148
if __name__ == "__main__" :
149
- parser = defineConsole ()
149
+ parser = define_console ()
150
150
namespace = parser .parse_args ()
151
151
bnglPath = namespace .input + '.bngl'
152
152
finalName = namespace .output if namespace .output else namespace .input
@@ -172,11 +172,11 @@ def getNautyString(self, xmlSpeciesDefinition):
172
172
mdlDict = write_mdl .constructMDL (
173
173
namespace .input + '_sbml.xml.json' , namespace .input , finalName )
174
174
# create an mdl with nfsim-species and nfsim-reactions
175
- write_mdl .writeMDL (mdlDict , finalName )
175
+ write_mdl .write_mdl (mdlDict , finalName )
176
176
else :
177
177
try :
178
- mdlr2mdl = MDLR2MDL (os .path .join (getScriptPath (), 'mcellr.yaml' ))
179
- mdlr2mdl .processMDLR (namespace .input )
178
+ mdlr2mdl = MDLR2MDL (os .path .join (get_script_path (), 'mcellr.yaml' ))
179
+ mdlr2mdl .process_mdlr (namespace .input )
180
180
except IOError :
181
181
print ("Please create mcellr.yaml in the mcellRules directory. Use "
182
182
"mcellr.yaml.template as a reference." )
0 commit comments