Skip to content
Snippets Groups Projects
Commit 0710e3bb authored by Peter Schubert's avatar Peter Schubert
Browse files

Added fbc_gene_product and collect gene-product-association

parent 010bef12
No related branches found
No related tags found
No related merge requests found
"""Implementation of FbcGeneProduct class.
Peter Schubert, HHU Duesseldorf, July 2022
"""
class FbcGeneProduct:
def __init__(self, s_fbc_gene_product):
self.id = s_fbc_gene_product.name
self.name = s_fbc_gene_product.get('name', '')
self.label = s_fbc_gene_product['label']
...@@ -97,7 +97,7 @@ class SboTerm: ...@@ -97,7 +97,7 @@ class SboTerm:
@property @property
def sbo_term(self): def sbo_term(self):
return self.__sbo_term return re.sub('_', ':', self.__sbo_term)
@sbo_term.setter @sbo_term.setter
def sbo_term(self, sbo_term): def sbo_term(self, sbo_term):
......
...@@ -14,6 +14,7 @@ from .xba_parameter import XbaParameter ...@@ -14,6 +14,7 @@ from .xba_parameter import XbaParameter
from .xba_reaction import XbaReaction from .xba_reaction import XbaReaction
from .xba_species import XbaSpecies from .xba_species import XbaSpecies
from .fbc_objective import FbcObjective from .fbc_objective import FbcObjective
from .fbc_gene_product import FbcGeneProduct
# TODO: implement isGBAmodel(), isFBAmodel(), isRBAmodel() # TODO: implement isGBAmodel(), isFBAmodel(), isRBAmodel()
...@@ -51,6 +52,9 @@ class XbaModel: ...@@ -51,6 +52,9 @@ class XbaModel:
if 'fbcObjectives' in model_dict: if 'fbcObjectives' in model_dict:
self.fbc_objectives = {oid: FbcObjective(row) self.fbc_objectives = {oid: FbcObjective(row)
for oid, row in model_dict['fbcObjectives'].iterrows()} for oid, row in model_dict['fbcObjectives'].iterrows()}
if 'fbcGeneProducts' in model_dict:
self.fbc_gene_products = {gp_id: FbcGeneProduct(row)
for gp_id, row in model_dict['fbcGeneProducts'].iterrows()}
def get_stoic_matrix(self, sids, rids): def get_stoic_matrix(self, sids, rids):
"""retrieve stoichiometric sub-matrix [sids x rids]. """retrieve stoichiometric sub-matrix [sids x rids].
......
...@@ -47,6 +47,9 @@ class XbaReaction: ...@@ -47,6 +47,9 @@ class XbaReaction:
if self.reversible is False: if self.reversible is False:
self.fbc_lb = max(0, self.fbc_lb) self.fbc_lb = max(0, self.fbc_lb)
self.fbc_ub = max(0, self.fbc_ub) self.fbc_ub = max(0, self.fbc_ub)
if 'fbcGeneProdAssoc' in s_reaction:
if type(s_reaction['fbcGeneProdAssoc']) == str:
self.fbc_gpa = re.sub(r'^assoc=', '', s_reaction['fbcGeneProdAssoc'])
if 'xmlAnnotation' in s_reaction: if 'xmlAnnotation' in s_reaction:
attrs = sbmlxdf.extract_xml_attrs(s_reaction['xmlAnnotation'], ns=xml_rba_ns, token='kinetics') attrs = sbmlxdf.extract_xml_attrs(s_reaction['xmlAnnotation'], ns=xml_rba_ns, token='kinetics')
if 'kapp_f_per_s' in attrs: if 'kapp_f_per_s' in attrs:
......
...@@ -34,7 +34,7 @@ class XbaSpecies: ...@@ -34,7 +34,7 @@ class XbaSpecies:
if 'process_capacity_per_s' in attrs: if 'process_capacity_per_s' in attrs:
self.rba_process_capacity = float(attrs.pop('process_capacity_per_s')) self.rba_process_capacity = float(attrs.pop('process_capacity_per_s'))
if len(attrs) > 0: if len(attrs) > 0:
self.rba_process_costs = attrs self.rba_process_costs = {key: float(val) for key, val in attrs.items()}
self.ps_rid = None self.ps_rid = None
self.m_reactions = {} self.m_reactions = {}
......
...@@ -143,7 +143,6 @@ class FbaProblem: ...@@ -143,7 +143,6 @@ class FbaProblem:
if lp is None: if lp is None:
return {'success': False, 'message': 'not an FBA model'} return {'success': False, 'message': 'not an FBA model'}
res = lp.solve() res = lp.solve()
del lp
res['x'] = self.combine_fwd_bwd(res['x']) res['x'] = self.combine_fwd_bwd(res['x'])
res['reduced_costs'] = self.combine_fwd_bwd(res['reduced_costs']) res['reduced_costs'] = self.combine_fwd_bwd(res['reduced_costs'])
return res return res
...@@ -176,7 +175,6 @@ class FbaProblem: ...@@ -176,7 +175,6 @@ class FbaProblem:
res = lp.solve() res = lp.solve()
res['x'] = self.combine_fwd_bwd(res['x']) res['x'] = self.combine_fwd_bwd(res['x'])
res['reduced_costs'] = self.combine_fwd_bwd(res['reduced_costs']) res['reduced_costs'] = self.combine_fwd_bwd(res['reduced_costs'])
del lp
return res return res
def fva_optimize(self, rids=None, fract_of_optimum=1.0): def fva_optimize(self, rids=None, fract_of_optimum=1.0):
...@@ -231,7 +229,6 @@ class FbaProblem: ...@@ -231,7 +229,6 @@ class FbaProblem:
else: else:
print(f"FVA max failed for {rid}") print(f"FVA max failed for {rid}")
flux_ranges[1, idx] = np.nan flux_ranges[1, idx] = np.nan
del lp
res = {'rids': rids, 'min': flux_ranges[0], 'max': flux_ranges[1], res = {'rids': rids, 'min': flux_ranges[0], 'max': flux_ranges[1],
'obj_min': flux_ranges[2], 'obj_max': flux_ranges[3]} 'obj_min': flux_ranges[2], 'obj_max': flux_ranges[3]}
......
...@@ -24,6 +24,8 @@ class RbaProblem: ...@@ -24,6 +24,8 @@ class RbaProblem:
:param xba_model: :param xba_model:
""" """
self.xba_model = xba_model
# metabolic reactions and enzyme transitions (no FBA reactions, no protein synthesis, no degradation) # metabolic reactions and enzyme transitions (no FBA reactions, no protein synthesis, no degradation)
self.mr_rids = [r.id for r in xba_model.reactions.values() if r.sboterm.is_in_branch('SBO:0000167') self.mr_rids = [r.id for r in xba_model.reactions.values() if r.sboterm.is_in_branch('SBO:0000167')
and r.sboterm.is_in_branch('SBO:0000179') is False] and r.sboterm.is_in_branch('SBO:0000179') is False]
...@@ -145,7 +147,6 @@ class RbaProblem: ...@@ -145,7 +147,6 @@ class RbaProblem:
lp = LpProblem() lp = LpProblem()
lp.configure(self.obj_coefs, constr_coefs, self.fix_row_bnds, self.col_bnds, self.obj_dir) lp.configure(self.obj_coefs, constr_coefs, self.fix_row_bnds, self.col_bnds, self.obj_dir)
res = lp.solve(scaling=self.scaling) res = lp.solve(scaling=self.scaling)
del lp
if res['success'] and res['fun'] > 1e-10: if res['success'] and res['fun'] > 1e-10:
gr['lb'] = gr['try'] gr['lb'] = gr['try']
gr['try'] *= 10 gr['try'] *= 10
...@@ -169,13 +170,19 @@ class RbaProblem: ...@@ -169,13 +170,19 @@ class RbaProblem:
lp = LpProblem() lp = LpProblem()
lp.configure(self.obj_coefs, constr_coefs, self.fix_row_bnds, self.col_bnds, self.obj_dir) lp.configure(self.obj_coefs, constr_coefs, self.fix_row_bnds, self.col_bnds, self.obj_dir)
res = lp.solve(scaling=self.scaling) res = lp.solve(scaling=self.scaling)
del lp
if res['success'] and res['fun'] > 1e-10: if res['success'] and res['fun'] > 1e-10:
gr['lb'] = gr['try'] gr['lb'] = gr['try']
else: else:
gr['ub'] = gr['try'] gr['ub'] = gr['try']
if (gr['ub'] - gr['lb']) < gr['try'] * 1e-5: if (gr['ub'] - gr['lb']) < gr['try'] * 1e-5:
break break
# get optimum values for the final solution
gr['try'] = gr['lb']
constr_coefs = self.fix_mat + gr['try'] * self.var_mat
lp = LpProblem()
lp.configure(self.obj_coefs, constr_coefs, self.fix_row_bnds, self.col_bnds, self.obj_dir)
res = lp.solve(scaling=self.scaling)
res['fun'] = gr['try'] res['fun'] = gr['try']
return res return res
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment