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

Sampling on the flux space of multiple metabolic networks #18

Closed
wants to merge 65 commits into from
Closed
Show file tree
Hide file tree
Changes from 59 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
cb6005e
unknown
hariszaf Jul 15, 2021
3fc3d12
Revert "Create CODE_OF_CONDUCT.md"
hariszaf Jul 15, 2021
ffd7eaf
Revert "Update issue templates"
hariszaf Jul 15, 2021
e251c0a
Revert "unknown"
hariszaf Jul 15, 2021
3c80cc6
Revert "Revert "Create CODE_OF_CONDUCT.md""
hariszaf Jul 15, 2021
f82fcce
Revert "Revert "Update issue templates""
hariszaf Jul 15, 2021
cad5e53
parse 2 models and build concatenated S
hariszaf Aug 15, 2021
a30828a
.mat models for species of a
hariszaf Aug 15, 2021
a16cebf
.mat models for species of b
hariszaf Aug 15, 2021
04944a7
.mat models for species of c
hariszaf Aug 15, 2021
47623cb
init classes for community level
hariszaf Aug 15, 2021
d370bb3
embl models in mat format
hariszaf Aug 15, 2021
223e4a8
embl models in mat format
hariszaf Aug 15, 2021
1056bff
embl models in mat format
hariszaf Aug 15, 2021
bc592b3
embl models in mat format
hariszaf Aug 16, 2021
ac1dba7
embl models in mat format
hariszaf Aug 16, 2021
667099c
embl models in mat format
hariszaf Aug 16, 2021
2942009
embl models in mat format
hariszaf Aug 16, 2021
b40df75
embl models in mat format
hariszaf Aug 16, 2021
668a5fb
embl models in mat format
hariszaf Aug 16, 2021
ac25f50
embl models in mat format
hariszaf Aug 16, 2021
a3f5e31
embl models in mat format
hariszaf Aug 16, 2021
ad30113
embl models in mat format
hariszaf Aug 16, 2021
c59de31
embl models in mat format
hariszaf Aug 16, 2021
006d34d
embl models in mat format
hariszaf Aug 16, 2021
bffe305
embl models in mat format
hariszaf Aug 16, 2021
2111699
embl models in mat format
hariszaf Aug 16, 2021
e7bb703
embl models in mat format
hariszaf Aug 16, 2021
03eb29b
embl models in mat format
hariszaf Aug 16, 2021
7858ca1
embl models in mat format
hariszaf Aug 16, 2021
53d6636
embl models in mat format
hariszaf Aug 16, 2021
c383567
embl models in mat format
hariszaf Aug 16, 2021
cccd9e0
embl models in mat format
hariszaf Aug 16, 2021
892c9ed
new function for building the community level model
hariszaf Aug 16, 2021
ae181b7
new class for building community level model
hariszaf Aug 16, 2021
fe54929
fix identification error
hariszaf Aug 16, 2021
5d4e46e
communityMetabolicNetwork class for loading multiple files and buildi…
hariszaf Aug 16, 2021
11897e0
fix typo in class name
hariszaf Aug 16, 2021
937becb
buildConqMatrix function added
hariszaf Aug 16, 2021
1b1db5e
import buildConqMatrix
hariszaf Aug 16, 2021
0dacb91
fix self variables
hariszaf Aug 16, 2021
5905950
import CommunityPolytopeSampler class
hariszaf Aug 16, 2021
d2087ce
building the sampling function for community; in progress
hariszaf Aug 16, 2021
e2dc87f
getIndividualMatrices and matrices_for_community_level functions working
hariszaf Aug 16, 2021
dfe2e75
sampling on the flux space of 2 models
hariszaf Aug 16, 2021
bff70ea
remove .mat.gz from mmodels dir
hariszaf Aug 17, 2021
f0455db
merge @ dell in the /GitHub dir
hariszaf Aug 17, 2021
0978a59
script to build .mat models from .xml ones
hariszaf Aug 17, 2021
17d6d0b
ignore notebook checkpoints
hariszaf Aug 17, 2021
9371331
test case for the community classes
hariszaf Aug 17, 2021
62bc662
modifs
hariszaf Aug 17, 2021
3dea11a
add parameters for community models
hariszaf Aug 19, 2021
f825b4c
modif in comment
hariszaf Aug 19, 2021
ec73f68
add community case
hariszaf Aug 19, 2021
28484da
fix args
hariszaf Aug 19, 2021
2359c86
modifs
hariszaf Aug 19, 2021
dd39486
modifs to fix main for community
hariszaf Aug 19, 2021
96f7851
remove .mat models; they ll be available in a zenodo repo
hariszaf Aug 31, 2021
95caaa7
replace the 2 model files with a README
hariszaf Aug 31, 2021
2ee3a25
running from terminal example
hariszaf Aug 31, 2021
3518d78
one class per file; according modifs to import classes
hariszaf Sep 20, 2021
2a7db96
replace the pair-based notion in the get_model_list for multiple spec…
hariszaf Sep 22, 2021
6128d20
notebook to set the workflow for working with polyround - hops
hariszaf Sep 25, 2021
cb31f4d
merge before adding jupyter notebook for hops and polyround
hariszaf Sep 25, 2021
747bb13
maybe mapped samples maybe not
hariszaf Sep 25, 2021
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ dingo.egg-info
volestipy.cpp
volestipy.egg-info
*.npy

.ipynb_checkpoints/
230 changes: 216 additions & 14 deletions dingo/MetabolicNetwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Member

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

Expand All @@ -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:
Expand All @@ -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)
Expand Down Expand Up @@ -223,3 +223,205 @@ def shut_down_reaction(self, index_val):

self._lb[index_val] = 0
self._ub[index_val] = 0


class CommunityMetabolicNetwork():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use a single .py document per class

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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"]:
Copy link
Member

Choose a reason for hiding this comment

The 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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which objective function do you use here?
I think FBA has to be separately applied in each model to obtain the maximum value per model.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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 μ_c as described in the micom concept..

How about leaving as fba the per organism and build a new function for community growth ?

"""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


Loading