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 all 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/
219 changes: 219 additions & 0 deletions dingo/CommunityMetabolicNetwork.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
# dingo : a python library for metabolic networks sampling and analysis
# dingo is part of GeomScale project

# Copyright (c) 2021 Apostolos Chalkis
# Copyright (c) 2021 Haris Zafeiropoulos

# Licensed under GNU LGPL.3, see LICENCE file

import numpy as np
import sys, os
from dingo.loading_models import read_json_file, read_mat_file, get_model_list
from dingo.fva import slow_fva
from dingo.fba import slow_fba

try:
import gurobipy
from dingo.gurobi_based_implementations import fast_fba, fast_fva, fast_inner_ball
except ImportError as e:
pass

class CommunityMetabolicNetwork():

# 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 = get_model_list(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"]:
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 max_community_growth_rate(self):
"""A member function to apply the FBA method on the growth rate of the community metabolic network.
Based on the micom concept for modeling a microbial community."""

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