python/methylnet/interpretation_classes.py
def plot_lola_output_(lola_csv, plot_output_dir, description_col, cell_types):
    """Plots any LOLA output in the form of a forest plot.

    Parameters
    ----------
    lola_csv : type
        CSV containing lola results.
    plot_output_dir : type
        Plot output directory.
    description_col : type
        Column that will label the points on the plot.
    cell_types : type
        Column containing cell-types, colors plots and are rows to be compared.

    """
    os.makedirs(plot_output_dir,exist_ok=True)
    import matplotlib
    matplotlib.use('Agg')
    import seaborn as sns
    import matplotlib.pyplot as plt
    # from rpy2.robjects.packages import importr
    # import rpy2.robjects as robjects
    # from rpy2.robjects import pandas2ri
    # pandas2ri.activate()
    # ggplot=importr("ggplot2")
    # importr("ggpubr")
    # forcats=importr('forcats')
    #
    # create_bar_chart=robjects.r("""function(df,fill.col=NULL){
    #                     ggboxplot(df, x = "description", y = "oddsRatio", fill = fill.col,#,
    #                       color = "white",           # Set bar border colors to white
    #                       palette = "jco",            # jco journal color palett. see ?ggpar
    #
    #                       orientation = "horiz")}           # Sort the value in dscending order
    #                       #sort.by.groups = F, #TRUE,      # Sort inside each group
    #                       # sort.val = "desc",
    #                       #)
    #                 #}""")

    def create_bar_chart(df, description='description', cell_type=None):
        sns.set(style="whitegrid")
        f, ax = plt.subplots(figsize=(10,7))
        sns.despine(bottom=True, left=True)
        sns.stripplot(x="oddsRatio", y=description, hue=cell_type,
              data=df, dodge=True, jitter=True,
              alpha=.25, zorder=1)
        sns.pointplot(x="oddsRatio", y=description, hue=cell_type,
              data=df, dodge=.532, join=False, palette="dark",
              markers="d", scale=.75, ci=None)
        handles, labels = ax.get_legend_handles_labels()
        ax.legend(handles[3:], labels[3:], title="Cell Types",
                  handletextpad=0, columnspacing=1,
                  loc="lower right", ncol=3, frameon=True)
        ax.set_xlim(left=0)
        return f,ax

    lola_results=pd.read_csv(lola_csv)#[['collection','description','oddsRatio','cellType']]

    # filter cell types here
    collections_df=lola_results.groupby('collection')
    for name,df in collections_df:
        top_results_df=df.iloc[:min(25,df.shape[0]),:].reset_index(drop=True)

        #top_results_df=pandas2ri.py2ri(top_results_df)#pandas2ri.py2ri(top_results_df)
        #robjects.r("print")(top_results_df)
        #top_results_df=robjects.r("function(df){data.frame(df,stringsAsFactors=FALSE)}")(robjects.r("function(df){lapply(df,as.character)}")(top_results_df)) # FIX
        #print(top_results_df)
        """RESET FACTORS ^^^"""
        #diagnose_df=pandas2ri.ri2py(top_results_df)
        top_results_df=top_results_df.fillna('NULL')
        plt.figure()
        f,ax=create_bar_chart(top_results_df,description_col,'cellType')
        plt.tight_layout()
        plt.savefig(join(plot_output_dir,lola_csv.split('/')[-1].replace('.csv','_{}.png'.format(name))))
        plt.close()
        #ggplot.ggsave(join(plot_output_dir,lola_csv.split('/')[-1].replace('.csv','_{}.png'.format(name))))
    # add shore island breakdown
Plots any LOLA output in the form of a forest plot.

    Parameters
    ----------
    lola_csv : type
        CSV containing lola results.
    plot_output_dir : type
        Plot output directory.
    description_col : type
        Column that will label the points on the plot.
    cell_types : type
        Column containing cell-types, colors plots and are rows to be compared.

    
Plots any LOLA output in the form of a forest plot.
Parameters

