def plotHeatmap(data, ax, cmap=False, xlbls=True, ylbls=True): """ This function creates and plots a heatmap or a hcheatmap (hiearchical cluster heat map) :Arguments: :type data: pandas data frame. :param data: Data that is going to be used to plot :type ax: matplotlib axis :param ax: axis to be drawn on. :Returns: :return ax: matplotlib axis. :rtype ax: axis with the drawn figure. """ # Create a custom colormap for the heatmap values # You can have two possible ways to create a pallete. # 1) sns.diverging_palette (a seaborn function) # 2) palettable.colorbrewer.diverging.[color].mpl_colors if not cmap: colors = colorHandler(pal="diverging", col="Spectral_10") cmap = colors.mpl_colormap # Draw the full plot sns.heatmap(data, linewidths=0.0, ax=ax, cmap=cmap, xticklabels=xlbls, yticklabels=ylbls)
def _artVenn2(venn, innerLabels): """ Modifies the colors, text and alpha for the 2 cicles venn plot. :Arguments: :type data: matplotlib.figure :param data: Figure with the venn diagram :type innerLabels: list :param innerLabels: List of the labels to be printed inside the circles [Ab,AB,aB] """ # Subset innerLabels venn.get_label_by_id('10').set_text(innerLabels[0]) venn.get_label_by_id('01').set_text(innerLabels[1]) venn.get_label_by_id('11').set_text(innerLabels[2]) #Selecting colours from colour manager palette = colorHandler(pal="tableau", col="BlueRed_6") # Subset colors venn.get_patch_by_id('10').set_color(palette.mpl_colors[3]) venn.get_patch_by_id('01').set_color(palette.mpl_colors[4]) venn.get_patch_by_id('11').set_color(palette.mpl_colors[5]) # Subset alphas venn.get_patch_by_id('10').set_alpha(1.0) venn.get_patch_by_id('01').set_alpha(1.0) venn.get_patch_by_id('11').set_alpha(1.0)
def main(args): """ Main Script """ #Getting palettes for data and cutoffs global cutPalette cutPalette = ch.colorHandler(pal="tableau", col="TrafficLight_9") # Checking if levels if args.levels and args.group: levels = [args.group] + args.levels elif args.group and not args.levels: levels = [args.group] else: levels = [] #Parsing data with interface dat = wideToDesign(args.input, args.design, args.uniqID, group=args.group, anno=args.levels, logger=logger, runOrder=args.order) #Dropping missing values and remove groups with just one sample dat.dropMissing() if args.group: dat.removeSingle() #Select colors for data dataPalette.getColors(design=dat.design, groups=levels) dat.design = dataPalette.design #Open pdfPages Calculate SED with PdfPages(os.path.abspath(args.figure)) as pdf: SEDtoMean, SEDpairwise = calculateSED(dat, dataPalette.ugColors, dataPalette.combName, pdf, args.p) #Outputing files for tsv files SEDtoMean.to_csv(os.path.abspath(args.toMean), index_label="sampleID", columns=["SED_to_Mean"], sep='\t') SEDpairwise.drop(["colors"], axis=1, inplace=True) if args.group: SEDpairwise.drop(["colors_x", "colors_y"], axis=1, inplace=True) SEDpairwise.to_csv(os.path.abspath(args.pairwise), index_label="sampleID", sep='\t') #Ending script logger.info("Script complete.")
def plotHCHeatmap(data, hcheatmap=True, cmap=False, xlbls=True, ylbls=True): """ This function creates and plots a heatmap or a hcheatmap (hiearchical cluster heat map) :Arguments: :type data: pandas data frame. :param data: Data that is going to be used to plot :type hcheatmap: boolean :param hcheatmap: boolean to determinate wether you want to plot a normal heatmap or a hcheatmap. :Returns: :return hmap: Instance of the heatmap :rtype hmap: seaborn.matrix.ClusterGrid """ # Create a custom colormap for the heatmap values # You can have two possible ways to create a pallete. # 1) sns.diverging_palette (a seaborn function) # 2) palettable.colorbrewer.diverging.[color].mpl_colors if not cmap: colors = colorHandler(pal="diverging", col="Spectral_10") cmap = colors.mpl_colormap # Draw the full plot hmap = sns.clustermap(data, row_cluster=hcheatmap, col_cluster=hcheatmap, linewidths=0.0, figsize=(13, 13), cmap=cmap, xticklabels=xlbls, yticklabels=ylbls) #Rotate axis plt.setp(hmap.ax_heatmap.yaxis.get_majorticklabels(), rotation=0) plt.setp(hmap.ax_heatmap.xaxis.get_majorticklabels(), rotation=90) #Return Plot return hmap
# Iterating over groups for name, group in dat.design.groupby(args.group): logger.info(u"Plotting for group {0}".format(name)) # Plotting Density and Box plot for the group plotDensity(data=wide.T[group.index], name=name, pdf=pdf) # Get colors for each feature for "All groups" logger.info(u"Plotting for group {0}".format("samples")) palette.getColors(design=dat.design, groups=[]) # Plotting density and boxplots for all plotDensity(data=wide, name="samples", pdf=pdf) #Ending script logger.info(u"Ending script") if __name__ == '__main__': args = getOptions() logger = logging.getLogger() sl.setLogger(logger) logger.info("Importing data with following parameters: "\ "\n\tWide: {0}"\ "\n\tDesign: {1}"\ "\n\tUnique ID: {2}".format(args.input, args.design, args.uniqID)) palette = colorHandler(pal=args.palette, col=args.color) logger.info(u"Using {0} color scheme from {1} palette".format( args.color, args.palette)) main(args)
# Ending script logger.info("Script complete.") if __name__ == '__main__': # Turn on Logging if option -g was given args = getOptions() # Turn on logger logger = logging.getLogger() sl.setLogger(logger) # Standar logging logger.info(u"""Importing data with following parameters: \tWide: {0} \tDesign: {1} \tUnique ID: {2} \tGroup: {3} \tRun Order: {4} """.format(args.input, args.design, args.uniqID, args.group, args.order)) # Stablishing color palette for adata and cutoffs dataPalette = colorHandler(pal=args.palette, col=args.color) cutPalette = colorHandler(pal="tableau", col="TrafficLight_9") logger.info(u"Using {0} color scheme from {1} palette".format( args.color, args.palette)) #Main script main(args)