def main():
  """Create the command-line parser, parse in all the timecourse files
     adding them together into one overall timecourse and finally out
     put the result to standard out"""
  description = """Add together a bunch of timeseries"""
  parser = argparse.ArgumentParser(add_help=True,
                                   description=description)
   # Might want to make the type of this 'FileType('r')'
  parser.add_argument('filenames', metavar='F', nargs='+',
                      help="A function definition file to translate")
  parser.add_argument('--column', action=utils.ListArgumentAction,
                      help="Specify a column to be plotted")
  parser.add_argument('--mcolumn', action=utils.ListArgumentAction,
                      help="Specify a column not to be plotted")
  parser.add_argument('--output-separator', action='store',
                      help="Specify the separator to use in the output")
 
  arguments = parser.parse_args()

  timecourse = timeseries.get_timecourse_from_file(arguments.filenames[0])
  for filename in arguments.filenames[1:]:
    additional_timecourse = timeseries.get_timecourse_from_file(filename)
    timecourse.add_timeseries(additional_timecourse)

  for column_name in timecourse.get_column_names():
    if not plotcsv.should_plot_column(arguments, column_name):
      timecourse.remove_column(column_name)

  separator = arguments.output_separator
  if separator == "tab":
    separator = "\t"
  timecourse.write_to_file(sys.stdout, separator=separator)
def process_file(filename):
  """Do the work for a single file"""
  timecourse = timeseries.get_timecourse_from_file(filename)

  timecourse.remove_zero_columns()
   
  # note, now it's not actually a new file, but the current one
  # so that we are actually overwriting the file 
  newfile = open (filename, "w")
  timecourse.write_to_file(newfile)
  newfile.close()
def check_experimental_data(sbml_file, timecourse_file):
  """Parse in both an sbml file and a time course data file. Calculate
     the invariants of the sbml file and attempt to determine whether
     or not the experimental data conforms to the invariant. We could also
     get the initial populations of the species and determine whether or
     not the model is capable of matching the experimental data.
  """
  inv_inferer = invariant_inferer_model_file(sbml_file, False, False)
  timecourse = timeseries.get_timecourse_from_file(timecourse_file)

  invariants = inv_inferer.calculate_invariants()
 
  for invariant in invariants:
    invariant_timecourse_rows = calculate_invariant_timecourse(invariant,
                                                               timecourse)
    print(invariant_timecourse_rows) 
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()
def run():
    """Perform the banalities of command-line argument processing
     and then actually do the main work """
    description = "Analyse SBML files for invariants"
    parser = argparse.ArgumentParser(description=description)
    # Might want to make the type of this 'FileType('r')'
    parser.add_argument("filenames", metavar="F", nargs="+", help="an sbml file to check invariants for")
    parser.add_argument("--pretty", action="store_true", help="Pretty print the xml")
    parser.add_argument("--column", action=utils.ListArgumentAction, help="Specify a column to be interpreted")
    parser.add_argument("--mcolumn", action=utils.ListArgumentAction, help="Specify a column not to be interpreted")

    arguments = parser.parse_args()

    sbml_files = [x for x in arguments.filenames if utils.has_xml_or_sbml_ext(x)]
    copasi_files = [x for x in arguments.filenames if utils.has_copasi_ext(x)]
    timecourse_files = [x for x in arguments.filenames if not x in sbml_files and not x in copasi_files]

    events = []
    species = []
    for filename in timecourse_files:
        timecourse = timeseries.get_timecourse_from_file(filename)
        species.extend(timecourse.get_column_names())
        these_events = events_from_timecourse(timecourse, arguments)
        events.extend(these_events)

    if not events:
        print("No events to add, doing nothing:")
        sys.exit(1)

    if not sbml_files and not copasi_files:
        for event in events:
            print(event.format_event())
    else:
        for filename in sbml_files:
            add_events_sbml(filename, events, species, arguments)
        for filename in copasi_files:
            add_events_copasi(filename, events, arguments)
Example #6
0
def get_gold_standard_timeseries(filename):
  """Open the gold standard file and parse in as a comma-separated value
     file. Obtaining a time series which is returned"""
  return timeseries.get_timecourse_from_file(filename)