Projects

Projects are at the heart of gsmodutils. Essentially, a project is a directory that contains all the models, designs, conditions and other gsmodutils tools such as Docker files.

Creating projects

Project creation is best done with the command line utility. This provides a step by step guide for project creation.

$ gsmodutils init PROJECT_PATH MODEL_PATH

Alternatively, this can be done in python using the GSMProject class.

from gsmodutils import GSMProject
from cameo import models

model = models.bigg.e_coli_core

# Note, running more than once will throw an error.
# Projects can't be created in the folder more than once.
project = GSMProject.create_project(
    models=[model],
    description='Example ecoli core model',
    author='A user',
    author_email='A.user@example.com',
    project_path='example_project'
)

Using the cli lets have a look inside the newly created project:

$ gsmodutils create_project ./example_project e_coli_core.json
...
$ cd example_project
$ gsmodutils info
--------------------------------------------------------------------------------------------------
Project description - Example ecoli core model
Author(s): - A user
Author email - A.user@example.com
Designs directory - designs
Tests directory - tests

Models:
        * e_coli_core.json
                 e_coli_core
--------------------------------------------------------------------------------------------------

This will also allow access to a project object that can be used to access gsmodutils features, such as accessing models

from gsmodutils import GSMProject
project = GSMProject('example_project')
# load the default model
model = project.load_model()

It is now recomended that you use source control, such as git or mercurial, create a repository and add the project to it to track all changes to models that are made over the course of the project.

Adding conditions

In many cases it is desirable to compare models configured with different growth conditions. In this simplistic example we show how conditions can be adjusted by switching the growth media from glucose to fructose. This setting can then be saved and reloaded at a later time.

from gsmodutils import GSMProject
# Load existing project
project = GSMProject('example_project')
model = project.model

# Switching off glucose uptake
model.reactions.EX_glc__D_e.lower_bound = 0
# switching on Xylose uptake
model.reactions.EX_fru_e.lower_bound = -10
# Check it works
s = model.optimize()
project.save_conditions(model, 'fructose_growth')

Loading them back should now be straightforward:

# loading the conditions back into a different model
fructose_m = project.load_conditions('fructose_growth')

# These will raise assertion errors if this hasn't worked
# fructose should be in the medium
# Glucose should not be present
assert "EX_fru_e" in fructose_m.medium
assert "EX_glc__D_e" not in fructose_m.medium
assert fructose_m.medium["EX_fru_e"] == 10

GSMProject class

class gsmodutils.project.interface.GSMProject(path='.')[source]

Bases: object

add_essential_pathway(tid, reactions, description='', reaction_fluxes=None, models=None, designs=None, conditions=None, overwrite=False)[source]

Add a pathway to automated testing to confirm reactions are always present in model and the pathway always carries flux.

This is just a simpler way of adding essential pathways than manually adding a json file with the same information.

Parameters:
  • tid
  • reactions
  • description
  • reaction_fluxes
  • models – If None, only the default model is checked unless at least one design is specified
  • designs – By default designs are never checked. specifying all tests the pathway on all designs
  • conditions – None, by default. Specifies the conditions which a pathway is present in.
  • overwrite
Returns:

add_model(model_path, validate=True)[source]

Add a model given a path to it copy it to model directory unless its in the project path already.

conditions

Different model conditions :return: dict of model conditions

conditions_schema = {'properties': {'growth_conditions': {'patternProperties': {'^.*$': {'properties': {'models': {'items': {'type': 'string'}, 'type': 'array'}, 'observe_growth': {'type': 'bool'}, 'carbon_source': {'type': 'string'}, 'media': {'patternProperties': {'^.*$': {'type': 'number'}}, 'type': 'object'}}, 'type': 'object'}}, 'type': 'object'}, 'carbon_sources': {'items': {'type': 'string'}, 'type': 'array'}}, 'type': 'object'}
classmethod create_project(models, description, author, author_email, project_path)[source]

Creates new projects

Parameters:
  • models – iterable of models can be strings to path locations or cobra model instances.
  • description – String description of project
  • author – string author names, separate with &
  • author_email – email of project owner. separate with ‘;’
  • project_path – location on disk to place project. Must not contain existing gsmodutils project.
Returns:

design_path
designs

Return list of all the designs stored for the project

get_conditions(update=False)[source]

Load the saved conditions file

get_design(design)[source]

Get the StrainDesign object (not resulting model) of a design :param design: design identifier :return:

growth_condition(conditions_id)[source]
iter_models()[source]

Generator for models

list_conditions
list_designs

List designs stored in design dir

list_models
load_conditions(conditions_id, model=None, copy=False)[source]

Load a model with a given set of pre-saved media conditions :param conditions_id: identifier of conditions file :param model: string or cobrapy model :param copy: return copy of model or modify inplace :return:

load_design(design, model=None, copy=False)[source]

Returns a model with a specified design modification

Design must either be a design stored in the folder path or a path to a json file The json file should conform to the same standard as a json model

required fields:
“metabolites”:[] “reactions”:[] “description”: “”, “notes”: {}, “genes”: [], “id”:”“
optional fields:
“parent”: str - parent design to be applied first “conditions”: “” “removed_reactions”:[] “removed_metabolites”:[]

Note if conditions is specified it is loaded first other bounds are set afterwards

load_diff(diff, base_model=None)[source]

Take a diff dictionary and add it to a model (does not require saving a design file)

load_model(mpath=None)[source]

Get a model stored by the project mpath refers to the relative path of the model

model

Returns default model for project

models

Lists all the models that can be loaded

project_context_lock

Returns a gloab project lock to stop multiple operations on files. This software is not designed to be used in multiple user environments, so this is slow. However, it provides some degree of protection for the user against modifying the same files

project_path
project_tester()[source]

Creates a tester for this project instance

run_tests()[source]

Returns the log output of all the tests :return:

save_conditions(model, conditions_id, carbon_source=None, apply_to=None, observe_growth=True)[source]

Add media conditions that a given model has to the project. Essentially the lower bounds on transport reactions. All other trnasport reactions will be switched off.

In some cases, one may wish to set conditions under which a model should not grow. observe_growth allows this to be configured. If using a single model or if the condition should not grow under any circumstances, observe_growth can be set to false.

If certain models should grow, specify this with a a tuple where the entries refer to the model files tracked by the project. All models specified must be contained within the project.

Parameters:
  • model – cobrapy model
  • conditions_id – identifier for the conditions should be unique
  • carbon_source – name of carbon source in the media that has a fixed uptake rate
  • apply_to – iterable of models that this set of designs applies to
  • observe_growth – bool or list.
Returns:

save_design(model, did, name, description='', conditions=None, base_model=None, parent=None, overwrite=False)[source]

Creates a design from a diff of model_a and model_b

id should be a string with no spaces (conversion handled)

Returns the saved design diff

Parameters:
  • model – cobrapy model
  • did – design identifier
  • name – name of the design
  • description – text description of what it does
  • conditions – conditions that should be applied for the design
  • base_model – Model that the design should be derived from - specified model included in project
  • parent – string for parent design that this design is a diff from
  • overwrite – overwrite and existing design (only applies if the id is already in use)
tests_dir

Tests directory

update()[source]

Updates this class from configuration file