from pyscescbm.CBVersion import __DEBUG__, __version__
from pyscescbm import CBRead, CBWrite, CBTools
from pyscescbm import CBSolver as slv

work_dir = os.path.join(cDir, work_dir)
if not os.path.exists(work_dir):
    os.mkdir(work_dir)

if sbml_level == 3:
    print('Trying level 3')
    cmod = CBRead.readSBML3FBC(model_file, work_dir=model_dir)
else:
    cmod = CBRead.readSBML2FBA(model_file, work_dir=model_dir)
cmod.id = model_name

slv.analyzeModel(cmod, lpFname=os.path.join(work_dir, 'raw_({0:s})'.format(cmod.id)))

# scan for duplicates
print('\nScan for duplicates')
dup_C = CBTools.scanForReactionDuplicates(cmod, ignore_coefficients=False)
print('\nReaction pairs with matching reagents and coefficients: {0:d}'.format( len(dup_C) ))
for d in dup_C:
    print('{0:s} == {1:s} ({2:s})'.format(d[0],d[1],d[2]))

# write duplicate reactions to file
F = open(os.path.join(model_dir,'{0:s}.duplicates.csv'.format(model_file)),'w')
F.write('Model file: {0:s},,,,\n'.format( model_file) )
F.write('Duplicate reactions pairs: {0:d},,,,\n'.format( len(dup_C) ) )
for d in dup_C:
    F.write('\"{0:s}\",\"{1:s}\",\"{2:s}\",\"{3:s}\",\"{4:s}\"\n'.format(d[0],d[1],d[2],d[3],d[4]))
F.write('\n')
コード例 #2
0
work_dir2 = os.path.join(data_dir,'models','h-format')

if not os.path.exists(work_dir2):
    os.makedirs(work_dir2)

if sbml_level == 3:
    print('Trying level 3')
    cmod = CBRead.readSBML3FBC(model_file, work_dir=model_dir)
else:
    cmod = CBRead.readSBML2FBA(model_file, work_dir=model_dir)

cmod.id = model_name
print('\nAttempting to delete bounds for biomass reaction,', cmod.getActiveObjective().getFluxObjectiveReactions()[0])
cmod.deleteBoundsForReactionId(cmod.getActiveObjective().getFluxObjectiveReactions()[0])

mLP = slv.analyzeModel(cmod, return_lp_obj=True)
CBWrite.printFBASolution(cmod)
tmp_mid = cmod.id+'_cplex'

CBTools.countedPause(1)

cmod.id = tmp_mid

print('\n{0:d}\n'.format(len(cmod.flux_bounds)) )
cmod.changeAllFluxBoundsWithValue(inf_bound, 'Infinity')
cmod.changeAllFluxBoundsWithValue(-inf_bound, '-Infinity')
cmod.changeAllFluxBoundsWithValue(numpy.inf, 'Infinity')
cmod.changeAllFluxBoundsWithValue(-numpy.inf, '-Infinity')

print('\n{0:d}\n'.format(len(cmod.flux_bounds)) )
slv.analyzeModel(cmod, lpFname=os.path.join(work_dir2, cmod.id), oldlpgen=False)
コード例 #3
0
    """
    write calculate module to a csv file
    """
    file_path = os.path.join(modules_dir,"modules.txt")
    file_out = open(file_path,"w")        
    for module in flux_modules:
        if len(module) > 1:       # modules should contain more than one reaction
            for item in module[:-1]:
               file_out.write("{0}, ".format(item))
            file_out.write("{0}\n".format(module[-1]))
    file_out.close()

if not os.path.exists(work_dir2):
    os.makedirs(work_dir2)

if sbml_level == 3:
    print('Trying level 3')
    cmod = CBRead.readSBML3FBC(model_file, work_dir=model_dir)
else:
    cmod = CBRead.readSBML2FBA(model_file, work_dir=model_dir)
    
if solver.upper() == "CPLEX":
    fva_dat, fva_names = CBMultiCore.runMultiCoreFVA(cmod,procs=ncores)       
elif solver.upper() == "GLPK":
    fva_dat,fva_names = slv.glpk_FluxVariabilityAnalysis(cmod)    
else: 
    fva_dat, fva_names = CBMultiCore.runMultiCoreFVA(cmod,procs=ncores)     
    
lst_flux_modules = fmod.computeModules(cmod,tol=tolerance)    
writeModule2CSV(lst_flux_modules)