コード例 #1
0
 def __init__(self, model):
   self.species = outline_sbml.get_list_of_species(model)
   self.assignment_rules = outline_sbml.get_list_of_assignment_rules(model)
   self.assignments = dict()
   for assignment_rule in self.assignment_rules:
     name = assignment_rule.get_variable_name()
     self.assignments[name] = assignment_rule.get_assigned_expr()
コード例 #2
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()
コード例 #3
0
 def species(self):
   """ Returns the species of the model again possibly parsing the model,
       again the species are then stored such that subsequent calls will
       not involve any re-parsing.
   """
   if self._species:
     return self._species
   else:
     species = outline_sbml.get_list_of_species(self.model)
     self._species = species
     return species
コード例 #4
0
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
コード例 #5
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()
コード例 #6
0
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
コード例 #7
0
def convert_file(filename):
  """Given an sbml file convert it into the corresponding UserModel.{ch}
     files for use with sbsi numerics
  """
  dom = xml.dom.minidom.parse(filename)
  model = dom.getElementsByTagName("model")[0]
  species = outline_sbml.get_list_of_species(model)

  model_name = model.getAttribute("name")
  if not model_name:
    model_name = model.getAttribute("id")
  if not model_name:
    model_name = "nameless_model"

  c_file = open ("UserModel.C", "w")
  c_file.write(
  """#include <cmath>
using namespace std;

#include <cModel.h>
#include "UserModel.h"
#define pi M_PI 
  """)

  c_file.write("/**** The model has " + str(len(species)) + 
               " species ****/\n")
  c_file.write("void " + model_name + "::inputModel(){\n")

  # For each species 
  for component in species:
    if component.initial_amount:
      c_file.write ("  setStateByName(\"" + component.ident +
                    "\", " + str(component.initial_amount) + ");\n")
    else:
      c_file.write ("  // Setting the state to zero as it should be\n")
      c_file.write ("  // updated by an initial assignment\n")
      c_file.write ("  setStateByName(\"" + component.ident +
                    "\", 0);\n")

  # We also need to do the same for variables and parameters
  parameters = outline_sbml.get_list_of_parameters(model)
  for param in parameters:
    if param.value:
      c_file.write("  setParamByName(\"" + param.ident +
                   "\", " + param.value + ");\n")
    else:
      c_file.write("  // Parameter's value not set in model file\n")
      c_file.write("  // Presumably set elsewhere, eg initialAssignment\n")
      c_file.write("  setParamByName(\"" + param.ident +
                   "\", 0);\n")
      
   

  c_file.write(
"""
	/*  0th Species with Id A  in main */   
	// Setting the state to zero as it should be 
	// updated by an initial assinment
	setStateByName("A",0);

	/*  1th Species with Id B  in main */   
	// Setting the state to zero as it should be 
	// updated by an initial assinment
	setStateByName("B",0);

	/*  2th Species with Id AB  in main */   
	// Setting the state to zero as it should be 
	// updated by an initial assinment
	setStateByName("AB",0);


	setVarByName("AB",0);

	setParamByName("k1",1);
	setParamByName("k2",1);
	setParamByName("k3",1);
	setParamByName("main",1);
	};
""")


  c_file.write("\n")
  c_file.close()