Beispiel #1
0
def parseMolecules(molecules):
    '''
    Parses an XML molecule section
    Returns: a molecule structure
    '''

    mol = st.Molecule(molecules.get('id'),molecules.get('id'))
    components = \
      molecules.find('.//{http://www.sbml.org/sbml/level3}ListOfComponentTypes')
    if components != None:
        for component in components.getchildren():
            comp = parseComponent(component)
            mol.addComponent(comp)
    return mol       
Beispiel #2
0
def createMolecule(molecule, bonds):
    nameDict = {}
    mol = st.Molecule(molecule.get('name'),molecule.get('id'))
    if molecule.get('compartment') not in ['',None]:
        mol.setCompartment(molecule.get('compartment'))
    nameDict[molecule.get('id')] = molecule.get('name')
    listOfComponents =  molecule.find('.//{http://www.sbml.org/sbml/level3}ListOfComponents')
    if listOfComponents != None:
        for element in listOfComponents:
            component = st.Component(element.get('name'),element.get('id'))
            nameDict[element.get('id')] = element.get('name')
            if element.get('numberOfBonds') in ['+','?']:
                component.addBond(element.get('numberOfBonds'))
            elif element.get('numberOfBonds') != '0':
                component.addBond(findBond(bonds, element.get('id')))
            state = element.get('state') if element.get('state') != None else ''
            component.states.append(state)
            component.activeState = state
            mol.addComponent(component)
    return mol, nameDict
Beispiel #3
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