Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #52

Merged
merged 6 commits into from
May 19, 2021
Merged

Dev #52

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 134 additions & 0 deletions CLAI
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
EPFL / LCSB / Lausanne / CH
Individual Contributor License Agreement ("Agreement") V2.0
http://www.apache.org/licenses/

Thank you for your interest in software from EPFL/LCSB (Lab).
In order to clarify the intellectual property license
granted with Contributions from any person or entity, the Lab
must have a Contributor License Agreement ("CLA") on file that has
been signed by each Contributor, indicating agreement to the license
terms below. This license is for your protection as a Contributor as
well as the protection of the Lab and its users; it does not
change your rights to use your own Contributions for any other purpose.
If you have not already done so, please complete and sign, then scan
and email a pdf file of this Agreement to softwares.lcsb@epfl.ch.

Please read this document carefully before
signing and keep a copy for your records.

Full name: ______________________________________________________

(optional) Public name: _________________________________________

Mailing Address: ________________________________________________

________________________________________________

Country: ______________________________________________________

Telephone: ______________________________________________________

E-Mail: ______________________________________________________

Github account: _________________________________________________

You accept and agree to the following terms and conditions for Your
present and future Contributions submitted to the Lab. In
return, the Lab shall not use Your Contributions in a way that
is contrary to the public benefit or inconsistent with its nonprofit
status and bylaws in effect at the time of the Contribution. Except
for the license granted herein to the Lab and recipients of
software distributed by the Lab, You reserve all right, title,
and interest in and to Your Contributions.

1. Definitions.

"You" (or "Your") shall mean the copyright owner or legal entity
authorized by the copyright owner that is making this Agreement
with the Lab. For legal entities, the entity making a
Contribution and all other entities that control, are controlled
by, or are under common control with that entity are considered to
be a single Contributor. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.

"Contribution" shall mean any original work of authorship,
including any modifications or additions to an existing work, that
is intentionally submitted by You to the Lab for inclusion
in, or documentation of, any of the products owned or managed by
the Lab (the "Work"). For the purposes of this definition,
"submitted" means any form of electronic, verbal, or written
communication sent to the Lab or its representatives,
including but not limited to communication on electronic mailing
lists, source code control systems, and issue tracking systems that
are managed by, or on behalf of, the Lab for the purpose of
discussing and improving the Work, but excluding communication that
is conspicuously marked or otherwise designated in writing by You
as "Not a Contribution."

2. Grant of Copyright License. Subject to the terms and conditions of
this Agreement, You hereby grant to the Lab and to
recipients of software distributed by the Lab a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare derivative works of,
publicly display, publicly perform, sublicense, and distribute Your
Contributions and such derivative works.

3. Grant of Patent License. Subject to the terms and conditions of
this Agreement, You hereby grant to the Lab and to
recipients of software distributed by the Lab a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have
made, use, offer to sell, sell, import, and otherwise transfer the
Work, where such license applies only to those patent claims
licensable by You that are necessarily infringed by Your
Contribution(s) alone or by combination of Your Contribution(s)
with the Work to which such Contribution(s) was submitted. If any
entity institutes patent litigation against You or any other entity
(including a cross-claim or counterclaim in a lawsuit) alleging
that your Contribution, or the Work to which you have contributed,
constitutes direct or contributory patent infringement, then any
patent licenses granted to that entity under this Agreement for
that Contribution or Work shall terminate as of the date such
litigation is filed.

4. You represent that you are legally entitled to grant the above
license. If your employer(s) has rights to intellectual property
that you create that includes your Contributions, you represent
that you have received permission to make Contributions on behalf
of that employer, that your employer has waived such rights for
your Contributions to the Lab, or that your employer has
executed a separate Corporate CLA with the Lab.

5. You represent that each of Your Contributions is Your original
creation (see section 7 for submissions on behalf of others). You
represent that Your Contribution submissions include complete
details of any third-party license or other restriction (including,
but not limited to, related patents and trademarks) of which you
are personally aware and which are associated with any part of Your
Contributions.

6. You are not expected to provide support for Your Contributions,
except to the extent You desire to provide support. You may provide
support for free, for a fee, or not at all. Unless required by
applicable law or agreed to in writing, You provide Your
Contributions on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
OF ANY KIND, either express or implied, including, without
limitation, any warranties or conditions of TITLE, NON-
INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE.

7. Should You wish to submit work that is not Your original creation,
You may submit it to the Lab separately from any
Contribution, identifying the complete details of its source and of
any license or other restriction (including, but not limited to,
related patents, trademarks, and license agreements) of which you
are personally aware, and conspicuously marking the work as
"Submitted on behalf of a third-party: [named here]".

8. You agree to notify the Lab of any facts or circumstances of
which you become aware that would make these representations
inaccurate in any respect.

