Skip to content

Commit

Permalink
Merge branch 'devel' into devel-nonfree
Browse files Browse the repository at this point in the history
  • Loading branch information
hredestig committed Mar 20, 2017
2 parents d17c8a0 + db85347 commit 1c39b6e
Show file tree
Hide file tree
Showing 42 changed files with 3,267 additions and 3,175 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,5 @@ docs/_build
.vagrant
*~
/.DS_Store
.cache
/coverage.xml
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
language: python
sudo: false
sudo: required
dist: trusty

python:
- '2.7'
Expand Down Expand Up @@ -37,11 +38,11 @@ before_install:
- 'echo "this is a build for: $TRAVIS_BRANCH"'
- 'if [[ "$TRAVIS_BRANCH" != "devel" && ($TRAVIS_PYTHON_VERSION == "3.4" || $TRAVIS_PYTHON_VERSION == "2.7") ]]; then bash ./.travis/install_cplex.sh; fi'
install:
- pip install flake8 numpy scipy pyzmq pandas
- pip install flake8 numpy scipy pyzmq pandas pytest pytest-cov
- pip install .[swiglpk,test,parallel,cli]
before_script:
- if [[ $TRAVIS_PYTHON_VERSION == "3.6" ]]; then flake8 .; fi
script: nosetests
script: pytest -v -rsx --cov --cov-report=xml
after_success:
- codecov
notifications:
Expand Down
272 changes: 200 additions & 72 deletions cameo/api/designer.py

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions cameo/cli/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ class Meta:
(['-m', '--multiprocess'], dict(help='Run multiprocess mode', action='store_true')),
(['-c', '--cores'], dict(help="Number of cores (if multiprocess)")),
(['-o', '--output'], dict(help="Output file")),
(['-of', '--output-format'], dict(help="Output file format (default xlsx)\nOptions:%s" % VALID_OUTPUT_FORMATS)),
(['-y', '--yes-all'], dict(help="Auto select suggested options", action="store_true"))]
(['-of', '--output-format'], dict(help="Output file format (default xlsx)\nOptions:%s" %
VALID_OUTPUT_FORMATS)),
(['-y', '--yes-all'], dict(help="Auto select suggested options", action="store_true")),
(['-t', '--test'], dict(help="Test mode", action="store_true"))]

@expose(hide=True)
def default(self):
Expand Down Expand Up @@ -105,9 +107,14 @@ def default(self):
else:
view = SequentialView()

design.debug = self.app.pargs.test

results = design(product=product, hosts=_hosts,
view=view, aerobic=not self.app.pargs.anaerobic)

results['heterologous_pathway'] = results.heterologous_pathway.apply(str)
results['manipulations'] = results.manipulations.apply(str)

OUTPUT_WRITER[output_format](results, output)

@expose(help="Search for products in our internal database")
Expand Down
4 changes: 2 additions & 2 deletions cameo/core/metabolite.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

@six.add_metaclass(inheritdocstring)
class Metabolite(cobra.core.Metabolite):

# TODO: figure out how to handle the _reaction attribute
@classmethod
def clone(cls, metabolite, model=None):
Expand All @@ -35,7 +34,8 @@ def clone(cls, metabolite, model=None):
setattr(new_metabolite, attribute, value)
except AttributeError:
logger.info(
"Can't set attribute %s for metabolite %s (while cloning it to a cameo style metabolite). Skipping it ..." %
"Can't set attribute %s for metabolite %s (while cloning it to a "
"cameo style metabolite). Skipping it ..." %
(attribute, metabolite)
)
if model is not None:
Expand Down
6 changes: 4 additions & 2 deletions cameo/core/reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def clone(cls, reaction, model=None):
setattr(new_reaction, attribute, value)
except AttributeError:
logger.info(
"Can't set attribute %s for reaction %s (while cloning it to a cameo style reaction). Skipping it ..." % (
"Can't set attribute %s for reaction %s (while cloning it to a "
"cameo style reaction). Skipping it ..." % (
attribute, reaction))
if not isinstance(reaction.model, cameo.core.solver_based_model.SolverBasedModel):
new_reaction._model = None
Expand Down Expand Up @@ -333,7 +334,8 @@ def model(self, value):

@property
def objective_coefficient(self):
if self.model is not None and isinstance(self.model, cameo.core.SolverBasedModel) and self.model.objective is not None:
if self.model is not None and isinstance(self.model,
cameo.core.SolverBasedModel) and self.model.objective is not None:
coefficients_dict = self.model.objective.expression.as_coefficients_dict()
forw_coef = coefficients_dict.get(self.forward_variable, 0)
rev_coef = coefficients_dict.get(self.reverse_variable, 0)
Expand Down
12 changes: 8 additions & 4 deletions cameo/core/solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,11 @@ def __init__(self, model, *args, **kwargs):
self._reduced_values = model.solver.reduced_costs

for reaction in model.reactions:
self.fluxes[reaction.id] = self._primal_values[reaction._get_forward_id()] - self._primal_values[reaction._get_reverse_id()]
self.fluxes[reaction.id] = self._primal_values[reaction._get_forward_id()] - self._primal_values[
reaction._get_reverse_id()]

self.reduced_costs[reaction.id] = self._reduced_values[reaction._get_forward_id()] - self._reduced_values[reaction._get_reverse_id()]
self.reduced_costs[reaction.id] = self._reduced_values[reaction._get_forward_id()] - self._reduced_values[
reaction._get_reverse_id()]

self.status = model.solver.status
self._reaction_ids = [r.id for r in self.model.reactions]
Expand Down Expand Up @@ -228,7 +230,8 @@ def timestamp_formatter(timestamp):
"%Y-%m-%d %H:%M:%S:%f")

