Пример #1
0
def latexify_file(filename, arguments):
  """ Converts a file containing Bio-PEPA source into a file containing
      LaTeX source to format the same model.
  """
  model_file = open(filename, "r")
  parse_result = biopepa_parser.parse_model_file_exit_on_error(model_file)
  model_file.close()

  biopepa_model = parse_result

  out_filename = utils.get_output_filename(filename, arguments, ".tex")
  if out_filename == "stdout":
    translate_biopepa_model(biopepa_model, sys.stdout)
  else:
    out_file = open(out_filename, "w")
    translate_biopepa_model(biopepa_model, out_file)
    out_file.close()
Пример #2
0
def output_to_sbml_file(filename, arguments, document):
  """A utility function for consumers of this module to calculate
     the output file for given a set of parsed arguments which includes
     the possible argument "--output-file". We then output the given
     document to that file. This is basically a suitable place to put
     this functionality that is common to nearly all x_to_sbml translators
     that we have.
     Note that the first argument is the filename of the file from which
     we have translated into sbml and not the sbml filename itself.
  """
  sbml_filename = utils.get_output_filename(filename, arguments, ".sbml")
  if sbml_filename == "stdout":
    sbml_file = sys.stdout
  else:
    sbml_file =  open(sbml_filename, "w")
  
  output_to_file(sbml_file, document)

  if sbml_filename != "stdout":
    sbml_file.close()
def run(arguments_parser, get_new_timecourse, needs_arguments):
  """
     The shell of the main method, essentially does all the busy work
     and accepts a function which will given a read-in timecourse,
     return a new timecourse.
  """
  arguments = arguments_parser.parse_args()
  if len(arguments.filenames) < 1:
    print ("Must provide at least one timeseries to add noise to")
    sys.exit(1)

  # We should do all this, once for each timecourse file.
  timecourse_file = arguments.filenames[0]
  timecourse = timeseries.get_timecourse_from_file(timecourse_file)

  all_names = timecourse.get_column_names()
  used_names = utils.get_non_ignored(all_names,
                                     arguments.column,
                                     arguments.mcolumn)
  for name in all_names:
    if name not in used_names:
      timecourse.remove_column(name)

  if needs_arguments:
    new_timecourse = get_new_timecourse(arguments, timecourse)  
  else:
    new_timecourse = get_new_timecourse(timecourse)  

   
  output_filename = utils.get_output_filename(timecourse_file, arguments,
                                              "_modified.csv")
  if output_filename == "stdout":
    output_file = sys.stdout
  else:
    output_file = open(output_filename, "w")

  # Write the new time course to the file
  new_timecourse.write_to_file(output_file)

  if output_filename != "stdout":
    output_file.close()
Пример #4
0
def process_file(filename, arguments):
  """Parse in a Bio-PEPA file and convert to an equivalent Bio-PEPA
     file that is flattened in the sense that it uses no compartments
     and hence no compartment-related rules.
  """
  model_file = open(filename, "r")
  parse_result = biopepa_parser.parse_model_file_exit_on_error(model_file)
  model_file.close()

  output_filename = utils.get_output_filename(filename, arguments,
                                              "_flattened.biopepa") 
  if output_filename != "stdout":
    output_file = open(output_filename, "w")
  else:
    output_file = sys.stdout


  flatten_model(parse_result)
  parse_result.output_model(output_file)

  if output_filename != "stdout":
    output_file.close()
Пример #5
0
def convert(source, target, models):
    # Load the versions graph which has information about possible conversions.
    versions_graph = Graph()
    directory = dirname(sys.argv[0]) or "."
    versions_graph.parse(directory + "/conversions/versions.ttl",
                         format="turtle")
    versions_graph.bind("version",
                        Namespace("https://brickschema.org/version#"))

    # Ask if the conversion is possible
    job = versions_graph.query("""ASK{
                        "%s" version:convertsTo+ "%s"
    }""" % (source, target))

    # If yes, find the shortest path and convert
    for doable in job:
        if doable:
            print("Conversion available!\n=====================")
            # Find the conversions to update the model in minimum number of version upgrades
            conversions = find_conversions(source, target, versions_graph)

            # Loop through all the input models
            for model in models:
                print("\n\nUpdating {}...".format(model))

                standardize_namespaces(model)

                # Execute all conversions
                for conversion in conversions:
                    model_graph = Graph()
                    model_graph.parse(model, format="turtle")
                    print("Converting to {}...".format(conversion[1]))
                    execute_conversions(conversion, model_graph)
                    output = get_output_filename(model, conversion[1])
                    model_graph.serialize(output, format="turtle")
                print("Output stored: {}".format(output))
        else:
            print("No conversions available from {} to {}.".format(
                source, target))