Esempio n. 1
0
def db_model(pub_model):
    # dump the model
    start = time()
    # take out special characters from model bigg_id
    db_model = dump_model(pub_model.id.replace('.', '_'))
    print("Dumped %s in %.2f sec" % (pub_model.id, time() - start))
    return db_model
Esempio n. 2
0
def write_static_model(bigg_id, model_polisher_path):
    """Write out static files for a model with the given BiGG ID.

    This will output compressed and uncompressed SBML L3 + FBCv2, JSON,
    and MAT files.

    """
    success = True
    print('Dumping model')
    t = time.time()
    model = dump_model(bigg_id)
    print('Dumping finished in %.2f seconds' % (time.time() - t))
    sbml_filepath = join(static_dir, bigg_id + '.xml')
    try:
        print('Writing SBML')
        t = time.time()
        cobra.io.write_sbml_model(model, sbml_filepath)
        print('Writing SBML finished in %.2f seconds' % (time.time() - t))
    except Exception as e:
        success = False
        print('failed to export sbml model "%s": %s' % (bigg_id, e.message))
    else:
        print('Compressing')
        t = time.time()
        system('gzip --keep --force --best ' + sbml_filepath)
        print('Compressing finished in %.2f seconds' % (time.time() - t))
        # else:
        #     success = False

    print('Writing MAT')
    t = time.time()
    mat_filepath = join(static_dir, bigg_id + '.mat')
    cobra.io.save_matlab_model(model, mat_filepath)
    system('gzip --keep --force --best ' + mat_filepath)
    print('Writing MAT finished in %.2f seconds' % (time.time() - t))

    print('Writing JSON')
    t = time.time()
    json_filepath = join(static_dir, bigg_id + '.json')
    cobra.io.save_json_model(model, json_filepath)
    system('gzip --keep --force --best ' + json_filepath)
    print('Writing JSON finished in %.2f seconds' % (time.time() - t))

    return success
Esempio n. 3
0
def test_cannot_dump_unknown_model(dumped_model, session):
    with pytest.raises(Exception):
        dump_model('C3PO', session)
Esempio n. 4
0
def dumped_model(load_models, session):
    bigg_id = 'Ecoli_core_model'
    model = dump_model(bigg_id)
    return model
Esempio n. 5
0
def write_static_model(bigg_id, model_polisher_path):
    """Write out static files for a model with the given BiGG ID.

    This will output compressed and uncompressed SBML L3 + FBCv2, JSON,
    and MAT files.

    """
    success = True
    print('Dumping model')
    t = time.time()
    model = dump_model(bigg_id)
    print('Dumping finished in %.2f seconds' % (time.time() - t))
    raw_sbml_filepath = join(static_dir, 'raw', bigg_id + '.xml')
    sbml_filepath = join(static_dir, bigg_id + '.xml')
    try:
        print('Writing SBML')
        t = time.time()
        cobra.io.write_sbml_model(model, raw_sbml_filepath)
        print('Writing SBML finished in %.2f seconds' % (time.time() - t))
    except Exception as e:
        success = False
        print('failed to export sbml model "%s": %s' % (bigg_id, e.message))
    else:
        # polish
        print('Polishing')
        t = time.time()
        command = [settings.java,
                   '-jar',
                   '-Xms8G',
                   '-Xmx8G',
                   '-Xss128M',
                   '-Duser.language=en',
                   model_polisher_path,
                   '--user=%s' % settings.postgres_user,
                   '--passwd=%s' % settings.postgres_password,
                   '--host=%s' % settings.postgres_host,
                   '--dbname=%s' % settings.postgres_database,
                   '--input=%s' % raw_sbml_filepath,
                   '--output=%s' % static_dir,
                   '--compression-type=NONE',
                   '--check-mass-balance=true',
                   '--omit-generic-terms=false',
                   '--log-level=OFF',
                   '--include-any-uri=false',
                   '--annotate-with-bigg=true']
        polish_result = call(command)
        print('Polishing finished in %.2f seconds' % (time.time() - t))
        if polish_result == 0:
            # compress model
            print('Compressing')
            t = time.time()
            system('gzip --keep --force --best ' + sbml_filepath)
            print('Compressing finished in %.2f seconds' % (time.time() - t))
        else:
            success = False

    print('Writing MAT')
    t = time.time()
    mat_filepath = join(static_dir, bigg_id + '.mat')
    cobra.io.save_matlab_model(model, mat_filepath)
    system('gzip --keep --force --best ' + mat_filepath)
    print('Writing MAT finished in %.2f seconds' % (time.time() - t))

    print('Writing JSON')
    t = time.time()
    json_filepath = join(static_dir, bigg_id + '.json')
    cobra.io.save_json_model(model, json_filepath)
    system('gzip --keep --force --best ' + json_filepath)
    print('Writing JSON finished in %.2f seconds' % (time.time() - t))

    return success
Esempio n. 6
0
def test_cannot_dump_unknown_model(dumped_model, session):
    with pytest.raises(Exception):
        dump_model('C3PO', session)
Esempio n. 7
0
def dumped_model(load_models, session):
    bigg_id = 'Ecoli_core_model'
    model = dump_model(bigg_id)
    return model