def create_species_from_pattern(speciesPattern): tmp_species = st.Species() if 'speciesCompartment' in speciesPattern.keys(): tmp_species.compartment = speciesPattern['speciesCompartment'][1] for idx, element in enumerate(speciesPattern['speciesPattern']): tmp_species.addMolecule(create_molecule_from_pattern(element, idx)) return tmp_species
def createSpecies(pattern): tmpDict = {} species = st.Species() species.idx = pattern.get('id') species.trueName = pattern.get('name') compartment = pattern.get('compartment') if compartment != None: species.compartment = compartment mol = pattern.find('.//{http://www.sbml.org/sbml/level3}ListOfMolecules') bonds = pattern.find('.//{http://www.sbml.org/sbml/level3}ListOfBonds') for molecule in mol.getchildren(): molecule, nameDict = createMolecule(molecule, bonds) tmpDict.update(nameDict) species.addMolecule(molecule) if bonds != None: species.bonds = [(bond.get('site1'), bond.get('site2')) for bond in bonds] tmpDict.update(nameDict) return species, tmpDict
def parseRule(rule, parameterDict): ''' Parses a rule XML section Returns: a list of the reactants and products used, followed by the mapping between the two and the list of operations that were performed ''' rp = rule.find( './/{http://www.sbml.org/sbml/level3}ListOfReactantPatterns') pp = rule.find('.//{http://www.sbml.org/sbml/level3}ListOfProductPatterns') mp = rule.find('.//{http://www.sbml.org/sbml/level3}Map') op = rule.find('.//{http://www.sbml.org/sbml/level3}ListOfOperations') rt = rule.find('.//{http://www.sbml.org/sbml/level3}RateLaw') nameDict = {} reactants = [] products = [] actions = [] mappings = [] if len(rp) == 0: sp = st.Species() ml = st.Molecule('0', '') sp.addMolecule(ml) reactants.append(sp) if len(pp) == 0: sp = st.Species() ml = st.Molecule('0', '') sp.addMolecule(ml) products.append(sp) for pattern in rp: elm, tmpDict = createSpecies(pattern) reactants.append(elm) nameDict.update(tmpDict) for pattern in pp: elm, tmpDict = createSpecies(pattern) products.append(elm) nameDict.update(tmpDict) for operation in op: action = st.Action() tag = operation.tag tag = tag.replace('{http://www.sbml.org/sbml/level3}', '') if operation.get('site1') != None: action.setAction(tag, operation.get('site1'), operation.get('site2')) else: action.setAction(tag, operation.get('site'), None) actions.append(action) for mapping in mp: tmpMap = (mapping.get('sourceID'), mapping.get('targetID')) mappings.append(tmpMap) rateConstants = rt.find( './/{http://www.sbml.org/sbml/level3}ListOfRateConstants') if rateConstants == None: rateConstants = rt.get('name') else: for constant in rateConstants: tmp = constant.get('value') rateConstants = tmp rateConstantsValue = parameterDict[ rateConstants] if rateConstants in parameterDict else rateConstants #rule = st.Rule() label = rule.get('name') label = label.replace('(', '_').replace(')', '_') rule = st.Rule(label) rule.addReactantList(reactants) rule.addProductList(products) rule.addActionList(actions) rule.addMappingList(mappings) rule.addRate(rateConstants) # return reactants, products, actions, mappings, nameDict,rateConstantsValue,rateConstants return rule, nameDict, rateConstantsValue, rateConstants