Exemple #1
0
def process_reaction_rules(rules):
    rStr = StringIO()
    rStr.write('begin reaction rules\n')
    for rule in rules:
        tmp_rule = st.Rule()
        for pattern in rule['reactants']:
            tmp_rule.addReactant(create_species_from_pattern(pattern))
        for pattern in rule['products']:
            tmp_rule.addProduct(create_species_from_pattern(pattern))
        for rate in rule['rate']:
            tmp_rule.addRate(rate)
        rStr.write('\t{0}\n'.format(str(tmp_rule)))

    rStr.write('end reaction rules\n')
    return rStr.getvalue()
Exemple #2
0
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