Example #1
0
 def test_reconstruct(self, b_theta_genome_id, b_theta_id, b_theta_name):
     stats = mackinac.reconstruct_modelseed_model(b_theta_genome_id, model_id=b_theta_id)
     assert stats['id'] == b_theta_id
     assert stats['name'] == b_theta_name
     assert stats['num_compartments'] == 2
     assert stats['num_genes'] == 739
     assert stats['num_biomass_compounds'] == 85
     assert stats['source'] == 'PATRIC'
Example #2
0
    f.close()
    return templist


#Script
path = '/home/jan/sbml_models/'
input_list = read_list('/home/jan/Downloads/PATRIC_genome.csv',
                       skip_first_line=True)
modelled_strain_ids = []

model_dict = {}
gapfilled_model_dict = {}
mackinac.get_token('JBaijens')
for patric_id in input_list[43:]:  #CHANGE THIS IF RESTARTING
    try:
        mackinac.reconstruct_modelseed_model(patric_id)
    except:
        pass
    model_dict[patric_id] = mackinac.create_cobra_model_from_modelseed_model(
        patric_id)
    tempmodel = model_dict[patric_id]
    if len(tempmodel.genes) > 299:
        tempname = path + patric_id + '.sbml'
        cobra.io.write_sbml_model(tempmodel, tempname)
        modelled_strain_ids.append(patric_id)
        print 'Added model %s to model_dict.' % patric_id
        try:
            mackinac.gapfill_modelseed_model(patric_id)
        except:
            pass
        gapfilled_model_dict[
Example #3
0
def create_species_models(genome_ids,
                          output_folder,
                          replace=False,
                          optimize=False):
    """ Create ModelSEED models from a list of PATRIC genome IDs.

    The ModelSEED server can be overwhelmed by too many requests so reconstructing
    models is single-threaded (and got weird errors trying to use multiprocessing).

    Parameters
    ----------
    genome_ids : list of str
        List of PATRIC genome IDs
    output_folder: str
        Path to folder where single species models are stored
    replace : bool, optional
        When True, always reconstruct model using ModelSEED service and replace local model
    optimize : bool, optional
        When True, optimize the model and check for growth

    Returns
    -------
    list of str
        List of paths to single species model files
    """

    # Get a model for each genome in the list.
    output_models = list()
    for genome_id in genome_ids:
        # If possible, use the model that was previously obtained from ModelSEED.
        model_filename = join(output_folder, '{0}.json'.format(genome_id))
        if exists(model_filename) and not replace:
            output_models.append(model_filename)
        else:
            reconstruct = False
            try:
                get_modelseed_model_stats(genome_id)
                if replace:
                    delete_modelseed_model(genome_id)
                    reconstruct = True
            except ObjectNotFoundError:
                reconstruct = True

            # If needed, reconstruct and gap fill a model from the genome.
            if reconstruct:
                reconstruct_modelseed_model(genome_id)
                gapfill_modelseed_model(genome_id)

            # Create a COBRA model and save in JSON format.
            model = create_cobra_model_from_modelseed_model(genome_id)
            save_json_model(model, model_filename)
            output_models.append(model_filename)

    # If requested, verify ModelSEED models produce growth.
    if optimize:
        for model_filename in output_models:
            model = load_json_model(model_filename)
            solution = model.optimize()
            if solution.f <= 0.0001:
                warn('Model {0} does not produce growth'.format(model.id))
    return output_models
Example #4
0
mackinac.genome.patric_url = 'https://www.patricbrc.org/api/'
mackinac.get_token('asuccurro')

orgs = {'Root491': '1736548.3', 'Root9': '1736604.3', 'Root66D1': '1736582.3'}

mymodels = mackinac.list_modelseed_models()
mymodelsnames = ';'.join(map(lambda y: y['ref'], mymodels))

gprs = {'Root491': {}, 'Root9': {}, 'Root66D1': {}}

for o in ['Root491', 'Root9', 'Root66D1']:
    #for o in ['Root491']:
    if orgs[o] not in mymodelsnames:
        print('Reconstructing modelseed model for', o, '(', orgs[o], ')')
        mackinac.get_genome_summary(orgs[o])
        mackinac.reconstruct_modelseed_model(orgs[o])
        mackinac.get_modelseed_model_stats(orgs[o])
    model = mackinac.get_modelseed_model_data(orgs[o])
    for r in model['modelreactions']:
        tmpgprs = []
        for p in r['modelReactionProteins']:
            for s in p['modelReactionProteinSubunits']:
                if s['feature_refs'] == []:
                    print(s)
                    gpr = 'Unknown'
                else:
                    gpr = ' OR '.join(
                        map(lambda y: y.split('/')[-1], s['feature_refs']))
                tmpgprs.append('(%s)' % gpr)
        gprs[o][r['id']] = ' AND '.join(tmpgprs)
Example #5
0
def test_model(b_theta_genome_id, b_theta_id):
    # Reconstruct a model so there is a folder in the workspace.
    stats = mackinac.reconstruct_modelseed_model(b_theta_genome_id,
                                                 model_id=b_theta_id)
    yield stats
    mackinac.delete_modelseed_model(b_theta_id)