raise UndefinedSolution(
'The solution (captured around %s) has become invalid as the model has been re-optimized recently (%s).' % (
'The solution (captured around %s) has become invalid as the model has been '
're-optimized recently (%s).' % (
timestamp_formatter(self._time_stamp),
timestamp_formatter(self.model._timestamp_last_optimization))
)
Expand Down Expand Up @@ -268,7 +271,8 @@ def reduced_costs(self):

reduced_costs = OrderedDict()
for reaction in self.model.reactions:
reduced_costs[reaction.id] = reduced_values[reaction._get_forward_id()] - reduced_values[reaction._get_reverse_id()]
reduced_costs[reaction.id] = reduced_values[reaction._get_forward_id()] - reduced_values[
reaction._get_reverse_id()]
return reduced_costs

@property
Expand Down
3 changes: 2 additions & 1 deletion cameo/core/solver_based_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,8 @@ def add_reactions(self, reaction_list):
else:
cloned_reaction_list.append(reaction)

# cobrapy will raise an exceptions if one of the reactions already exists in the model (before adding any reactions)
# cobrapy will raise an exceptions if one of the reactions already exists in the model (before adding any
# reactions)
super(SolverBasedModel, self).add_reactions(cloned_reaction_list)
for reac in cloned_reaction_list:
reac.model = self
Expand Down
32 changes: 20 additions & 12 deletions cameo/core/strain_design.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ def __init__(self, targets):
self.targets = DictList(targets)

def __str__(self):
return "".join(str(t) for t in self.targets)
return ", ".join(str(t) for t in self.targets)

def __repr__(self):
return str(self)
return "<StrainDesign [" + ";".join(repr(t) for t in self.targets) + "]>"

def __iter__(self):
return iter(self.targets)
Expand Down Expand Up @@ -92,35 +92,43 @@ def apply(self, model, time_machine=None):
target.apply(model, time_machine)

def __add__(self, other):
if not isinstance(other, StrainDesign):
raise AssertionError("Only instances of StrainDesign can be added together")

targets = {}
for target in self.targets:
if target.id not in targets:
targets[target.id] = []
targets[target.id].append(target)
targets[target.id] = set()
targets[target.id].add(target)

for target in other.targets:
if target.id not in targets:
targets[target.id] = []
targets[target.id].append(target)
targets[target.id] = set()
targets[target.id].add(target)

targets = [t[0] if len(t) == 1 else EnsembleTarget(id, t) for id, t in six.iteritems(targets)]
targets = [next(iter(t)) if len(t) == 1 else EnsembleTarget(id, t) for id, t in six.iteritems(targets)]

return StrainDesign(targets)

def __iadd__(self, other):
if not isinstance(other, StrainDesign):
raise AssertionError("Only instances of StrainDesign can be added together")

targets = {}
for target in self.targets:
if target.id not in targets:
targets[target.id] = []
targets[target.id].append(target)
targets[target.id] = set()
targets[target.id].add(target)

for target in other.targets:
if target.id not in targets:
targets[target.id] = []
targets[target.id].append(target)
targets[target.id] = set()
targets[target.id].add(target)

targets = [next(iter(t)) if len(t) == 1 else EnsembleTarget(id, t) for id, t in six.iteritems(targets)]

targets = [t[0] if len(t) == 1 else EnsembleTarget(id, t) for id, t in six.iteritems(targets)]
self.targets = DictList(targets)

return self

def _repr_html_(self):
Expand Down
Loading

0 comments on commit 1c39b6e

Please sign in to comment.