Hi Gnu grep folks
I believe that
fgrep -x -f file file
should output the contents of `file`. However, it outputs something very
different for the attached file.
command:
fgrep -x -f dfba.py dfba.py > actual_output.txt
versions:
$ uname -a
Linux 8845f126fe89 4.19.76-linuxkit #1 SMP Thu Oct 17 19:31:58 UTC 2019
x86_64 x86_64 x86_64 GNU/Linux
$ fgrep --version
grep (GNU grep) 3.1
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Mike Haertel and others, see
<http://git.sv.gnu.org/cgit/grep.git/tree/AUTHORS>.
Thanks
Arthur
--
Arthur Goldberg
https://www.linkedin.com/in/arthurgoldberg
artgoldb...@gmail.com
import conv_opt
from de_sim.simulation_object import SimulationObject
from wc_sim import message_types
from wc_sim.config import core as config_core_multialgorithm
from wc_sim.multialgorithm_errors import DynamicMultialgorithmError,
MultialgorithmError
from wc_sim.species_populations import TempPopulationsLSP
from wc_sim.submodels.dynamic_submodel import DynamicSubmodel
from wc_utils.util.list import det_dedupe
class OdeSubmodel(DynamicSubmodel):
messages_sent = [message_types.RunOde]
event_handlers = [(message_types.RunOde, 'handle_RunOde_msg')]
def __init__(self, id, dynamic_model, reactions, species,
dynamic_compartments,
local_species_population, ode_time_step, options=None):
if not isinstance(ode_time_step, (float, int)):
raise MultialgorithmError(f"OdeSubmodel {self.id}: ode_time_step
must be a number but is "
f"{ode_time_step}")
if ode_time_step <= 0:
raise MultialgorithmError("ode_time_step must be positive, but is
{}".format(ode_time_step))
self.ode_time_step = ode_time_step
self.options = options
# log initialization data
self.log_with_time("init: id: {}".format(id))
self.log_with_time("init: time_step: {}".format(str(ode_time_step)))
### dFBA specific code ###
# AG: let's use lower_with_under naming for instance variables
# AG: see https://google.github.io/styleguide/pyguide.html
self.metabolismProductionReaction = None
self.exchangedSpecies = None
self.thermodynamicBounds = None
self.exchangeRateBounds = None
self.defaultOdeBound = 1e15
### AG: should be size of # of reactions, I believe
self.reactionFluxes = np.zeros(0)
self.set_up_ode_submodel()
self.set_up_optimizations()
def set_up_ode_submodel(self):
""" Set up a DFBA submodel, by converting to a linear programming
matrix """
ode_species = []
for idx, rxn in enumerate(self.reactions):
for species_coefficient in rxn.participants:
species_id = species_coefficient.species.gen_id()
ode_species.append(species_id)
self.ode_species_ids = det_dedupe(ode_species)
### dFBA specific code ###
# AG: TODO
# Reuse my code to convert reactions to conv_opt variables
# Create a dictionary that maps variables to reactions
# Create a dictionary that maps species to a dictionary that maps
variables to species stoichiometric coefficient
# Reuse my code to set up the objective function in conv_opt format
self.schedule_next_FBA_analysis()
def schedule_next_ode_analysis(self):
""" Schedule the next analysis by this FBA submodel.
"""
self.send_event(self.ode_time_step, self, message_types.RunOde())
def set_up_optimizations(self):
""" To improve performance, pre-compute and pre-allocate some data
structures """
# make fixed set of species ids used by this OdeSubmodel
self.ode_species_ids_set = set(self.ode_species_ids)
# pre-allocate dict of adjustments used to pass changes to
LocalSpeciesPopulation
self.adjustments = {species_id: None for species_id in
self.ode_species_ids}
# pre-allocate numpy arrays for populations
self.num_species = len(self.ode_species_ids)
self.populations = np.zeros(self.num_species)
def current_species_populations(self):
""" Obtain the current populations of species modeled by this FBA
The current populations are written into `self.populations`.
"""
pops_dict = self.local_species_population.read(self.time,
self.ode_species_ids_set, round=False)
for idx, species_id in enumerate(self.ode_species_ids):
self.populations[idx] = pops_dict[species_id]
def run_ode_solver(self):
""" Run the FBA solver for one time step """
### dFBA specific code ###
# AG: TODO
# AG: do the bounds come from rate laws? I thought they would come from
Reaction flux bounds in
# wc_lang.core.Reaction.flux_min and wc_lang.core.Reaction.flux_max
# Eval rate laws and set as bounds
# Set bounds of exchange reactions
# Maximize objective function and retrieve the reaction fluxes
# If no solution is found, raise error
self.current_species_populations()
# Calculate the adjustment for each species as sum over reactions of
reaction flux * stoichiometry / ode_time_step
# Check that the adjustment will not cause a species population to
become negative
# AG: I think that negative populations will need to generate an error
# the only other possibility would be to reduce the time step such that
populations
# stay positive, subject to a minimum time step
# If it becomes negative, then change the adjustment so that the
species population is zero
### store results in local_species_population ###
self.local_species_population.adjust_continuously(self.time,
self.adjustments)
# flush expressions that depend on species and reactions modeled by
this FBA submodel from cache
# AG: we can rename "ode_flush_after_populations_change" to
# "continuous_submodel_flush_after_populations_change" and use it both
here and in odes.py
self.dynamic_model.ode_flush_after_populations_change(self.id) # will
add this method to dynamic_components.py
def handle_RunOde_msg(self):
""" Handle an event containing a RunOde message
Args:
event (:obj:`Event`): a simulation event
"""
self.run_ode_solver()
self.schedule_next_ode_analysis()
import conv_opt
from de_sim.simulation_object import SimulationObject
from wc_sim import message_types
from wc_sim.config import core as config_core_multialgorithm
from wc_sim.multialgorithm_errors import DynamicMultialgorithmError, MultialgorithmError
from wc_sim.species_populations import TempPopulationsLSP
from wc_sim.submodels.dynamic_submodel import DynamicSubmodel
from wc_utils.util.list import det_dedupe
class OdeSubmodel(DynamicSubmodel):
messages_sent = [message_types.RunOde]
event_handlers = [(message_types.RunOde, 'handle_RunOde_msg')]
def __init__(self, id, dynamic_model, reactions, species, dynamic_compartments,
local_species_population, ode_time_step, options=None):
if not isinstance(ode_time_step, (float, int)):
raise MultialgorithmError(f"OdeSubmodel {self.id}: ode_time_step must be a number but is "
f"{ode_time_step}")
if ode_time_step <= 0:
raise MultialgorithmError("ode_time_step must be positive, but is {}".format(ode_time_step))
self.ode_time_step = ode_time_step
self.options = options
# log initialization data
self.log_with_time("init: id: {}".format(id))
self.log_with_time("init: time_step: {}".format(str(ode_time_step)))
### dFBA specific code ###
# AG: let's use lower_with_under naming for instance variables
# AG: see https://google.github.io/styleguide/pyguide.html
self.metabolismProductionReaction = None
self.exchangedSpecies = None
self.thermodynamicBounds = None
self.exchangeRateBounds = None
self.defaultOdeBound = 1e15
### AG: should be size of # of reactions, I believe
self.reactionFluxes = np.zeros(0)
self.set_up_ode_submodel()
self.set_up_optimizations()
def set_up_ode_submodel(self):
""" Set up a DFBA submodel, by converting to a linear programming matrix """
ode_species = []
for idx, rxn in enumerate(self.reactions):
for species_coefficient in rxn.participants:
species_id = species_coefficient.species.gen_id()
ode_species.append(species_id)
self.ode_species_ids = det_dedupe(ode_species)
### dFBA specific code ###
# AG: TODO
# Reuse my code to convert reactions to conv_opt variables
# Create a dictionary that maps variables to reactions
# Create a dictionary that maps species to a dictionary that maps variables to species stoichiometric coefficient
# Reuse my code to set up the objective function in conv_opt format
self.schedule_next_FBA_analysis()
def schedule_next_ode_analysis(self):
""" Schedule the next analysis by this FBA submodel.
"""
self.send_event(self.ode_time_step, self, message_types.RunOde())
def set_up_optimizations(self):
""" To improve performance, pre-compute and pre-allocate some data structures """
# make fixed set of species ids used by this OdeSubmodel
self.ode_species_ids_set = set(self.ode_species_ids)
# pre-allocate dict of adjustments used to pass changes to LocalSpeciesPopulation
self.adjustments = {species_id: None for species_id in self.ode_species_ids}
# pre-allocate numpy arrays for populations
self.num_species = len(self.ode_species_ids)
self.populations = np.zeros(self.num_species)
def current_species_populations(self):
""" Obtain the current populations of species modeled by this FBA
The current populations are written into `self.populations`.
"""
pops_dict = self.local_species_population.read(self.time, self.ode_species_ids_set, round=False)
for idx, species_id in enumerate(self.ode_species_ids):
self.populations[idx] = pops_dict[species_id]
def run_ode_solver(self):
""" Run the FBA solver for one time step """
### dFBA specific code ###
# AG: TODO
# AG: do the bounds come from rate laws? I thought they would come from Reaction flux bounds in
# wc_lang.core.Reaction.flux_min and wc_lang.core.Reaction.flux_max
# Eval rate laws and set as bounds
# Set bounds of exchange reactions
# Maximize objective function and retrieve the reaction fluxes
# If no solution is found, raise error
self.current_species_populations()
# Calculate the adjustment for each species as sum over reactions of reaction flux * stoichiometry / ode_time_step
# Check that the adjustment will not cause a species population to become negative
# AG: I think that negative populations will need to generate an error
# the only other possibility would be to reduce the time step such that populations
# stay positive, subject to a minimum time step
# If it becomes negative, then change the adjustment so that the species population is zero
### store results in local_species_population ###
self.local_species_population.adjust_continuously(self.time, self.adjustments)
# flush expressions that depend on species and reactions modeled by this FBA submodel from cache
# AG: we can rename "ode_flush_after_populations_change" to
# "continuous_submodel_flush_after_populations_change" and use it both here and in odes.py
self.dynamic_model.ode_flush_after_populations_change(self.id) # will add this method to dynamic_components.py
def handle_RunOde_msg(self):
""" Handle an event containing a RunOde message
Args:
event (:obj:`Event`): a simulation event
"""
self.run_ode_solver()
self.schedule_next_ode_analysis()