Exemplo n.º 1
0
def mergeASM(modelfile, outputfile, prefix='exp'):
    '''!
    Function to read the AdvanceSyn model specification file(s) 
    and merge them into a single AdvanceSyn model specification 
    file.

    Usage:

        python astools.py mergeASM --prefix=exp --modelfile=models/asm/glycolysis.modelspec;models/asm/RFPproduction.modelspec --outputfile=models/asm/glycolysis_RFP.modelspec

    @param modelfile String: Relative path(s) to the model specification 
    file(s), separated by semi-colon. 
    @param outputfile String: Relative path to the output model 
    objects file.
    @param prefix String: Prefix for new reaction IDs. This prefix 
    cannot be any existing prefixes in any of the model specifications 
    to be merged. Default = 'exp'.
    '''
    specList = []
    modelobjList = []
    modelfile = [x.strip() for x in modelfile.split(';')]
    print('Input Model File(s) ...')
    count = 1
    for mf in modelfile:
        mf = os.path.abspath(mf)
        print('ASM Model File %s: %s' % (count, mf))
        (spec, modelobj) = modelReader(mf, 'ASM', 'basic')
        specList.append(spec)
        modelobjList.append(modelobj)
        count = count + 1
    print('')
    (merged_spec, merged_modelobj) = \
        ASModeller.modelMerge(specList, modelobjList, prefix, 
                              True, False)
    filepath = os.path.abspath(outputfile)
    print('Output AdvanceSyn Model Specification File: ' + filepath)
    outfile = open(filepath, 'w')
    merged_spec.write(outfile)
    outfile.close()
Exemplo n.º 2
0
def generateModelObject(modelfile, outputfile, prefix='exp'):
    '''!
    Function to read the AdvanceSyn model specification file(s) 
    and generate a file consisting of the internal model objects.

    Usage:

        python astools.py genMO --prefix=exp --modelfile=models/asm/glycolysis.modelspec;models/asm/RFPproduction.modelspec --outputfile=models/mo/glycolysis.mo

    @param modelfile String: Relative path(s) to the model specification 
    file(s), separated by semi-colon. 
    @param outputfile String: Relative path to the output model 
    objects file.
    @param prefix String: Prefix for new reaction IDs. This prefix 
    cannot be any existing prefixes in any of the model specifications 
    to be merged. Default = 'exp'.
    '''
    specList = []
    modelobjList = []
    modelfile = [x.strip() for x in modelfile.split(';')]
    print('Input Model File(s) ...')
    count = 1
    for mf in modelfile:
        mf = os.path.abspath(mf)
        print('ASM Model File %s: %s' % (count, mf))
        (spec, modelobj) = modelReader(mf, 'ASM', 'extended')
        specList.append(spec)
        modelobjList.append(modelobj)
        count = count + 1
    print('')
    (merged_spec, merged_modelobj) = \
        ASModeller.modelMerge(specList, modelobjList, prefix, 
                              True, True)
    filepath = os.path.abspath(outputfile)
    print('Output Model Objects File: ' + filepath)
    with open(filepath, 'wb') as f:
        dumpdata = (merged_spec, merged_modelobj)
        pickle.dump(dumpdata, f, pickle.HIGHEST_PROTOCOL)