def write_fluxes_to_objectives( fluxes: np_series, objective_value: float, rpsbml: rpSBML, objective_id: str, logger: Logger = getLogger(__name__)) -> None: """ Write Cobra results to the reactions of pathway with id pathway_id in rpsbml object. Parameters ---------- fluxes: np_series Fluxes. objective_value: float Value of the objective. rpsbml: rpSBML rpSBML object of which reactions will be updated with results objective_id: str The id of the objective to optimise """ rpsbml.logger.debug( 'Set the objective ' + str(objective_id) \ + ' a flux_value of ' + str(objective_value) ) # get the objective obj = rpsbml.getObjective(objective_id, objective_value) rpsbml.updateBRSynth(obj, 'flux_value', str(objective_value)) Bigg_Reaction_Prefix = 'R_' for flux_obj in obj.getListOfFluxObjectives(): rxn_id = flux_obj.getReaction() if rxn_id.startswith(Bigg_Reaction_Prefix): rxn_id = rxn_id[2:] flux = fluxes.get(rxn_id) # sometimes flux cannot be returned if flux is None: rpsbml.logger.warning( f'Cannot retrieve reaction ID {str(rxn_id)} flux from cobrapy... setting to 0.0' ) flux = 0.0 rpsbml.logger.debug( 'Set the reaction ' + str(rxn_id) \ + ' a flux_value of ' + str(flux) ) rpsbml.updateBRSynth(flux_obj, 'flux_value', str(flux))
def write_fluxes_to_reactions( fluxes: np_series, rpsbml: rpSBML, pathway_id: str, sim_type: str, logger: Logger = getLogger(__name__)) -> None: """ Write Cobra results to the reactions of pathway with id pathway_id in rpsbml object. Parameters ---------- fluxes: np_series Fluxes. rpsbml: rpSBML rpSBML object of which reactions will be updated with results pathway_id: str The id of the pathway within reactions will be updated objective_id: str The id of the objective to optimise """ rp_pathway = rpsbml.getGroup(pathway_id) for member in rp_pathway.getListOfMembers(): rxn = rpsbml.getModel().getReaction(member.getIdRef()) if rxn is None: logger.error( 'Cannot retreive the following reaction: ' \ + str(member.getIdRef()) ) #return False continue flux = fluxes.get(rxn.getId()) logger.debug( 'Set the reaction ' + str(member.getIdRef()) \ + ' a ' + str('fba_' + str(sim_type)) \ + ' of ' + str(flux)) rpsbml.updateBRSynth(rxn, 'fba_' + str(sim_type), str(flux))