def test_make_averages(self): '''make_averages: this tests the main function in make_rarefaction_plots and returns an html output''' filename1='/tmp/html_plots/testcol_0_row_0_ave.png' folder1='/tmp/html_plots' filename3='/tmp/average_tables/testSampleID.txt' folder2='/tmp/average_tables' filename4='/tmp/average_plots/testSampleID.png' folder3='/tmp/average_plots' self._paths_to_clean_up = [filename1,filename3,filename4] self._folders_to_cleanup = [folder1,folder2,folder3] obs=make_averages(self.color_prefs,self.data,self.background_color, \ self.label_color,self.rares,self.output_dir, \ self.resolution,self.imagetype,None,False, \ self.std_type) self.assertEqual(obs,exp_html) self.assertTrue(exists(filename1)) self.assertTrue(exists(filename3)) self.assertTrue(exists(filename4)) self.assertTrue(exists(folder1)) self.assertTrue(exists(folder2)) self.assertTrue(exists(folder3))
def test_make_averages(self): '''make_averages: this tests the main function in make_rarefaction_plots and returns an html output''' filename1 = '/tmp/html_plots/testcol_0_row_0_ave.png' folder1 = '/tmp/html_plots' filename3 = '/tmp/average_tables/testSampleID.txt' folder2 = '/tmp/average_tables' filename4 = '/tmp/average_plots/testSampleID.png' folder3 = '/tmp/average_plots' self._paths_to_clean_up = [filename1, filename3, filename4] self._folders_to_cleanup = [folder1, folder2, folder3] obs=make_averages(self.color_prefs,self.data,self.background_color, \ self.label_color,self.rares,self.output_dir, \ self.resolution,self.imagetype,None,False, \ self.std_type) self.assertEqual(obs, exp_html) self.assertTrue(exists(filename1)) self.assertTrue(exists(filename3)) self.assertTrue(exists(filename4)) self.assertTrue(exists(folder1)) self.assertTrue(exists(folder2)) self.assertTrue(exists(folder3))
def main(): option_parser, opts, args = parse_command_line_parameters(**script_info) input_dir = opts.input_dir imagetype = opts.imagetype resolution = opts.resolution output_dir = opts.output_dir ymax = opts.ymax std_type = opts.std_type suppress_webpage = opts.suppress_html_output output_type = opts.output_type generate_per_sample_plots = opts.generate_per_sample_plots generate_average_tables = opts.generate_average_tables # Get the command-line options. prefs, data, background_color, label_color, ball_scale, arrow_colors = \ sample_color_prefs_and_map_data_from_options(opts) rares = {} if isdir(input_dir): rarenames = listdir(input_dir) rarenames = [r for r in rarenames if not r.startswith('.')] for r in rarenames: try: rarefl = open(path.join(input_dir, r), 'U').readlines() rares[r] = parse_rarefaction(rarefl) except(IOError): option_parser.error('Problem with rarefaction file. %s' % exc_info()[1]) exit(0) else: try: input_file = input_dir.split(',') for i in range(len(input_file)): input_path = split(input_file[i])[-1] rarefl = open(input_file[i], 'U').readlines() rares[input_path] = parse_rarefaction(rarefl) except(IOError): option_parser.error('Problem with rarefaction file. %s' % exc_info()[1]) exit(0) if imagetype not in ['png', 'svg', 'pdf']: option_parser.error('Supplied extension not supported.') exit(0) try: resolution = int(resolution) except(ValueError): option_parser.error('Inavlid resolution.') exit(0) # output directory check if isinstance(output_dir, str) and output_dir != '.': if exists(output_dir): output_dir = output_dir else: try: create_dir(output_dir, False) output_dir = output_dir except(ValueError): option_parser.error('Could not create output directory.') exit(0) else: output_dir = get_random_directory_name() # Generate the plots and html text html_output = make_averages(prefs, data, background_color, label_color, rares, output_dir, resolution, imagetype, ymax, suppress_webpage, std_type, output_type, generate_per_sample_plots=generate_per_sample_plots, generate_average_tables=generate_average_tables) if html_output: # Write the html file. outfile = open(path.join(output_dir, 'rarefaction_plots.html'), 'w') outfile.write(html_output) outfile.close()
def main(): option_parser, options, args = parse_command_line_parameters(**script_info) ops = {} input_dir = options.input_dir rares = {} if isdir(input_dir): rarenames = listdir(input_dir) rarenames = [r for r in rarenames if not r.startswith(".")] for r in rarenames: try: rarefl = open(path.join(input_dir, r), "U").readlines() rares[r] = parse_rarefaction(rarefl) except (IOError): option_parser.error("Problem with rarefaction file. %s" % exc_info()[1]) exit(0) else: try: input_file = input_dir.split(",") for i in range(len(input_file)): input_path = split(input_file[i])[-1] rarefl = open(input_file[i], "U").readlines() rares[input_path] = parse_rarefaction(rarefl) except (IOError): option_parser.error("Problem with rarefaction file. %s" % exc_info()[1]) exit(0) if options.imagetype not in ["png", "svg", "pdf"]: option_parser.error("Supplied extension not supported.") exit(0) else: imagetype = options.imagetype try: resolution = int(options.resolution) except (ValueError): option_parser.error("Inavlid resolution.") exit(0) # Get the command-line options. prefs, data, background_color, label_color, ball_scale, arrow_colors = sample_color_prefs_and_map_data_from_options( options ) # output directory check if isinstance(options.output_dir, str) and options.output_dir != ".": if exists(options.output_dir): output_dir = options.output_dir else: try: create_dir(options.output_dir, False) output_dir = options.output_dir except (ValueError): option_parser.error("Could not create output directory.") exit(0) else: output_dir = get_random_directory_name() # Generate the plots and html text ymax = options.ymax suppress_webpage = options.suppress_html_output html_output = make_averages( prefs, data, background_color, label_color, rares, output_dir, resolution, imagetype, ymax, suppress_webpage ) if html_output: # Write the html file. outfile = open(path.join(output_dir, "rarefaction_plots.html"), "w") outfile.write(html_output) outfile.close()