def test_plot_rank_abundance_graphs_dense(self): """plot_rank_abundance_graphs works with any number of samples (DenseOTUTable)""" self.otu_table = parse_biom_table_str(otu_table_dense) self.dir = get_tmp_filename(tmp_dir=self.tmp_dir, prefix="test_plot_rank_abundance", suffix="/") create_dir(self.dir) self._dirs_to_remove.append(self.dir) #test empty sample name self.assertRaises(ValueError, plot_rank_abundance_graphs, '', self.otu_table, self.dir) #test invalid sample name self.assertRaises(ValueError, plot_rank_abundance_graphs, 'Invalid_sample_name', self.otu_table, self.dir) #test with two samples file_type="pdf" plot_rank_abundance_graphs('S3,S5', self.otu_table, self.dir, file_type=file_type) tmp_file = abspath(self.dir+"rank_abundance_cols_0_2."+file_type) self.assertTrue(exists(tmp_file)) self.files_to_remove.append(tmp_file) # test with all samples plot_rank_abundance_graphs('*', self.otu_table, self.dir, file_type=file_type) tmp_file = abspath(self.dir+"rank_abundance_cols_0_1_2."+file_type) self.files_to_remove.append(tmp_file) self.assertTrue(exists(tmp_file))
def test_plot_rank_abundance_graphs_dense(self): """plot_rank_abundance_graphs works with any number of samples (DenseOTUTable)""" self.otu_table = parse_biom_table_str(otu_table_dense) self.dir = get_tmp_filename(tmp_dir=self.tmp_dir, prefix="test_plot_rank_abundance", suffix="/") create_dir(self.dir) self._dirs_to_remove.append(self.dir) tmp_fname = get_tmp_filename(tmp_dir=self.dir) #test empty sample name self.assertRaises(ValueError, plot_rank_abundance_graphs, tmp_fname,'', self.otu_table) #test invalid sample name self.assertRaises(ValueError, plot_rank_abundance_graphs, tmp_fname, 'Invalid_sample_name', self.otu_table) #test with two samples file_type="pdf" tmp_file = abspath(self.dir+"rank_abundance_cols_0_2."+file_type) plot_rank_abundance_graphs(tmp_file, 'S3,S5', self.otu_table, file_type=file_type) self.assertTrue(exists(tmp_file)) self.files_to_remove.append(tmp_file) # test with all samples tmp_file = abspath(self.dir+"rank_abundance_cols_0_1_2."+file_type) plot_rank_abundance_graphs(tmp_file,'*', self.otu_table,file_type=file_type) self.files_to_remove.append(tmp_file) self.assertTrue(exists(tmp_file))
def test_plot_rank_abundance_graphs(self): """plot_rank_abundance_graphs works with any number of samples""" self.otu_table = otu_table_fake.split("\n") self.dir = get_tmp_filename(tmp_dir=self.tmp_dir, prefix="test_plot_rank_abundance", suffix="/") create_dir(self.dir) self._dirs_to_remove.append(self.dir) # test empty sample name self.assertRaises(ValueError, plot_rank_abundance_graphs, "", iter(self.otu_table), self.dir) # test invalid sample name self.assertRaises(ValueError, plot_rank_abundance_graphs, "Invalid_sample_name", iter(self.otu_table), self.dir) # test with two samples file_type = "pdf" plot_rank_abundance_graphs("S3,S5", iter(self.otu_table), self.dir, file_type=file_type) tmp_file = abspath(self.dir + "rank_abundance_cols_0_2." + file_type) self.assertTrue(exists(tmp_file)) self.files_to_remove.append(tmp_file) # test with all samples plot_rank_abundance_graphs("*", iter(self.otu_table), self.dir, file_type=file_type) tmp_file = abspath(self.dir + "rank_abundance_cols_0_1_2." + file_type) self.files_to_remove.append(tmp_file) self.assertTrue(exists(tmp_file))
def test_plot_rank_abundance_graphs_filetype(self): """plot_rank_abundance_graphs works with all filetypes""" self.otu_table = otu_table_fake.split("\n") self.dir = get_tmp_filename(tmp_dir=self.tmp_dir, prefix="test_plot_rank_abundance", suffix="/") create_dir(self.dir) self._dirs_to_remove.append(self.dir) # test all supported filetypes for file_type in ["pdf", "svg", "png", "eps"]: plot_rank_abundance_graphs("S3", iter(self.otu_table), self.dir, file_type=file_type) tmp_file = abspath(self.dir + "rank_abundance_cols_0." + file_type) self.files_to_remove.append(tmp_file) self.assertTrue(exists(tmp_file))
def main(): option_parser, opts, args = parse_command_line_parameters(**script_info) otu_table_fp = opts.otu_table_fp sample_name = opts.sample_name log_fn = opts.result_fp + "_log.txt" log_fh = open(log_fn, 'w') log_fh.write("OTU table file: %s\n" % otu_table_fp) log_fh.write("sample names: %s\n" % sample_name) otu_table = load_table(opts.otu_table_fp) plot_rank_abundance_graphs(opts.result_fp, opts.sample_name, otu_table, opts.file_type, opts.absolute_counts, opts.x_linear_scale, opts.y_linear_scale, opts.no_legend, log_fh)
def main(): option_parser, opts, args = parse_command_line_parameters(**script_info) otu_table_fp = opts.otu_table_fp sample_name = opts.sample_name log_fn = opts.result_fp + "_log.txt" log_fh = open(log_fn, 'w') log_fh.write("OTU table file: %s\n" % otu_table_fp) log_fh.write("sample names: %s\n" % sample_name) otu_table = load_table(opts.otu_table_fp) plot_rank_abundance_graphs(opts.result_fp, opts.sample_name, otu_table, opts.file_type, opts.absolute_counts, opts.x_linear_scale, opts.y_linear_scale, opts.no_legend, log_fh)
def test_plot_rank_abundance_graphs_filetype(self): """plot_rank_abundance_graphs works with all filetypes""" self.otu_table = parse_biom_table_str(otu_table_sparse) self.dir = get_tmp_filename(tmp_dir=self.tmp_dir, prefix="test_plot_rank_abundance", suffix="/") create_dir(self.dir) self._dirs_to_remove.append(self.dir) #test all supported filetypes for file_type in ['pdf','svg','png','eps']: plot_rank_abundance_graphs('S3', self.otu_table, self.dir, file_type=file_type) tmp_file = abspath(self.dir+"rank_abundance_cols_0."+file_type) self.files_to_remove.append(tmp_file) self.assertTrue(exists(tmp_file))
def test_plot_rank_abundance_graphs_filetype(self): """plot_rank_abundance_graphs works with all filetypes""" self.otu_table = parse_biom_table_str(otu_table_sparse) self.dir = get_tmp_filename(tmp_dir=self.tmp_dir, prefix="test_plot_rank_abundance", suffix="/") create_dir(self.dir) self._dirs_to_remove.append(self.dir) #test all supported filetypes for file_type in ['pdf','svg','png','eps']: tmp_file = abspath(self.dir+"rank_abundance_cols_0."+file_type) plot_rank_abundance_graphs(tmp_file,'S3', self.otu_table, file_type=file_type) self.files_to_remove.append(tmp_file) self.assertTrue(exists(tmp_file))
def main(): option_parser, opts, args =\ parse_command_line_parameters(**script_info) output_dir = opts.output_dir otu_table_fp = opts.otu_table_fp sample_name = opts.sample_name create_dir(output_dir) if opts.verbose: log_fh = open(output_dir+"/plot_rank_abundance_log.txt",'w') log_fh.write("OTU table file: %s\n"% otu_table_fp) log_fh.write("sample names: %s\n" % sample_name) else: log_fh=None otu_table = parse_biom_table(open(opts.otu_table_fp,"U")) plot_rank_abundance_graphs(opts.sample_name, otu_table, output_dir, opts.file_type, opts.absolute_counts, opts.x_linear_scale, opts.y_linear_scale, opts.no_legend, log_fh)
def main(): option_parser, opts, args =\ parse_command_line_parameters(**script_info) #set up and create the outpurt dir if opts.output_dir: output_dir = opts.output_dir else: output_dir = get_tmp_filename(tmp_dir='./', prefix='rank_abundance_', suffix='') create_dir(output_dir, fail_on_exist=True) if opts.verbose: log_fh = open(output_dir+"/plot_rank_abundance_log.txt",'w') log_fh.write("OTU table file: %s\n"% opts.otu_table_fp) log_fh.write("sample names: %s\n" % opts.sample_name) else: log_fh=None plot_rank_abundance_graphs(opts.sample_name, open(opts.otu_table_fp,"U"), output_dir, opts.file_type, opts.absolute_counts, opts.x_linear_scale, opts.y_linear_scale, opts.no_legend, log_fh)
def test_plot_rank_abundance_graphs(self): """plot_rank_abundance_graphs works with any number of samples (Table)""" self.otu_table = parse_biom_table(otu_table_sparse) self.dir = mkdtemp(dir=self.tmp_dir, prefix="test_plot_rank_abundance", suffix="/") self._dirs_to_remove.append(self.dir) fd, tmp_fname = mkstemp(dir=self.dir) close(fd) # test empty sample name self.assertRaises( ValueError, plot_rank_abundance_graphs, tmp_fname, '', self.otu_table) # test invalid sample name self.assertRaises(ValueError, plot_rank_abundance_graphs, tmp_fname, 'Invalid_sample_name', self.otu_table) # test with two samples file_type = "pdf" tmp_file = abspath(self.dir + "rank_abundance_cols_0_2." + file_type) plot_rank_abundance_graphs(tmp_file, 'S3,S5', self.otu_table, file_type=file_type) self.assertTrue(exists(tmp_file)) self.files_to_remove.append(tmp_file) # test with all samples tmp_file = abspath(self.dir + "rank_abundance_cols_0_1_2." + file_type) plot_rank_abundance_graphs(tmp_file, '*', self.otu_table, file_type=file_type) self.files_to_remove.append(tmp_file) self.assertTrue(exists(tmp_file))