return dist


if __name__ == "__main__":  #If the module is executed as a program, run a test.
    from cobra.io.sbml import read_sbml_model
    cobramodel = read_sbml_model('../SBML/SCHUETZR.xml')
    import loadData as load
    fluxvalues = load.ExpFluxesfromXML('expdata.xml', 'Perrenoud', 'Batch',
                                       'aerobe')
    rmap = load.ReactionMapfromXML('reactionmaps.xml', 'Perrenoud', 'SCHUETZR')

    optreq = 1.0

    import QPmindist as qp

    gurobimodel = qp.QPmindist(cobramodel, fluxvalues, rmap, optreq)

    QPsolutiondict = qp.getgurobisolutiondict(gurobimodel)

    import extractflux2 as extract

    extractfluxdict = extract.extractfluxdict(QPsolutiondict, rmap)

    dictdist = compdistdict(extractfluxdict)

    print('dist:', dictdist)

    simple1 = {"A": 1, "B": 2, "C": 3}
    simple2 = {"A": 1, "B": 2, "C": 4}
    simpledist = compdistdict(simple1, expdata=simple2)
Пример #2
0
def optreqanalysis(modeldicts,
                   objectives,
                   experiments,
                   steps=10,
                   makeplots=True,
                   expfluxdict="Default",
                   plotter="easyviz"):
    '''Function for evaluating how the minimally achievable distance between a flux solution and a set of experimental fluxes
    changes when varying the required relative FBA objective-optimality of the flux solution.

    syntax: optreqanalysis(modeldicts,objectives,experiments,steps = 10,makeplots = True,expfluxdict)

    arguments:
    modeldicts: An array of python dictionaries with the following fields:
        modelobject: A CobraPy model object for the model in question.
        reactionmap: A reaction map array mapping between model reactions and experimental reactions for the model and experiment in question.
    objectives: A list of objectives to be used in the analysis.
    experiments: A list of experiments to be used in the analysis
    steps: The granularity of the analysis and produced plots.
    makeplots: Whether plots should be produced or not
    expfluxdict: A python dictionary with experiment-ids as keys and the corresponding flux value arrays as values.
    '''
    for objective in objectives:
        pass  #Placeholder

    for experiment in experiments:
        pass  #Placeholder

    if expfluxdict == "Default":  #This section should be rewritten to use an "expflux" dict.
        expdata = scipy.io.loadmat('expdata.mat')  #load experimentaldata
        perrenoud = expdata['expdata']['perrenoud']
        fluxvalarray = perrenoud[0][0][0][0][0][0][0][0][0][0][0][0][0][0]
        fluxvalues = [row[0] for row in fluxvalarray
                      ]  #expdata.perrenoud.abs.batch.aerobe.fluxvalues

        expfluxdict = load.ExpFluxesfromXML('expdata.xml', 'Perrenoud',
                                            'Batch', 'aerobe')

    resultlist = []
    for modeldict in modeldicts:
        cobramodel = modeldict['modelobject']
        #print 'modeldict:',modeldict
        reactionmap = modeldict['reactionmap']
        #print 'cobramodel:',cobramodel
        #print type(cobramodel)

        optreqs = []
        for i in range(steps + 1):
            optreqs.append(float(i) / steps)
        results = []
        #print 'opreqs:',optreqs
        #q = raw_input('Continue?')
        for optreq in optreqs:
            optimizedmodel = QPmindist(cobramodel, fluxvalues, reactionmap,
                                       optreq)
            results.append(math.sqrt(optimizedmodel.ObjVal))
        resultlist.append(results)
        #Using easyviz
        #ev.plot(optreqs,results)
        #ev.hold()

        #Using prettyplotlib
        #fig, ax = plt.subplots(1)
        #ppl.scatter(ax, x, y)
        #ppl.plot(optreqs,results)
    return resultlist