python/pymethylprocess/visualizations.py
def plot_heatmap(input_csv,outfilename,index_col,font_scale, min_val, max_val, annot,norm,cluster,matrix_type, xticks, yticks, transpose, color_column):
    """Plot heatmap from CSV file."""
    import os
    os.makedirs(outfilename[:outfilename.rfind('/')],exist_ok=True)
    import matplotlib
    matplotlib.use('Agg')
    import seaborn as sns
    sns.set(font_scale=font_scale)
    import matplotlib.pyplot as plt
    plt.figure(figsize=(20,20))
    df=pd.read_csv(input_csv,index_col=index_col)
    colors=None
    if color_column in list(df):
        network_pal = sns.light_palette('red', len(df[color_column].unique()))
        color_dict = dict(zip(sorted(df[color_column].unique()), network_pal))
        if 0:
            color_dict = dict(zip(df[color_column].unique().tolist(),["#"+''.join(np.random.choice(list('0123456789ABCDEF'),6))
                 for i in range(len(df[color_column].unique()))]))
        colors = df[color_column].map(color_dict)
        df=df.drop(columns=[color_column])
    if transpose:
        df = df.T
    if norm:
        df.loc[:,:]=df.values.astype(np.float)/df.values.astype(np.float).sum(axis=1)[:, np.newaxis]
    #print(df)
    if cluster:
        import scipy.spatial as sp, scipy.cluster.hierarchy as hc
        if matrix_type=='none':
            linkage=None
        else:
            if matrix_type=='similarity':
                df = (df+df.T)/2
                print(df)
                df = 1.-df
            linkage = hc.linkage(sp.distance.squareform(df), method='average')
        sns.clustermap(df, row_linkage=linkage, col_linkage=linkage, xticklabels=xticks, yticklabels=yticks, row_colors=colors, col_colors=None)
    else:
        sns.heatmap(df,vmin=min_val, vmax=max_val if max_val!=-1 else None, annot=annot, xticklabels=xticks, yticklabels=yticks)#,fmt='g'
    plt.tight_layout()
    plt.savefig(outfilename, dpi=300)
Plot heatmap from CSV file.
Plot heatmap from CSV file.
Plot heatmap from CSV file .
def plot_heatmap(input_csv,outfilename,index_col,font_scale, min_val, max_val, annot,norm,cluster,matrix_type, xticks, yticks, transpose, color_column):
    import os
    os.makedirs(outfilename[:outfilename.rfind('/')],exist_ok=True)
    import matplotlib
    matplotlib.use('Agg')
    import seaborn as sns
    sns.set(font_scale=font_scale)
    import matplotlib.pyplot as plt
    plt.figure(figsize=(20,20))
    df=pd.read_csv(input_csv,index_col=index_col)
    colors=None
    if color_column in list(df):
        network_pal = sns.light_palette('red', len(df[color_column].unique()))
        color_dict = dict(zip(sorted(df[color_column].unique()), network_pal))
        if 0:
            color_dict = dict(zip(df[color_column].unique().tolist(),["#"+''.join(np.random.choice(list('0123456789ABCDEF'),6))
                 for i in range(len(df[color_column].unique()))]))
        colors = df[color_column].map(color_dict)
        df=df.drop(columns=[color_column])
    if transpose:
        df = df.T
    if norm:
        df.loc[:,:]=df.values.astype(np.float)/df.values.astype(np.float).sum(axis=1)[:, np.newaxis]
    if cluster:
        import scipy.spatial as sp, scipy.cluster.hierarchy as hc
        if matrix_type=='none':
            linkage=None
        else:
            if matrix_type=='similarity':
                df = (df+df.T)/2
                print(df)
                df = 1.-df
            linkage = hc.linkage(sp.distance.squareform(df), method='average')
        sns.clustermap(df, row_linkage=linkage, col_linkage=linkage, xticklabels=xticks, yticklabels=yticks, row_colors=colors, col_colors=None)
    else:
        sns.heatmap(df,vmin=min_val, vmax=max_val if max_val!=-1 else None, annot=annot, xticklabels=xticks, yticklabels=yticks)
    plt.tight_layout()
    plt.savefig(outfilename, dpi=300)
def plot_heatmap ( input_csv , outfilename , index_col , font_scale , min_val , max_val , annot , norm , cluster , matrix_type , xticks , yticks , transpose , color_column ) : import os os . makedirs ( outfilename [ : outfilename . rfind ( '/' ) ] , exist_ok = True ) import matplotlib matplotlib . use ( 'Agg' ) import seaborn as sns sns . set ( font_scale = font_scale ) import matplotlib . pyplot as plt plt . figure ( figsize = ( 20 , 20 ) ) df = pd . read_csv ( input_csv , index_col = index_col ) colors = None if color_column in list ( df ) : network_pal = sns . light_palette ( 'red' , len ( df [ color_column ] . unique ( ) ) ) color_dict = dict ( zip ( sorted ( df [ color_column ] . unique ( ) ) , network_pal ) ) if 0 : color_dict = dict ( zip ( df [ color_column ] . unique ( ) . tolist ( ) , [ "#" + '' . join ( np . random . choice ( list ( '0123456789ABCDEF' ) , 6 ) ) for i in range ( len ( df [ color_column ] . unique ( ) ) ) ] ) ) colors = df [ color_column ] . map ( color_dict ) df = df . drop ( columns = [ color_column ] ) if transpose : df = df . T if norm : df . loc [ : , : ] = df . values . astype ( np . float ) / df . values . astype ( np . float ) . sum ( axis = 1 ) [ : , np . newaxis ] if cluster : import scipy . spatial as sp , scipy . cluster . hierarchy as hc if matrix_type == 'none' : linkage = None else : if matrix_type == 'similarity' : df = ( df + df . T ) / 2 print ( df ) df = 1. - df linkage = hc . linkage ( sp . distance . squareform ( df ) , method = 'average' ) sns . clustermap ( df , row_linkage = linkage , col_linkage = linkage , xticklabels = xticks , yticklabels = yticks , row_colors = colors , col_colors = None ) else : sns . heatmap ( df , vmin = min_val , vmax = max_val if max_val != - 1 else None , annot = annot , xticklabels = xticks , yticklabels = yticks ) plt . tight_layout ( ) plt . savefig ( outfilename , dpi = 300 )
Plot heatmap from CSV file.
Plot heatmap from CSV file .
"""Plot heatmap from CSV file.""" #print(df) #,fmt='g'
input_csv
outfilename
index_col
font_scale
min_val
max_val
annot
norm
cluster
matrix_type
xticks
yticks
transpose
color_column