lola_csv : type
CSV containing lola results.
plot_output_dir : type
Plot output directory.
description_col : type
Column that will label the points on the plot.
cell_types : type
Column containing cell-types, colors plots and are rows to be compared.
Plots any LOLA output in the form of a forest plot . Parameters lola_csv : type CSV containing lola results . plot_output_dir : type Plot output directory . description_col : type Column that will label the points on the plot . cell_types : type Column containing cell - types colors plots and are rows to be compared .
def plot_lola_output_(lola_csv, plot_output_dir, description_col, cell_types):
    os.makedirs(plot_output_dir,exist_ok=True)
    import matplotlib
    matplotlib.use('Agg')
    import seaborn as sns
    import matplotlib.pyplot as plt
     create_bar_chart=robjects.r("""function(df,fill.col=NULL){
                         ggboxplot(df, x = "description", y = "oddsRatio", fill = fill.col,,
                           color = "white",            Set bar border colors to white
                           palette = "jco",             jco journal color palett. see ?ggpar
                           orientation = "horiz")}            Sort the value in dscending order
                           sort.by.groups = F, TRUE,       Sort inside each group
                            sort.val = "desc",
                           )
                     }""")
    def create_bar_chart(df, description='description', cell_type=None):
        sns.set(style="whitegrid")
        f, ax = plt.subplots(figsize=(10,7))
        sns.despine(bottom=True, left=True)
        sns.stripplot(x="oddsRatio", y=description, hue=cell_type,
              data=df, dodge=True, jitter=True,
              alpha=.25, zorder=1)
        sns.pointplot(x="oddsRatio", y=description, hue=cell_type,
              data=df, dodge=.532, join=False, palette="dark",
              markers="d", scale=.75, ci=None)
        handles, labels = ax.get_legend_handles_labels()
        ax.legend(handles[3:], labels[3:], title="Cell Types",
                  handletextpad=0, columnspacing=1,
                  loc="lower right", ncol=3, frameon=True)
        ax.set_xlim(left=0)
        return f,ax
    lola_results=pd.read_csv(lola_csv)[['collection','description','oddsRatio','cellType']]
     filter cell types here
    collections_df=lola_results.groupby('collection')
    for name,df in collections_df:
        top_results_df=df.iloc[:min(25,df.shape[0]),:].reset_index(drop=True)
        top_results_df=pandas2ri.py2ri(top_results_df)pandas2ri.py2ri(top_results_df)
        robjects.r("print")(top_results_df)
        top_results_df=robjects.r("function(df){data.frame(df,stringsAsFactors=FALSE)}")(robjects.r("function(df){lapply(df,as.character)}")(top_results_df))  FIX
        print(top_results_df)
        diagnose_df=pandas2ri.ri2py(top_results_df)
        top_results_df=top_results_df.fillna('NULL')
        plt.figure()
        f,ax=create_bar_chart(top_results_df,description_col,'cellType')
        plt.tight_layout()
        plt.savefig(join(plot_output_dir,lola_csv.split('/')[-1].replace('.csv','_{}.png'.format(name))))
        plt.close()
        ggplot.ggsave(join(plot_output_dir,lola_csv.split('/')[-1].replace('.csv','_{}.png'.format(name))))
     add shore island breakdown
def plot_lola_output_ ( lola_csv , plot_output_dir , description_col , cell_types ) : os . makedirs ( plot_output_dir , exist_ok = True ) import matplotlib matplotlib . use ( 'Agg' ) import seaborn as sns import matplotlib . pyplot as plt def create_bar_chart ( df , description = 'description' , cell_type = None ) : sns . set ( style = "whitegrid" ) f , ax = plt . subplots ( figsize = ( 10 , 7 ) ) sns . despine ( bottom = True , left = True ) sns . stripplot ( x = "oddsRatio" , y = description , hue = cell_type , data = df , dodge = True , jitter = True , alpha = .25 , zorder = 1 ) sns . pointplot ( x = "oddsRatio" , y = description , hue = cell_type , data = df , dodge = .532 , join = False , palette = "dark" , markers = "d" , scale = .75 , ci = None ) handles , labels = ax . get_legend_handles_labels ( ) ax . legend ( handles [ 3 : ] , labels [ 3 : ] , title = "Cell Types" , handletextpad = 0 , columnspacing = 1 , loc = "lower right" , ncol = 3 , frameon = True ) ax . set_xlim ( left = 0 ) return f , ax lola_results = pd . read_csv ( lola_csv ) collections_df = lola_results . groupby ( 'collection' ) for name , df in collections_df : top_results_df = df . iloc [ : min ( 25 , df . shape [ 0 ] ) , : ] . reset_index ( drop = True ) """RESET FACTORS ^^^""" top_results_df = top_results_df . fillna ( 'NULL' ) plt . figure ( ) f , ax = create_bar_chart ( top_results_df , description_col , 'cellType' ) plt . tight_layout ( ) plt . savefig ( join ( plot_output_dir , lola_csv . split ( '/' ) [ - 1 ] . replace ( '.csv' , '_{}.png' . format ( name ) ) ) ) plt . close ( )
Plots any LOLA output in the form of a forest plot.
Plots any LOLA output in the form of a forest plot .
"""Plots any LOLA output in the form of a forest plot.

    Parameters
    ----------
    lola_csv : type
        CSV containing lola results.
    plot_output_dir : type
        Plot output directory.
    description_col : type
        Column that will label the points on the plot.
    cell_types : type
        Column containing cell-types, colors plots and are rows to be compared.

    """ # from rpy2.robjects.packages import importr # import rpy2.robjects as robjects # from rpy2.robjects import pandas2ri # pandas2ri.activate() # ggplot=importr("ggplot2") # importr("ggpubr") # forcats=importr('forcats') # # create_bar_chart=robjects.r("""function(df,fill.col=NULL){ #                     ggboxplot(df, x = "description", y = "oddsRatio", fill = fill.col,#, #                       color = "white",           # Set bar border colors to white #                       palette = "jco",            # jco journal color palett. see ?ggpar # #                       orientation = "horiz")}           # Sort the value in dscending order #                       #sort.by.groups = F, #TRUE,      # Sort inside each group #                       # sort.val = "desc", #                       #) #                 #}""") #[['collection','description','oddsRatio','cellType']] # filter cell types here #top_results_df=pandas2ri.py2ri(top_results_df)#pandas2ri.py2ri(top_results_df) #robjects.r("print")(top_results_df) #top_results_df=robjects.r("function(df){data.frame(df,stringsAsFactors=FALSE)}")(robjects.r("function(df){lapply(df,as.character)}")(top_results_df)) # FIX #print(top_results_df) """RESET FACTORS ^^^""" #diagnose_df=pandas2ri.ri2py(top_results_df) #ggplot.ggsave(join(plot_output_dir,lola_csv.split('/')[-1].replace('.csv','_{}.png'.format(name)))) # add shore island breakdown
lola_csv
plot_output_dir
description_col
cell_types