Skip to content

Commit

Permalink
Merge 8c899a9 into 974abf7
Browse files Browse the repository at this point in the history
  • Loading branch information
phantomas1234 committed Mar 30, 2015
2 parents 974abf7 + 8c899a9 commit 215bf75
Show file tree
Hide file tree
Showing 55 changed files with 3,669 additions and 4,519 deletions.
7 changes: 2 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
language: python
python:
- "2.7"
# command to install dependencies
virtualenv:
system_site_packages: true
- "3.4"
before_install:
- sudo apt-get install swig redis-server libzmq3-dev libgmp-dev
- sudo service redis-server start
Expand All @@ -19,8 +17,7 @@ before_install:
- sudo ldconfig
- sudo ln -s /run/shm /dev/shm
install:
#glpk for cobra
- pip install glpk
- if [[ $TRAVIS_PYTHON_VERSION == "3.4" ]]; then pip install pyzmq pandas bokeh; fi
- pip install python-libsbml-experimental cython numpy scipy pyzmq pandas bokeh -f https://dl.dropboxusercontent.com/u/22461024/pypi.drosophi.la/index.html --no-index
- pip install coveralls coverage
- pip install redis
Expand Down
7 changes: 4 additions & 3 deletions cameo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,16 @@
mutation_rate=0.3, view=cameo.parallel.SequentialView(),
product="EX_succ_lp_e_rp_", num_elites=1)
"""
from __future__ import absolute_import, print_function

import os

_cameo_path = __path__[0]
_cameo_data_path = os.path.join(_cameo_path, 'data')

from util import get_system_info
from cameo import config

from .util import get_system_info

system_info = get_system_info()

Expand All @@ -67,8 +70,6 @@
except ImportError:
pass

import config

from cameo.core.solver_based_model import SolverBasedModel as Model
from cameo.core.reaction import Reaction
from cobra.core import Metabolite
Expand Down
12 changes: 2 additions & 10 deletions cameo/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,15 @@
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# import logging
# logging.basicConfig(level=logging.INFO)
# logger = logging.getLogger(__name__)
#
# logger.info('Initializing cameo advanced programming interface. Be patient this might take a while ...')

import os
import cPickle as pickle
import cameo
from __future__ import absolute_import

import logging
logger = logging.getLogger(__name__)
Expand Down
14 changes: 8 additions & 6 deletions cameo/api/designer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from types import StringType
from __future__ import absolute_import, print_function

from functools import partial
import progressbar
from cameo import Metabolite, Model
Expand All @@ -21,6 +22,7 @@
from cameo.api.products import products
from cameo.strain_design.pathway_prediction import PathwayPredictor
from cameo.util import TimeMachine, DisplayItemsWidget
import six


class Designs(object):
Expand Down Expand Up @@ -99,7 +101,7 @@ def predict_pathways(self, product, hosts=hosts): #TODO: make this work with a

def calculate_maximum_yields(self, pathways):
""""""
for (host, model), pathway in pathways.iteritems():
for (host, model), pathway in six.iteritems(pathways):
tm = TimeMachine()
tm(do=partial(model.add_reactions, pathway), undo=partial(model.remove_reactions, pathway))
maximum_theoretical_yield()
Expand All @@ -108,11 +110,11 @@ def calculate_maximum_yields(self, pathways):
def __translate_product_to_universal_reactions_model_metabolite(self, product):
if isinstance(product, Metabolite):
return product
elif isinstance(product, StringType):
elif isinstance(product, str):
search_result = products.search(product)
print "Found %d compounds that match query '%s'" % (len(search_result), product)
print repr(search_result)
print "Choosing best match (%s) ... please interrupt if this is not the desired compound." % search_result.name[0]
print("Found %d compounds that match query '%s'" % (len(search_result), product))
print(repr(search_result))
print("Choosing best match (%s) ... please interrupt if this is not the desired compound." % search_result.name[0])
return METANETX['universal_model'].metabolites.get_by_id(search_result.index[0])

design = Designer()
Expand Down
6 changes: 4 additions & 2 deletions cameo/api/hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import, print_function

import os
import optlang
import cameo
from cameo.util import IntelliContainer
from cameo import load_model
import six

MODEL_DIRECTORY = os.path.join(os.path.join(os.path.split(cameo.__path__[0])[0]), 'tests/data')

Expand Down Expand Up @@ -58,7 +60,7 @@ class Hosts(object):
def __init__(self, host_spec):
self._host_spec = host_spec
self._hosts = list()
for host_id, information in self._host_spec.iteritems():
for host_id, information in six.iteritems(self._host_spec):
host = Host(**information)
self._hosts.append(host)
setattr(self, host_id, host)
Expand All @@ -67,7 +69,7 @@ def __iter__(self):
return iter(self._hosts)

def __dir__(self):
return self._host_spec.keys()
return list(self._host_spec.keys())


HOST_SPECS = {'ecoli': {'name': 'Escherichia coli', 'models': ('iJO1366',)}, # 'iAF1260', 'iJO1366', 'EcoliCore'
Expand Down
6 changes: 4 additions & 2 deletions cameo/api/products.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import, print_function

import difflib
from cameo.data import metanetx


def inchi_to_svg(inchi, file=None):
try:
import openbabel
except ImportError, e:
print e
except ImportError as e:
print(e)
raise ImportError("OpenBabel seems to be not installed.")
convert = openbabel.OBConversion()
convert.SetInFormat("inchi")
Expand Down
2 changes: 2 additions & 0 deletions cameo/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import, print_function

non_zero_flux_threshold = 1e-6
ndecimals = 6

Expand Down
18 changes: 12 additions & 6 deletions cameo/core/reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import, print_function

from functools import partial
import hashlib
import cobra as _cobrapy
Expand All @@ -23,7 +25,9 @@
from cameo.parallel import SequentialView

import logging
import six
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)


class Reaction(_cobrapy.core.Reaction):
Expand All @@ -49,11 +53,13 @@ def clone(cls, reaction, model=None):
"""
new_reaction = cls(name=reaction.name)
for attribute, value in reaction.__dict__.iteritems():
for attribute, value in six.iteritems(reaction.__dict__):
if attribute == '_model': # _model needs to be set after all other attributes have been set.
continue
try:
setattr(new_reaction, attribute, value)
except AttributeError:
logger.debug("Can't set attribute %s for reaction %s (while cloning it to a cameo style reaction). Skipping it ..." % (attribute, reaction))
logger.info("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
if model is not None:
Expand Down Expand Up @@ -97,7 +103,7 @@ def reversibility(self):

def _get_reverse_id(self):
"""Generate the id of revers_variable from the reaction's id."""
return '_'.join((self.id, 'reverse', hashlib.md5(self.id).hexdigest()[0:5]))
return '_'.join((self.id, 'reverse', hashlib.md5(self.id.encode('utf-8')).hexdigest()[0:5]))

@property
def reverse_variable(self):
Expand Down Expand Up @@ -128,7 +134,7 @@ def lower_bound(self, value):
elif value < 0 and self._lower_bound >= 0 and self.reverse_variable is None: # self._lower_bound >= 0 implies self._upper_bound >= 0
reverse_variable = model.solver._add_variable(
model.solver.interface.Variable(self._get_reverse_id(), lb=0, ub=0))
for met, coeff in self._metabolites.iteritems():
for met, coeff in six.iteritems(self._metabolites):
model.solver.constraints[met.id] += sympy.Mul._from_args((-1 * sympy.RealNumber(coeff), reverse_variable))

variable = self.variable
Expand Down Expand Up @@ -178,7 +184,7 @@ def upper_bound(self, value):
if self.reverse_variable is None:
reverse_variable = model.solver._add_variable(
model.solver.interface.Variable(self._get_reverse_id(), lb=0, ub=0))
for met, coeff in self._metabolites.iteritems():
for met, coeff in six.iteritems(self._metabolites):
model.solver.constraints[met.id] += sympy.Mul._from_args((-1 * sympy.RealNumber(coeff), reverse_variable))
else:
reverse_variable = self.reverse_variable
Expand Down Expand Up @@ -249,7 +255,7 @@ def add_metabolites(self, metabolites, **kwargs):
super(Reaction, self).add_metabolites(metabolites, **kwargs)
model = self.model
if model is not None:
for metabolite, coefficient in metabolites.iteritems():
for metabolite, coefficient in six.iteritems(metabolites):
model.solver.constraints[metabolite.id] += coefficient*self.variable

def knock_out(self, time_machine=None):
Expand Down
14 changes: 8 additions & 6 deletions cameo/core/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import, print_function

import time
from datetime import datetime
from cameo import system_info
Expand Down Expand Up @@ -71,7 +73,7 @@ def __init__(self, solution, *args, **kwargs):

@property
def data_frame(self):
return pandas.DataFrame(self._fluxes.values(), index=self._fluxes.keys(), columns=['flux'])
return pandas.DataFrame(list(self._fluxes.values()), index=list(self._fluxes.keys()), columns=['flux'])

@property
def fluxes(self):
Expand All @@ -90,8 +92,8 @@ def objective_value(self):
from cameo.util import Timer
with Timer():
result = FluxDistributionResult(solution)
print result.meta_information.system_info
print result.meta_information.responsible
print result.meta_information.timestamp
print result.meta_information.human_readable_timestamp
print result.data_frame
print(result.meta_information.system_info)
print(result.meta_information.responsible)
print(result.meta_information.timestamp)
print(result.meta_information.human_readable_timestamp)
print(result.data_frame)
15 changes: 9 additions & 6 deletions cameo/core/solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import, print_function

from collections import OrderedDict

import time
Expand All @@ -22,6 +24,7 @@
from cameo.exceptions import UndefinedSolution

import logging
from six.moves import zip
logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -99,11 +102,11 @@ def __init__(self, model, *args, **kwargs):

@property
def x_dict(self):
return OrderedDict(zip(self._reaction_ids, self.x))
return OrderedDict(list(zip(self._reaction_ids, self.x)))

@property
def y_dict(self):
return OrderedDict(zip(self._reaction_ids, self.y))
return OrderedDict(list(zip(self._reaction_ids, self.y)))

@property
def fluxes(self):
Expand All @@ -115,7 +118,7 @@ def reduced_costs(self):

def __dir__(self):
# Hide 'cobrapy' attributes and methods from user.
fields = sorted(dir(type(self)) + self.__dict__.keys())
fields = sorted(dir(type(self)) + list(self.__dict__.keys()))
fields.remove('x')
fields.remove('y')
fields.remove('x_dict')
Expand Down Expand Up @@ -184,7 +187,7 @@ def f(self, value):
@property
def x(self):
self._check_freshness()
return self.x_dict.values()
return list(self.x_dict.values())

@property
def x_dict(self):
Expand All @@ -199,7 +202,7 @@ def x_dict(self):
@property
def y(self):
self._check_freshness()
return self.y_dict.values()
return list(self.y_dict.values())

@property
def y_dict(self):
Expand Down Expand Up @@ -227,7 +230,7 @@ def reduced_costs(self):

def __dir__(self):
# Hide 'cobrapy' attributes and methods from user.
fields = sorted(dir(type(self)) + self.__dict__.keys())
fields = sorted(dir(type(self)) + list(self.__dict__.keys()))
fields.remove('x')
fields.remove('y')
fields.remove('x_dict')
Expand Down
Loading

0 comments on commit 215bf75

Please sign in to comment.