def main(): option_parser, opts, args = parse_command_line_parameters(**script_info) #Check the version of Matplotlib matplotlib_version = re.split("[^\d]", matplotlib.__version__) matplotlib_version_info = tuple([int(i) for i in matplotlib_version if \ i.isdigit()]) if matplotlib_version_info != (1,1,0): print "This code was only tested with Matplotlib-1.1.0" #get QIIME directory qiime_dir=get_qiime_project_dir() if not opts.counts_fname: option_parser.error("A list of input files must be specified") #get color preferences color_prefs, color_data, background_color, label_color= \ taxonomy_color_prefs_and_map_data_from_options(opts) colorby = opts.colorby if colorby==None: colorby=[] for c in color_data['counts'].values(): colorby.extend(c[0]) else: colorby=colorby.strip().strip("'").split(',') counts_fname = opts.counts_fname #Define labels to use labels = opts.labels if not opts.labels: new_labels=[] #create an empty list since the user didn't specify labels for i in counts_fname: new_labels.append("") labels=','.join(new_labels) data = [(label,f.strip()) \ for f,label in zip(counts_fname,labels.split(","))] filepath=data[0][1] filename=filepath.strip().rpartition('/')[0] num_categories = int(opts.num_categories) if num_categories<=0: raise ValueError, 'The number of categories has to be greater than 0!' #create directory path dir_path = os.getcwd() if opts.dir_path: dir_path = opts.dir_path try: create_dir(opts.dir_path) except OSError: pass #make javascript output directory javascript_path = os.path.join(dir_path,'js') try: create_dir(javascript_path) except OSError: #raised if dir exists pass #make raw_data output directory raw_data_path = os.path.join(dir_path,'raw_data') try: create_dir(raw_data_path) except OSError: #raised if dir exists pass # move javascript file to javascript output directory shutil.copyfile(os.path.join(qiime_dir,'qiime','support_files',\ 'js/overlib.js'),\ os.path.join(javascript_path,'overlib.js')) #make css output directory css_path = os.path.join(dir_path,'css') try: create_dir(css_path) except OSError: #raised if dir exists pass # move css file to css output directory shutil.copyfile(os.path.join(qiime_dir,'qiime','support_files',\ 'css/qiime_style.css'),\ os.path.join(css_path,'qiime_style.css')) # verify all parameters are valid plot_width=float(opts.x_width) if plot_width<=0: raise ValueError, 'The width of the plot has to be greater than 0!' plot_height=float(opts.y_height) if plot_height<=0: raise ValueError, 'The height of the plot has to be greater than 0!' bar_width=float(opts.bar_width) if bar_width<=0 or bar_width>1: raise ValueError, 'The bar width of the plot has to be between 0 and 1!' dpi=float(opts.dpi) if dpi<=0: raise ValueError, 'The dpi of the plot has to be greater than 0!' resize_nth_label=int(opts.resize_nth_label) if resize_nth_label<0: raise ValueError, 'The resize_nth_label of the plot has to be greater than 0!' generate_image_type=opts.type_of_file label_type=opts.label_type include_html_legend=opts.include_html_legend include_html_counts=opts.include_html_counts plots_to_make=opts.chart_type.split(',') chart_types=['area','pie','bar'] for i in plots_to_make: chart_type=i.lower().strip() if chart_type not in chart_types: raise ValueError, 'Please type in one of the appropriate chart types (i.e. %s)!' % ','.join(chart_types) #make pie chart output path charts_path = os.path.join(dir_path,'charts') try: create_dir(charts_path) except OSError: #raised if dir exists pass make_all_charts(data,dir_path,filename,num_categories, \ colorby,args,color_data, color_prefs,background_color,label_color,\ chart_type,generate_image_type,plot_width,plot_height,bar_width,dpi,\ resize_nth_label,label_type,include_html_legend,include_html_counts)
def main(): option_parser, opts, args = parse_command_line_parameters(**script_info) #get QIIME directory qiime_dir=get_qiime_project_dir() if not opts.counts_fname: option_parser.error("A list of input files must be specified") #get color preferences color_prefs, color_data, background_color, label_color= \ taxonomy_color_prefs_and_map_data_from_options(opts) colorby = opts.colorby if colorby==None: colorby=[] for c in color_data['counts'].values(): colorby.extend(c[0]) else: colorby=colorby.strip().strip("'").split(',') counts_fname = opts.counts_fname #Define labels to use labels = opts.labels if not opts.labels: new_labels=[] #create an empty list since the user didn't specify labels for i in counts_fname: new_labels.append("") labels=','.join(new_labels) data = [(label,f.strip()) \ for f,label in zip(counts_fname,labels.split(","))] filepath=data[0][1] filename=filepath.strip().rpartition('/')[0] num_categories = int(opts.num_categories) if num_categories<=0: raise ValueError, 'The number of categories has to be greater than 0!' #create directory path dir_path = os.getcwd() if opts.dir_path: dir_path = opts.dir_path try: create_dir(opts.dir_path) except OSError: pass #make javascript output directory javascript_path = os.path.join(dir_path,'js') try: create_dir(javascript_path) except OSError: #raised if dir exists pass #make raw_data output directory raw_data_path = os.path.join(dir_path,'raw_data') try: create_dir(raw_data_path) except OSError: #raised if dir exists pass # move javascript file to javascript output directory shutil.copyfile(os.path.join(qiime_dir,'qiime','support_files',\ 'js/overlib.js'),\ os.path.join(javascript_path,'overlib.js')) #make css output directory css_path = os.path.join(dir_path,'css') try: create_dir(css_path) except OSError: #raised if dir exists pass # move css file to css output directory shutil.copyfile(os.path.join(qiime_dir,'qiime','support_files',\ 'css/qiime_style.css'),\ os.path.join(css_path,'qiime_style.css')) # verify all parameters are valid plot_width=float(opts.x_width) if plot_width<=0: raise ValueError, 'The width of the plot has to be greater than 0!' plot_height=float(opts.y_height) if plot_height<=0: raise ValueError, 'The height of the plot has to be greater than 0!' bar_width=float(opts.bar_width) if bar_width<=0 or bar_width>1: raise ValueError, 'The bar width of the plot has to be between 0 and 1!' dpi=float(opts.dpi) if dpi<=0: raise ValueError, 'The dpi of the plot has to be greater than 0!' resize_nth_label=int(opts.resize_nth_label) if resize_nth_label<0: raise ValueError, 'The resize_nth_label of the plot has to be greater\ than 0!' generate_image_type=opts.type_of_file label_type=opts.label_type include_html_legend=opts.include_html_legend include_html_counts=opts.include_html_counts plots_to_make=opts.chart_type for chart_type in plots_to_make: #make pie chart output path charts_path = os.path.join(dir_path,'charts') try: create_dir(charts_path) except OSError: #raised if dir exists pass make_all_charts(data,dir_path,filename,num_categories, \ colorby,args,color_data, color_prefs,background_color,label_color,\ chart_type,generate_image_type,plot_width,plot_height,bar_width,dpi,\ resize_nth_label,label_type,include_html_legend,include_html_counts)
def main(): option_parser, opts, args = parse_command_line_parameters(**script_info) # get QIIME directory qiime_dir = get_qiime_project_dir() if not opts.counts_fname: option_parser.error("A list of input files must be specified") # get color preferences color_prefs, color_data, background_color, label_color = taxonomy_color_prefs_and_map_data_from_options(opts) colorby = opts.colorby if colorby == None: colorby = [] for c in color_data["counts"].values(): colorby.extend(c[0]) else: colorby = colorby.strip().strip("'").split(",") counts_fname = opts.counts_fname # Define labels to use labels = opts.labels if not opts.labels: new_labels = [] # create an empty list since the user didn't specify labels for i in counts_fname: new_labels.append("") labels = ",".join(new_labels) data = [(label, f.strip()) for f, label in zip(counts_fname, labels.split(","))] filepath = data[0][1] filename = filepath.strip().rpartition("/")[0] num_categories = int(opts.num_categories) if num_categories <= 0: raise ValueError, "The number of categories has to be greater than 0!" # create directory path dir_path = os.getcwd() if opts.dir_path: dir_path = opts.dir_path try: create_dir(opts.dir_path) except OSError: pass # make javascript output directory javascript_path = os.path.join(dir_path, "js") try: create_dir(javascript_path) except OSError: # raised if dir exists pass # make raw_data output directory raw_data_path = os.path.join(dir_path, "raw_data") try: create_dir(raw_data_path) except OSError: # raised if dir exists pass # move javascript file to javascript output directory shutil.copyfile( os.path.join(qiime_dir, "qiime", "support_files", "js/overlib.js"), os.path.join(javascript_path, "overlib.js") ) # make css output directory css_path = os.path.join(dir_path, "css") try: create_dir(css_path) except OSError: # raised if dir exists pass # move css file to css output directory shutil.copyfile( os.path.join(qiime_dir, "qiime", "support_files", "css/qiime_style.css"), os.path.join(css_path, "qiime_style.css"), ) # verify all parameters are valid plot_width = float(opts.x_width) if plot_width <= 0: raise ValueError, "The width of the plot has to be greater than 0!" plot_height = float(opts.y_height) if plot_height <= 0: raise ValueError, "The height of the plot has to be greater than 0!" bar_width = float(opts.bar_width) if bar_width <= 0 or bar_width > 1: raise ValueError, "The bar width of the plot has to be between 0 and 1!" dpi = float(opts.dpi) if dpi <= 0: raise ValueError, "The dpi of the plot has to be greater than 0!" resize_nth_label = int(opts.resize_nth_label) if resize_nth_label < 0: raise ValueError, "The resize_nth_label of the plot has to be greater\ than 0!" generate_image_type = opts.type_of_file label_type = opts.label_type include_html_legend = opts.include_html_legend include_html_counts = opts.include_html_counts plots_to_make = opts.chart_type for chart_type in plots_to_make: # make pie chart output path charts_path = os.path.join(dir_path, "charts") try: create_dir(charts_path) except OSError: # raised if dir exists pass make_all_charts( data, dir_path, filename, num_categories, colorby, args, color_data, color_prefs, background_color, label_color, chart_type, generate_image_type, plot_width, plot_height, bar_width, dpi, resize_nth_label, label_type, include_html_legend, include_html_counts, )