Пример #1
0
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)
Пример #2
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.")
Пример #3
0
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
Пример #4
0
    df_transf.to_csv(args.oname, index=False, sep='\t', float_format="%.4f")
    df_rev.to_csv(args.oname2, index=False, sep='\t')


if __name__ == '__main__':
    # Command line options
    args = getOptions()

    # Activate Logger
    logger = logging.getLogger()
    sl.setLogger(logger)

    # Starting script
    logger.info(u"Importing data with following parameters: "\
                "\n\tWide: {0}"\
                "\n\tDesign: {1}"\
                "\n\tUnique ID: {2}"\
                "\n\tGroup Column: {3}".format(args.input, args.design,
                args.uniqID, args.group))

    # Stablishing color palette
    palette = colorHandler(pal=args.palette, col=args.color)
    logger.info(u"Using {0} color scheme from {1} palette".format(
        args.color, args.palette))

    # Getting rid of warnings.
    warnings.filterwarnings("ignore", category=DeprecationWarning)

    # Main Code
    main(args)