Please sign: __________________________________ Date: ________________
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ Here is an example script :
:target: http://pytfa.readthedocs.io/en/latest/?badge=latest
.. |license| image:: http://img.shields.io/badge/license-APACHE2-blue.svg
:target: https://github.com/EPFL-LCSB/pytfa/blob/master/LICENSE.txt
.. |Build Status| image:: https://travis-ci.org/EPFL-LCSB/pytfa.svg?branch=master
:target: https://travis-ci.org/EPFL-LCSB/pytfa
.. |Build Status| image:: https://travis-ci.com/EPFL-LCSB/pytfa.svg?branch=master
:target: https://travis-ci.com/EPFL-LCSB/pytfa
.. |Codecov| image:: https://img.shields.io/codecov/c/github/EPFL-LCSB/pytfa.svg
:target: https://codecov.io/gh/EPFL-LCSB/pytfa
.. |Codacy branch grade| image:: https://img.shields.io/codacy/grade/d8fd67ee134d46a69115c9b39c19be26/master.svg
Expand Down
2 changes: 1 addition & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def __getattr__(cls, name):
version = '0.9'
# The full version, including alpha/beta/rc tags.

release = '0.9.1'
release = '0.9.2'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
2 changes: 2 additions & 0 deletions docker/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
bokeh>=0.12.1
cobra>0.13
equilibrator-api
equilibrator-cache
ipdb
lxml
networkx
Expand Down
12 changes: 6 additions & 6 deletions models/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ Publications

Some models have been published:

+-----------------+-------------------------------------------------------------------------+
| small_ecoli.mat | Ataman, M., Gardiol, D. F. H., Fengos, G., & Hatzimanikatis, V. (2017). |
| | redGEM: Systematic reduction and analysis of genome-scale metabolic |
| | reconstructions for development of consistent core metabolic models. |
| | PLoS computational biology, 13(7), e1005444. |
+-----------------+-------------------------------------------------------------------------+
+-----------------+--------------------------------------------------------------------------------+
| small_ecoli.mat | Ataman, M., Hernandez Gardiol, D. F., Fengos, G., & Hatzimanikatis, V. (2017). |
| | redGEM: Systematic reduction and analysis of genome-scale metabolic |
| | reconstructions for development of consistent core metabolic models. |
| | PLoS computational biology, 13(7), e1005444. |
+-----------------+--------------------------------------------------------------------------------+



3 changes: 1 addition & 2 deletions pytfa/io/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,7 @@ def import_matlab_model(path, variable_name=None):
comp = comps[i]
comp['membranePot'] = {}
for j in range(num_comp):
comp['membranePot'][comps[j]['symbol']] = \
CompartmentDB['membranePot'][0][i, j]
comp['membranePot'][comps[j]['symbol']] = float(CompartmentDB['membranePot'][0][i, j])

cobra_model.compartments = Compartments

Expand Down
7 changes: 6 additions & 1 deletion pytfa/io/dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
from ..optim.constraints import ReactionConstraint, MetaboliteConstraint, ModelConstraint
from ..optim.utils import symbol_sum

from ..thermo.metabolite import MetaboliteThermo

from optlang.util import expr_to_json, parse_expr

from copy import copy
Expand Down Expand Up @@ -215,7 +217,7 @@ def model_to_dict(model):

if is_thermo and not is_peptide: # peptides have no thermo
the_met = model.metabolites.get_by_id(the_met_id)
_add_thermo_metabolite_info(the_met, rxn_dict)
_add_thermo_metabolite_info(the_met, met_dict)
met_dict['kind'] = 'Metabolite'

# Relaxation info
Expand Down Expand Up @@ -425,6 +427,9 @@ def init_thermo_model_from_dict(new, obj):

if 'thermo' in met_dict:
new._prepare_metabolite(met)
met.thermo = MetaboliteThermo(metData=None, pH=7,ionicStr=0)
for k,v in met_dict['thermo'].items():
setattr(met.thermo,k,v)
return new

def rebuild_compositions(new, compositions_dict):
Expand Down
24 changes: 24 additions & 0 deletions pytfa/io/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,27 @@ def load_json_model(filepath):

model = model_from_dict(obj)
return model


def json_dumps_model(model):
"""
Returns a JSON dump as a string

:param model:
:return:
"""

obj = model_to_dict(model)

return json.dumps(obj,cls=MyEncoder)


def json_loads_model(s):
"""
Loads a model from a string JSON dump

:param s: JSON string
:return:
"""
obj = json.loads(s)
return model_from_dict(obj)
4 changes: 3 additions & 1 deletion pytfa/optim/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import sympy
from cobra.core.solution import Solution

from sympy.core.numbers import Zero

from numbers import Number

from .constraints import GenericConstraint
Expand Down Expand Up @@ -107,7 +109,7 @@ def symbol_sum(variables):

k=0
# If we encounter a zero, which is a special type, increase k
while isinstance(variables[k], sympy.numbers.Zero) and k<len(variables):
while isinstance(variables[k], Zero) and k<len(variables):
k+=1
if k == len(variables):
# everything is 0
Expand Down
1 change: 0 additions & 1 deletion pytfa/optim/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,6 @@ class NegSlackLC(MetaboliteVariable):

prefix = 'NegSlackLC_'


