Model diffs

When making changes to a model within gsmodutils the gsmodutils.GSModuitlsModel instances (which is subclass of cobra.Model) allows you to track the differences between the in memory model and the model or design saved on disk. For example:

import gsmodutils
project = gsmodutils.GSMProject()
model = project.load_model()

model.remove_reactions([model.reactions.RXN_01])

diff = model.diff()
diff

Diff is gsmodutils.model_diff.ModelDiff object which is just a subclass of a python dictionary. If working within an jupyter notebook diff will display the model changes in HTML.

If working outside of as gsmodutils project with cobra models use:

from gsmodutils.model_diff import ModelDiff
diff = ModelDiff.model_diff(model_a, model_b)
diff

ModelDiff class

class gsmodutils.model_diff.ModelDiff(model_a=None, model_b=None, *args, **kwargs)[source]

Bases: dict

clear() → None. Remove all items from D.
copy() → a shallow copy of D
fromkeys()

Returns a new dict with keys from iterable and values equal to value.

get(k[, d]) → D[k] if k in D, else d. d defaults to None.
items() → a set-like object providing a view on D's items
keys() → a set-like object providing a view on D's keys
static model_diff(model_a, model_b)[source]

Returns a dictionary that contains all of the changed reactions between model a and model b This includes any reactions or metabolites removed, or any reactions or metabolites added/changed This does not say HOW a model has changed if reactions or metabolites are changed they are just included with their new values

Diff assumes l -> r (i.e. model_a is the base model) :param cobra.Model model_a: :param cobra.Model model_b: :return:

pop(k[, d]) → v, remove specified key and return the corresponding value.

If key is not found, d is returned if given, otherwise KeyError is raised

popitem() → (k, v), remove and return some (key, value) pair as a

2-tuple; but raise KeyError if D is empty.

setdefault(k[, d]) → D.get(k,d), also set D[k]=d if k not in D
update([E, ]**F) → None. Update D from dict/iterable E and F.

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values() → an object providing a view on D's values
gsmodutils.model_diff.model_diff(model_a, model_b)[source]

@depricated - use ModelDiff.model_diff(model_a, model_b) Returns a ModelDiff dictionary that contains all of the changed reactions between model a and model b This includes any reactions or metabolites removed, or any reactions or metabolites added/changed This does not say HOW a model has changed if reactions or metabolites are changed they are just included with their new values Diff assumes l -> r (i.e. model_a is the base model)