-
Notifications
You must be signed in to change notification settings - Fork 28
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
Sampling on the flux space of multiple metabolic networks #18
Changes from 59 commits
cb6005e
3fc3d12
ffd7eaf
e251c0a
3c80cc6
f82fcce
cad5e53
a30828a
a16cebf
04944a7
47623cb
d370bb3
223e4a8
1056bff
bc592b3
ac1dba7
667099c
2942009
b40df75
668a5fb
ac25f50
a3f5e31
ad30113
c59de31
006d34d
bffe305
2111699
e7bb703
03eb29b
7858ca1
53d6636
c383567
cccd9e0
892c9ed
ae181b7
fe54929
5d4e46e
11897e0
937becb
1b1db5e
0dacb91
5905950
d2087ce
e2dc87f
dfe2e75
bff70ea
f0455db
0978a59
17d6d0b
9371331
62bc662
3dea11a
f825b4c
ec73f68
28484da
2359c86
dd39486
96f7851
95caaa7
2ee3a25
3518d78
2a7db96
6128d20
cb31f4d
747bb13
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,4 @@ dingo.egg-info | |
volestipy.cpp | ||
volestipy.egg-info | ||
*.npy | ||
|
||
.ipynb_checkpoints/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,8 @@ | |
# Licensed under GNU LGPL.3, see LICENCE file | ||
|
||
import numpy as np | ||
import sys | ||
from dingo.loading_models import read_json_file, read_mat_file | ||
import sys, os | ||
from dingo.loading_models import read_json_file, read_mat_file, getModelList | ||
from dingo.fva import slow_fva | ||
from dingo.fba import slow_fba | ||
|
||
|
@@ -22,8 +22,8 @@ class MetabolicNetwork: | |
def __init__(self, tuple_args): | ||
|
||
self._parameters = {} | ||
self._parameters["opt_percentage"] = 100 | ||
self._parameters["distribution"] = "uniform" | ||
self._parameters["opt_percentage"] = 100 | ||
self._parameters["distribution"] = "uniform" | ||
self._parameters["nullspace_method"] = "sparseQR" | ||
|
||
try: | ||
|
@@ -38,20 +38,20 @@ def __init__(self, tuple_args): | |
"An unknown input format given to initialize a metabolic network object." | ||
) | ||
|
||
self._lb = tuple_args[0] | ||
self._ub = tuple_args[1] | ||
self._S = tuple_args[2] | ||
self._metabolites = tuple_args[3] | ||
self._reactions = tuple_args[4] | ||
self._biomass_index = tuple_args[5] | ||
self._lb = tuple_args[0] | ||
self._ub = tuple_args[1] | ||
self._S = tuple_args[2] | ||
self._metabolites = tuple_args[3] | ||
self._reactions = tuple_args[4] | ||
self._biomass_index = tuple_args[5] | ||
self._biomass_function = tuple_args[6] | ||
|
||
try: | ||
if ( | ||
self._lb.size != self._ub.size | ||
or self._lb.size != self._S.shape[1] | ||
or len(self._metabolites) != self._S.shape[0] | ||
or len(self._reactions) != self._S.shape[1] | ||
self._lb.size != self._ub.size | ||
or self._lb.size != self._S.shape[1] | ||
or len(self._metabolites) != self._S.shape[0] | ||
or len(self._reactions) != self._S.shape[1] | ||
or self._biomass_function.size != self._S.shape[1] | ||
or (self._biomass_index < 0) | ||
or (self._biomass_index > self._biomass_function.size) | ||
|
@@ -223,3 +223,205 @@ def shut_down_reaction(self, index_val): | |
|
||
self._lb[index_val] = 0 | ||
self._ub[index_val] = 0 | ||
|
||
|
||
class CommunityMetabolicNetwork(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use a single .py document per class There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done as suggested. |
||
|
||
# This implementation works only for communities of 2 models | ||
# Once our method is validated, we will move on to implement it for more | ||
|
||
def __init__(self, comm_tuple_args): | ||
|
||
self._comm_parameters = {} | ||
self._comm_parameters["opt_percentage"] = 100 | ||
self._comm_parameters["distribution"] = "uniform" | ||
self._comm_parameters["nullspace_method"] = "sparseQR" | ||
|
||
try: | ||
import gurobipy | ||
|
||
self._comm_parameters["fast_computations"] = True | ||
except ImportError as e: | ||
self._comm_parameters["fast_computations"] = False | ||
|
||
if len(comm_tuple_args) != 8: | ||
raise Exception( | ||
"An unknown input format given to initialize a metabolic network object." | ||
) | ||
|
||
self._comm_lb = comm_tuple_args[0] | ||
self._comm_ub = comm_tuple_args[1] | ||
self._comm_S = comm_tuple_args[2] | ||
self._comm_metabolites = comm_tuple_args[3] | ||
self._comm_reactions = comm_tuple_args[4] | ||
self._comm_biomass_index = comm_tuple_args[5] | ||
self._comm_biomass_function = comm_tuple_args[6] | ||
self._modelList = comm_tuple_args[7] | ||
|
||
try: | ||
if ( | ||
self._comm_lb.size != self._comm_ub.size | ||
or self._comm_lb.size != self._comm_S.shape[1] | ||
or len(self._comm_metabolites) != self._comm_S.shape[0] | ||
or len(self._comm_reactions) != self._comm_S.shape[1] | ||
or self._comm_biomass_function.size != self._comm_S.shape[1] | ||
or (self._comm_biomass_index < 0) | ||
or (self._comm_biomass_index > self._comm_biomass_function.size) | ||
): | ||
raise Exception( | ||
"Wrong tuple format given to initialize a metabolic network object." | ||
) | ||
except LookupError as error: | ||
raise error.with_traceback(sys.exc_info()[2]) | ||
|
||
|
||
@classmethod | ||
def buildModelList(cls, directory, format_type): | ||
comm_tuple_args = getModelList(directory, format_type) | ||
return cls(comm_tuple_args) | ||
|
||
def fva(self): | ||
"""A member function to apply the FVA method on the community metabolic network.""" | ||
|
||
if self._comm_parameters["fast_computations"]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should set the objective function to the zero vector before FVA() to study the unbiased case. |
||
return fast_fva( | ||
self._comm_lb, | ||
self._comm_ub, | ||
self._comm_S, | ||
self._comm_biomass_function, | ||
self._comm_parameters["opt_percentage"], | ||
) | ||
else: | ||
return slow_fva( | ||
self._comm_lb, | ||
self._comm_ub, | ||
self._comm_S, | ||
self._comm_biomass_function, | ||
self._comm_parameters["opt_percentage"], | ||
) | ||
|
||
def fba(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Which objective function do you use here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to consider an FBA per organism (single standed network) and something like a community FBA for the total community model a.k.a the How about leaving as |
||
"""A member function to apply the FBA method on the community metabolic network.""" | ||
|
||
if self._comm_parameters["fast_computations"]: | ||
return fast_fba(self._comm_lb, self._comm_ub, self._S, self._comm_biomass_function) | ||
else: | ||
return slow_fba(self._comm_lb, self._comm_ub, self._S, self._comm_biomass_function) | ||
|
||
@property | ||
def modelList(self): | ||
return self._modelList | ||
|
||
@property | ||
def lb(self): | ||
return self._comm_lb | ||
|
||
@property | ||
def ub(self): | ||
return self._comm_ub | ||
|
||
@property | ||
def S(self): | ||
return self._comm_S | ||
|
||
@property | ||
def metabolites(self): | ||
return self._comm_metabolites | ||
|
||
@property | ||
def reactions(self): | ||
return self._comm_reactions | ||
|
||
@property | ||
def biomass_index(self): | ||
return self._comm_biomass_index | ||
|
||
@property | ||
def biomass_function(self): | ||
return self._comm_biomass_function | ||
|
||
@property | ||
def parameters(self): | ||
return self._comm_parameters | ||
|
||
@property | ||
def get_as_tuple(self): | ||
return ( | ||
self._comm_lb, | ||
self._comm_ub, | ||
self._comm_S, | ||
self._comm_metabolites, | ||
self._comm_reactions, | ||
self._comm_biomass_index, | ||
self._comm_biomass_function, | ||
) | ||
|
||
def num_of_reactions(self): | ||
return len(self._comm_reactions) | ||
|
||
def num_of_metabolites(self): | ||
return len(self._comm_metabolites) | ||
|
||
@lb.setter | ||
def lb(self, value): | ||
self._comm_lb = value | ||
|
||
@ub.setter | ||
def ub(self, value): | ||
self._comm_ub = value | ||
|
||
@S.setter | ||
def S(self, value): | ||
self._comm_S = value | ||
|
||
@metabolites.setter | ||
def metabolites(self, value): | ||
self._comm_metabolites = value | ||
|
||
@reactions.setter | ||
def reactions(self, value): | ||
self._comm_reactions = value | ||
|
||
@biomass_index.setter | ||
def biomass_index(self, value): | ||
self._comm_biomass_index = value | ||
|
||
@biomass_function.setter | ||
def biomass_function(self, value): | ||
self._comm_biomass_function = value | ||
|
||
def set_fast_mode(self): | ||
|
||
try: | ||
import gurobipy | ||
|
||
self._comm_parameters["fast_computations"] = True | ||
except ImportError as e: | ||
print("You have to install gurobi to use the fast computations.") | ||
self._comm_parameters["fast_computations"] = False | ||
|
||
def set_slow_mode(self): | ||
|
||
self._comm_parameters["fast_computations"] = False | ||
|
||
def set_nullspace_method(self, value): | ||
|
||
self._comm_parameters["nullspace_method"] = value | ||
|
||
def set_opt_percentage(self, value): | ||
|
||
self._comm_parameters["opt_percentage"] = value | ||
|
||
def shut_down_reaction(self, index_val): | ||
|
||
if ( | ||
(not isinstance(index_val, int)) | ||
or index_val < 0 | ||
or index_val >= self._comm_S.shape[1] | ||
): | ||
raise Exception("The input does not correspond to a proper reaction index.") | ||
|
||
self._comm_lb[index_val] = 0 | ||
self._comm_ub[index_val] = 0 | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update the documentation according to your new implementations