Example #1
0
def flattenMotif(combined):
    #flatten the combined model by converting it to sbml and then converting back to Antimony
    antimony.clearPreviousLoads()
    code = antimony.loadAntimonyString(combined)
    if code <= 0:
        textfile = open('combined.txt', 'w')
        textfile.write(combined)
        textfile.close()
        raise AssertionError(
            'combined model is not flattenable. Are you using the right species names? '
            + 'Combined model saved as: ' + str(os.getcwd()) +
            '\\combined.txt')
    sbmlStr = antimony.getSBMLString('combined')
    antimony.loadSBMLString(sbmlStr)
    flatComb = antimony.getAntimonyString('combined')

    ####TODO
    #Delete extraneous mRNA -> Protein reactions at P_c connections
    #look for p_c#, regex
    #delete second equation with occurance of p_c#curr, regex

    #todo: remove extraneous species + parameters in the removed equation

    ####TODO
    return (flatComb)
Example #2
0
def sbmlToAntimony(str):
    """Convert a SBML string into Antimony:

    sbmlStr = sbmlToAntimony (antimonyStr)
    """
    err = antimony.loadSBMLString(str)

    if err < 0:
        raise Exception("Antimony: " + antimony.getLastError())

    return antimony.getAntimonyString(None)
def sbmlToCellML(sbml):
    """ Convert SBML to CellML string.

    :param sbml: SBML string or file
    :type sbml: str | file
    :return: CellML
    :rtype: str
    """
    if os.path.isfile(sbml):
        code = antimony.loadSBMLFile(sbml)
    else:
        code = antimony.loadSBMLString(sbml)
    _checkAntimonyReturnCode(code)
    return antimony.getCellMLString(None)
Example #4
0
def sbmlToCellML(sbml):
    """ Convert SBML to CellML string.

    :param sbml: SBML string or file
    :type sbml: str | file
    :return: CellML
    :rtype: str
    """
    if os.path.isfile(sbml):
        code = antimony.loadSBMLFile(sbml)
    else:
        code = antimony.loadSBMLString(sbml)
    _checkAntimonyReturnCode(code)
    return antimony.getCellMLString(None)
Example #5
0
def sbmlToAntimony(sbml):
    """ Convert SBML to antimony string.

    :param sbml: SBML string or file
    :type sbml: str | file
    :return: Antimony
    :rtype: str
    """
    isfile = False
    try:
        isfile = os.path.isfile(sbml)
    except:
        pass
    if isfile:
        code = antimony.loadSBMLFile(sbml)
    else:
        code = antimony.loadSBMLString(str(sbml))
    _checkAntimonyReturnCode(code)
    return antimony.getAntimonyString(None)
Example #6
0
def sbmlToAntimony(sbml):
    """ Convert SBML to antimony string.

    :param sbml: SBML string or file
    :type sbml: str | file
    :return: Antimony
    :rtype: str
    """
    isfile = False
    try:
        isfile = os.path.isfile(sbml)
    except:
        pass
    if isfile:
        code = antimony.loadSBMLFile(sbml)
    else:
        code = antimony.loadSBMLString(str(sbml))
    _checkAntimonyReturnCode(code)
    return antimony.getAntimonyString(None)
Example #7
0
    def sbmlToAntimony(self, sbml, addSBO=False):
        """ Converts a raw SBML string to Antimony source.

        :param sbml: The raw SBML string
        :returns: A 2-tuple (module_name, antimony_source)
        """

        import antimony as sb
        # try to load the Antimony code`
        code = sb.loadSBMLString(sbml)

        # if errors, bail
        if self.checkAntimonyReturnCode(code):
            errors = sb.getLastError()
            raise RuntimeError('Errors encountered when trying to load model:\n{}'.format(errors))

        module = sb.getMainModuleName()
        sb_source = sb.getAntimonyString(module)
        if addSBO:
            sb_source = self.tryAddSBOTerms(sb_source, sbml_str=sbml)
        return (module, sb_source)
Example #8
0
    def sbmlToAntimony(self, sbml, addSBO=False):
        """ Converts a raw SBML string to Antimony source.

        :param sbml: The raw SBML string
        :returns: A 2-tuple (module_name, antimony_source)
        """

        import antimony as sb
        # try to load the Antimony code`
        code = sb.loadSBMLString(sbml)

        # if errors, bail
        if self.checkAntimonyReturnCode(code):
            errors = sb.getLastError()
            raise RuntimeError('Errors encountered when trying to load model:\n{}'.format(errors))

        module = sb.getMainModuleName()
        sb_source = sb.getAntimonyString(module)
        if addSBO:
            sb_source = self.tryAddSBOTerms(sb_source, sbml_str=sbml)
        return (module, sb_source)
Example #9
0
#    #!!module names have to be identical to model names from imported models!!
#    A : model1();
#    B : model2();
#    #repeat for all models I have
#    #specify a global input node
#    var species p_c;
#    A.p_input is p_c;
#    B.p_output is p_c;
#    #repeat for n-1 modules
# end
# '''

#properly flatten the combined model
antimony.loadAntimonyString(combined)
sbmlstr = antimony.getSBMLString('combined')
antimony.loadSBMLString(sbmlstr)
flatcomb = antimony.getAntimonyString('combined')

r = te.loada(flatcomb)
r.exportToAntimony('combined.txt')
r.draw(layout='dot')

#combined =  reads +  '''
#model combined
#    var species p_c;
#    #!!module names have to be identical to model names from imported models!!
#    A : ffl1();
#    B : ffl1();
#    A.p_input is p_c;
#    B.p_output is p_c;
#end