def convert_file(filename, arguments): """Given an sbml file convert it into a corresponding facile model""" model = outline_sbml.get_model_from_sbml_file(filename) if arguments.output_file: eqn_filename = arguments.output_file else: eqn_filename = utils.change_filename_ext(filename, ".eqn") if eqn_filename == "stdout": output_file = sys.stdout else: output_file = open(eqn_filename, "w") # We also need to do the same for variables and parameters parameters = outline_sbml.get_list_of_parameters(model) for param in parameters: output_file.write(" ".join(["variable", param.name, "=", param.value, ";\n"])) # Reactions reactions = outline_sbml.get_list_of_reactions(model) for reaction in reactions: output_reaction(output_file, reaction) output_file.write("\nINIT\n") species = outline_sbml.get_list_of_species(model) init_assigns = outline_sbml.get_list_of_init_assigns(model) for component in species: init_string = component.initial_amount for init_assign in init_assigns: if init_assign.variable == component.name: init_string = format_math_element(init_assign.expression) output_file.write(component.name + " = " + init_string + " N;\n") if eqn_filename != "stdout": output_file.close()
def reactions(self): """Returns the reactions of the associated model, may parse the model file if it hasn't occured already """ if self._reactions: return self._reactions else: reactions = outline_sbml.get_list_of_reactions(self.model) self._reactions = reactions return reactions
def check_rates_sbml_model(model, arguments): """Perform analysis over the rate definitions of an SBML model""" reactions = outline_sbml.get_list_of_reactions(model) rate_analyser = RateAnalyser(model) num_warnings = 0 for reaction in reactions: allow_products = arguments.allow_reversible_products num_warnings += check_reaction(reaction, rate_analyser, allow_reversible=allow_products) return num_warnings
def kig_of_model(model, ignore_sources, ignore_sinks): """Compute and return the kinetic independence graph of a model. The kig is simply a mapping from reactions to their effects on the population of each species""" species = outline_sbml.get_list_of_species(model) # species_names = [ spec.get_name() for spec in species ] species_names = [ spec.ident for spec in species ] all_reactions = outline_sbml.get_list_of_reactions(model) reactions = [ r for r in all_reactions if (not r.is_source() or not ignore_sources) and (not r.is_sink() or not ignore_sinks) ] reaction_names = [ r.name for r in reactions ] kig = KinecticIndependenceGraph(species_names, reaction_names) for reaction in reactions: kig.add_reaction_info(reaction) return kig
def translate_file(filename, arguments): """Given an sbml file convert it into a corresponding Bio-PEPA model""" model = outline_sbml.get_model_from_sbml_file(filename) if arguments.output_file: biopepa_filename = arguments.output_file else: biopepa_filename = utils.change_filename_ext(filename, ".biopepa") if biopepa_filename == "stdout": output_file = sys.stdout else: output_file = open(biopepa_filename, "w") output_file.write("\n\n// Parameters\n") # We also need to do the same for variables and parameters parameters = outline_sbml.get_list_of_parameters(model) for param in parameters: output_file.write(" ".join([param.name, "=", param.value, ";\n"])) output_file.write("\n") # Reactions reactions = outline_sbml.get_list_of_reactions(model) output_file.write("\n\n// Rate Definitions\n") for reaction in reactions: output_file.write(reaction.name + " = [ ") output_file.write(format_math_element(reaction.kinetic_law)) output_file.write(" ] ;\n") output_file.write("\n\n// Component Definitions\n") component_defs = calculate_component_defs(reactions) for component_def in component_defs: output_file.write(component_def.show_definition()) output_file.write("\n") output_file.write("\n// System Equation\n") species = outline_sbml.get_list_of_species(model) init_assigns = outline_sbml.get_list_of_init_assigns(model) output_system_equation(output_file, species, init_assigns) if biopepa_filename != "stdout": output_file.close()
def reaction_knockout_kigs(filename, ignore_sources, ignore_sinks): """From an sbml file, return a list of kinetic information graphs, where for each reaction in the model there is a single kig which is derived from the model whilst ignoring that one reaction (and its inverse if present) and the source and/or sink reactions if those parameters are set to True """ dom = xml.dom.minidom.parse(filename) model = dom.getElementsByTagName("model")[0] species = outline_sbml.get_list_of_species(model) species_names = [ spec.get_name() for spec in species ] all_reactions = outline_sbml.get_list_of_reactions(model) non_ignored_reactions = [ r for r in all_reactions if (not r.is_source() or not ignore_sources) and (not r.is_sink() or not ignore_sinks) ] reactions = remove_inversed_reactions(non_ignored_reactions) kig_dictionary = dict() for reaction in reactions: kig = create_knocked_out_kig(reaction, reactions, species_names) kig_dictionary[reaction.name] = kig return kig_dictionary