class LinearizationVariable(ModelVariable):
"""
Class to represent a product A*B when performing linearization of the
Expand Down
24 changes: 19 additions & 5 deletions pytfa/redgem/lumpgem.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
GUROBI = 'optlang-gurobi'
GLPK = 'optlang-glpk'

DEFAULT_EPS = 1e-5

# Transforms (OnePerBBB --> oneperbbb), (one_per_bbb --> oneperbbb), etc ...
disambiguate = lambda s:s.lower().replace('_','')
Expand Down Expand Up @@ -292,7 +293,11 @@ def compute_lumps(self, force_solve=False, method='OnePerBBB'):
self._tfa_model.convert()
# self._tfa_model.objective_direction = 'min'

epsilon = self._tfa_model.solver.configuration.tolerances.feasibility
try:
epsilon = self._tfa_model.solver.configuration.tolerances.feasibility
except AttributeError as e:
self._tfa_model.logger.error('{} does not support tolerance settings.'.format(self._tfa_model.solver))
epsilon = DEFAULT_EPS

the_method = disambiguate(method)
print('Lumping method detected: {}'.format(the_method))
Expand Down Expand Up @@ -391,7 +396,11 @@ def _lump_min_plus_p(self, met_BBB, sink, p, force_solve):
:return:
"""

epsilon = self._tfa_model.solver.configuration.tolerances.integrality
try:
epsilon = self._tfa_model.solver.configuration.tolerances.integrality
except AttributeError as e:
self._tfa_model.logger.error('{} does not support tolerance settings.'.format(self._tfa_model.solver))
epsilon = DEFAULT_EPS

try:
max_lumps =self._param_dict['max_lumps_per_BBB']
Expand Down Expand Up @@ -475,8 +484,13 @@ def _build_lump(self, met_BBB, sink):
:return:
"""

epsilon_int = self._tfa_model.solver.configuration.tolerances.integrality
epsilon_flux = self._tfa_model.solver.configuration.tolerances.feasibility
try:
epsilon_int = self._tfa_model.solver.configuration.tolerances.integrality
epsilon_flux = self._tfa_model.solver.configuration.tolerances.feasibility
except AttributeError:
self._tfa_model.logger.error('{} does not support tolerance settings.'.format(self._tfa_model.solver))
epsilon_int = DEFAULT_EPS
epsilon_flux = DEFAULT_EPS

sigma = sink.flux
lump_dict = dict()
Expand Down Expand Up @@ -521,4 +535,4 @@ def sum_reactions(rxn_dict, id_ = 'summed_reaction', epsilon = 1e-9):
subnetwork = {x.id:v for x,v in rxn_dict.items()},
gene_reaction_rule=gpr)

return new
return new
14 changes: 10 additions & 4 deletions pytfa/redgem/redgem.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,16 @@ def run(self):

force_solve = self.params["force_solve"]
timeout = self.params["timeout"]
self._gem.solver.configuration.tolerances.feasibility = self.params["feasibility"]
self._gem.solver.configuration.tolerances.integrality = self.params["feasibility"]
self._source_gem.solver.configuration.tolerances.feasibility = self.params["feasibility"]
self._source_gem.solver.configuration.tolerances.integrality = self.params["feasibility"]
try:
self._gem.solver.configuration.tolerances.feasibility = self.params["feasibility"]
self._gem.solver.configuration.tolerances.integrality = self.params["feasibility"]
except AttributeError as e:
self.logger.error('Solver {} is not compatible with tolerance parameters'.format(self._gem.solver))
try:
self._source_gem.solver.configuration.tolerances.feasibility = self.params["feasibility"]
self._source_gem.solver.configuration.tolerances.integrality = self.params["feasibility"]
except AttributeError as e:
self.logger.error('Solver {} is not compatible with tolerance parameters'.format(self._source_gem.solver))

self.logger.info("Computing network expansion...")
expander = NetworkExpansion(self._gem, core_subsystems, extracellular_system,
Expand Down
3 changes: 2 additions & 1 deletion pytfa/thermo/equilibrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def build_thermo_from_equilibrator(model, T=TEMPERATURE_0):
ccache = create_compound_cache_from_quilt()
logger.debug("eQuilibrator compound cache is loaded.")

cc = ComponentContribution(temperature=Q_(str(T) + "K"))
cc = ComponentContribution()
cc.temperature=Q_(str(T) + "K")

thermo_data = {"name": "eQuilibrator", "units": "kJ/mol", "cues": {}}
met_to_comps = compat.map_cobra_metabolites(ccache, model.metabolites)
Expand Down
2 changes: 1 addition & 1 deletion pytfa/thermo/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def check_reaction_balance(reaction, proton = None):
'Cd', 'W', 'Hg', 'R', 'Mo', 'X'].index(atom[0])
except ValueError:
# Jorge Carrasco: Can we use warnings here?
reaction.model.logger.warn(
reaction.model.logger.warning(
'Warning : ' + metabolite.formula + '/' + atom[0]
)
continue
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# return reqs


version_tag = '0.9.1'
version_tag = '0.9.3'

setup(name='pytfa',
version=version_tag,
Expand Down
Loading