def main(): option_parser, opts, args = parse_command_line_parameters(**script_info) if opts.show_metrics: print("Known metrics are: %s\n" % (', '.join(list_known_cup_metrics()), )) exit(0) almost_required_options = ['input_path', 'output_path'] for option in almost_required_options: if getattr(opts, option) is None: option_parser.error('Required option --%s omitted.' % option) if os.path.isfile(opts.input_path): try: f = open(opts.output_path, 'w') except IOError: exit("ioerror, couldn't create output file") f.close() single_file_cup(opts.input_path, opts.metrics, opts.output_path, opts.look_ahead) else: exit("io error, input path not valid. does it exist?")
def test_single_file_cup_string(self): """Returns matrix with estimates using metrics string.""" # convert_biom using otu_table w/o leading # bt_string = ( '{"rows": [{"id": "1", "metadata": null}, {"id": "2",' '"metadata": null}, {"id": "3", "metadata": null}, {"id": "4", ' '"metadata": null}, {"id": "5", "metadata": null}], "format": ' '"Biological Observation Matrix 0.9.1-dev", "data": [[0, 0, 3.0], ' '[0, 1, 4.0], [1, 0, 2.0], [1, 1, 5.0], [2, 0, 1.0], [2, 1, 2.0], ' '[3, 1, 4.0], [4, 0, 1.0]], "columns": [{"id": "S1", "metadata": ' 'null}, {"id": "S2", "metadata": null}], "generated_by": ' '"BIOM-Format 0.9.1-dev", "matrix_type": "sparse", "shape": ' '[5, 2], "format_url": "http://biom-format.org", "date": ' '"2012-05-04T09:28:28.247809", "type": "OTU table", "id": null, ' '"matrix_element_type": "float"}') with open(self.tmp_file, 'w') as fh: fh.write(bt_string) single_file_cup(self.tmp_file, 'lladser_pe,lladser_ci', self.tmp_outfile, r=4) # Not much testing here, just make sure we get back a (formatted) # matrix with the right dimensions with open(self.tmp_outfile, 'U') as out_f: observed = out_f.readlines() self.assertEqual(len(observed), 3) self.assertEqual(len(observed[1].split('\t')), 4)
def test_single_file_cup_list(self): """Returns matrix with estimates using metrics list.""" # convert_biom using otu_table w/o leading # bt_string = ( '{"rows": [{"id": "1", "metadata": null}], "format": "Biological ' 'Observation Matrix 0.9.1-dev", "data": [[0, 0, 3.0]], "columns": ' '[{"id": "S1", "metadata": null}], "generated_by": ' '"BIOM-Format 0.9.1-dev", "matrix_type": "sparse", "shape": ' '[1, 1], "format_url": "http://biom-format.org", "date": ' '"2012-05-04T09:36:57.500673", "type": "OTU table", "id": null, ' '"matrix_element_type": "float"}') with open(self.tmp_file, 'w') as fh: fh.write(bt_string) single_file_cup(self.tmp_file, ['lladser_pe', 'lladser_ci'], self.tmp_outfile, r=4) with open(self.tmp_outfile, 'U') as out_f: observed = out_f.readlines() expected = [ "\tlladser_pe\tlladser_lower_bound\tlladser_upper_bound\n", "S1\tnan\tnan\tnan\n" ] self.assertEqual(observed, expected)
def test_single_file_cup_list(self): """Returns matrix with estimates using metrics list.""" # convert_biom using otu_table w/o leading # bt_string = ( '{"rows": [{"id": "1", "metadata": null}], "format": "Biological ' 'Observation Matrix 0.9.1-dev", "data": [[0, 0, 3.0]], "columns": ' '[{"id": "S1", "metadata": null}], "generated_by": ' '"BIOM-Format 0.9.1-dev", "matrix_type": "sparse", "shape": ' '[1, 1], "format_url": "http://biom-format.org", "date": ' '"2012-05-04T09:36:57.500673", "type": "OTU table", "id": null, ' '"matrix_element_type": "float"}') with open(self.tmp_file, 'w') as fh: fh.write(bt_string) single_file_cup(self.tmp_file, ['lladser_pe', 'lladser_ci'], self.tmp_outfile, r=4, alpha=0.95, f=10, ci_type="ULCL") with open(self.tmp_outfile, 'U') as out_f: observed = out_f.readlines() expected = ["\tlladser_pe\tlladser_lower_bound\tlladser_upper_bound\n", "S1\tNaN\tNaN\tNaN"] self.assertEqual(observed, expected)
def main(): option_parser, opts, args = parse_command_line_parameters(**script_info) if opts.show_metrics: print("Known metrics are: %s\n" \ % (', '.join(list_known_cup_metrics()),)) exit(0) almost_required_options = ['input_path', 'output_path'] for option in almost_required_options: if getattr(opts,option) == None: option_parser.error('Required option --%s omitted.' % option) if os.path.isfile(opts.input_path): try: f = open(opts.output_path, 'w') except IOError: exit("ioerror, couldn't create output file") f.close() single_file_cup(opts.input_path, opts.metrics, opts.output_path, opts.look_ahead, opts.alpha, opts.f_ratio, opts.ci_type) else: exit("io error, input path not valid. does it exist?")
def test_single_file_cup(self): """single_file_cup returns matrix with estimates""" # Test using a string as metrics # convert_biom using otu_table w/o leading # bt_string = '{"rows": [{"id": "1", "metadata": null}, {"id": "2",\ "metadata": null}, {"id": "3", "metadata": null}, {"id": "4", "metadata":\ null}, {"id": "5", "metadata": null}], "format": "Biological Observation\ Matrix 0.9.1-dev", "data": [[0, 0, 3.0], [0, 1, 4.0], [1, 0, 2.0],\ [1, 1, 5.0], [2, 0, 1.0], [2, 1, 2.0], [3, 1, 4.0], [4, 0, 1.0]], "columns":\ [{"id": "S1", "metadata": null}, {"id": "S2", "metadata": null}],\ "generated_by": "BIOM-Format 0.9.1-dev", "matrix_type": "sparse", "shape":\ [5, 2], "format_url": "http://biom-format.org", "date":\ "2012-05-04T09:28:28.247809", "type": "OTU table", "id": null,\ "matrix_element_type": "float"}' fh = open(self.tmp_file, "w") fh.write(bt_string) fh.close() self.files_to_remove.append(self.tmp_file) self.files_to_remove.append(self.tmp_outfile) # Not much testing here, just make sure we get back a (formatted) # matrix with the right dimensions single_file_cup(self.tmp_file, 'lladser_pe,lladser_ci', self.tmp_outfile, r=4, alpha=0.95, f=10, ci_type="ULCL") observed = open(self.tmp_outfile, "U").readlines() self.assertEqual(len(observed), 3) self.assertEqual(len(observed[1].split('\t')), 4) # Test using a list as metrics # convert_biom using otu_table w/o leading # bt_string = '{"rows": [{"id": "1", "metadata": null}], "format":\ "Biological Observation Matrix 0.9.1-dev", "data": [[0, 0, 3.0]], "columns":\ [{"id": "S1", "metadata": null}], "generated_by": "BIOM-Format 0.9.1-dev",\ "matrix_type": "sparse", "shape": [1, 1], "format_url":\ "http://biom-format.org", "date": "2012-05-04T09:36:57.500673", "type":\ "OTU table", "id": null, "matrix_element_type": "float"}' fh = open(self.tmp_file, "w") fh.write(bt_string) fh.close() single_file_cup(self.tmp_file, ['lladser_pe', 'lladser_ci'], self.tmp_outfile, r=4, alpha=0.95, f=10, ci_type="ULCL") observed = open(self.tmp_outfile, "U").readlines() expected = [ "\tlladser_pe\tlladser_lower_bound\tlladser_upper_bound\n", "S1\tNaN\tNaN\tNaN" ] self.assertEqual(observed, expected)
def test_single_file_cup(self): """single_file_cup returns matrix with estimates""" # Test using a string as metrics # convert_biom using otu_table w/o leading # bt_string = '{"rows": [{"id": "1", "metadata": null}, {"id": "2",\ "metadata": null}, {"id": "3", "metadata": null}, {"id": "4", "metadata":\ null}, {"id": "5", "metadata": null}], "format": "Biological Observation\ Matrix 0.9.1-dev", "data": [[0, 0, 3.0], [0, 1, 4.0], [1, 0, 2.0],\ [1, 1, 5.0], [2, 0, 1.0], [2, 1, 2.0], [3, 1, 4.0], [4, 0, 1.0]], "columns":\ [{"id": "S1", "metadata": null}, {"id": "S2", "metadata": null}],\ "generated_by": "BIOM-Format 0.9.1-dev", "matrix_type": "sparse", "shape":\ [5, 2], "format_url": "http://biom-format.org", "date":\ "2012-05-04T09:28:28.247809", "type": "OTU table", "id": null,\ "matrix_element_type": "float"}' fh = open(self.tmp_file,"w") fh.write(bt_string) fh.close() self.files_to_remove.append(self.tmp_file) self.files_to_remove.append(self.tmp_outfile) # Not much testing here, just make sure we get back a (formatted) # matrix with the right dimensions single_file_cup(self.tmp_file, 'lladser_pe,lladser_ci', self.tmp_outfile, r=4, alpha=0.95, f=10, ci_type="ULCL") observed = open(self.tmp_outfile,"U").readlines() self.assertEqual(len(observed), 3) self.assertEqual(len(observed[1].split('\t')), 4) # Test using a list as metrics # convert_biom using otu_table w/o leading # bt_string = '{"rows": [{"id": "1", "metadata": null}], "format":\ "Biological Observation Matrix 0.9.1-dev", "data": [[0, 0, 3.0]], "columns":\ [{"id": "S1", "metadata": null}], "generated_by": "BIOM-Format 0.9.1-dev",\ "matrix_type": "sparse", "shape": [1, 1], "format_url":\ "http://biom-format.org", "date": "2012-05-04T09:36:57.500673", "type":\ "OTU table", "id": null, "matrix_element_type": "float"}' fh = open(self.tmp_file,"w") fh.write(bt_string) fh.close() single_file_cup(self.tmp_file, ['lladser_pe','lladser_ci'], self.tmp_outfile, r=4, alpha=0.95, f=10, ci_type="ULCL") observed = open(self.tmp_outfile,"U").readlines() expected=["\tlladser_pe\tlladser_lower_bound\tlladser_upper_bound\n", "S1\tNaN\tNaN\tNaN"] self.assertEqual(observed, expected)
def main(): option_parser, opts, args = parse_command_line_parameters(**script_info) if opts.show_metrics: print("Known metrics are: %s\n" % (", ".join(list_known_cup_metrics()),)) exit(0) almost_required_options = ["input_path", "output_path"] for option in almost_required_options: if getattr(opts, option) is None: option_parser.error("Required option --%s omitted." % option) if os.path.isfile(opts.input_path): try: f = open(opts.output_path, "w") except IOError: exit("ioerror, couldn't create output file") f.close() single_file_cup(opts.input_path, opts.metrics, opts.output_path, opts.look_ahead) else: exit("io error, input path not valid. does it exist?")