Ejemplo n.º 1
0
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()
Ejemplo n.º 2
0
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()