Maintenance, speed up ensemble generation, populate ensemble with different bounds and BOFs #116
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Merging this PR has the same effect as merging the four suggested features (individual PRs) separately. Hence, this PR makes things easier if you would agree with all proposed changes. Below, I summarize all changes:
Maintenance
A few functions in the current Medusa/development branch are outdated, or now use different conventions. This affects the package performance, e.g., the first tutorial currently doesn't run, and running the pytests is also not possible. Merging this maintenance branch resolves this by:
from cobra.test import create_test_model
withfrom cobra.io import load_model
everywherepython setup.py development
withpython setup.py develop
pd.append
withpd.concat
rownames.contains
within rownames
test_ensemble.py
andflux_balance.py
), a small workaround was introduced. Originally, reactions objects were matched directly between the ensemble.base_model and the textbook model. This sometimes leads to issues (we can discuss), which are circumvented by searching on reaction.id.Refactor populate features base
Merging this PR will update the
ensemble.py
function, more specifically, the_populate_features_base
subroutine. This feature speeds up generating an ensemble from an existing list of GEMs considerably, e.g., for my personal project with a list of 150 GEMs, the runtime reduces from 1min30s to 2s. The speed gain can be largely attributed to pre-caching the model reaction attributes in dictionaries, thus avoiding repeatedgetattr
calls.Fast bounds feature
One aspect hampering the use of Medusa for certain applications is the need to construct a list of GEMs prior to creating and analyzing the ensemble. Indeed, in many situations, it is computationally less expensive to create and analyze each member of the fly. This feature allows for directly populating the ensemble without needing to first generate each individual member, for one specific situation. This feature allows for directly populating an ensemble where members only differ w.r.t. the lower and/or upper bounds for certain reactions. Note that as bounds can be set to zero, reaction reversibility and presence is allowed to be affected. Changes made:
boundsEnsemble.py
: workhorsetest_boundsEnsemble.py
: test validityHappy to discuss if functions like these would be a good fit for Medusa, or if they should be ported elsewhere.
Fast BOF feature
One aspect hampering the use of Medusa for certain applications is the need to construct a list of GEMs prior to creating and analyzing the ensemble. Indeed, in many situations, it is computationally less expensive to create and analyze each member of the fly. This feature allows for directly populating the ensemble without needing to first generate each individual member, for one specific situation. This feature allows for directly populating an ensemble where members only differ w.r.t. their biomass objective function (BOF) definition. Note that as BOF coefficients can be set to zero, metabolites can either be omitted or admitted to the BOF. Changes made:
bofEnsemble.py
: workhorsetest_boundsEnsemble.py
: test validityHappy to discuss if functions like these would be a good fit for Medusa, or if they should be ported elsewhere.