python/methylnet/interpretation_classes.py
def plot_cpgs(self, top_cpgs, output_dir='./'):
        """Plot top CpGs location in genome.

        Parameters
        ----------
        top_cpgs : type
            Input dataframe of top CpG name and SHAP scores. Future: Plot SHAP scores in locations?
        output_dir : type
            Where to output plots.

        """
        import rpy2.robjects as robjects
        from rpy2.robjects import pandas2ri
        from collections import defaultdict
        pandas2ri.activate()
        self.top_cpgs = top_cpgs
        cpg_locations = pandas2ri.ri2py(robjects.r['as'](robjects.r('getAnnotation(IlluminaHumanMethylation450kanno.ilmn12.hg19)'),'data.frame')).set_index(keys='Name',drop=False)
        print(cpg_locations)
        cpgs_grange = robjects.r('makeGRangesFromDataFrame')(pandas2ri.py2ri(cpg_locations),start_field='pos',end_field='pos',starts_in_df_are_0based=False)
        output_dfs = {}
        plots={}
        p=self.generate_base_plot()
        #ggsave = robjects.r("""function (file.name, p) {ggsave(file.name,p)}""")
        for i,k in enumerate(list(self.top_cpgs.keys())):
            list_cpgs=np.squeeze(self.top_cpgs[k].values[:,0])
            cpg_location_subset = cpg_locations.loc[list_cpgs,:]
            location_subset = robjects.r('makeGRangesFromDataFrame')(pandas2ri.py2ri(cpg_location_subset),start_field='pos',end_field='pos',starts_in_df_are_0based=False)
            locations=self.add_plot_data(location_subset,locations) if i>0 else self.add_plot_data(location_subset)
            #self.add_plot(p,location_subset)
        self.generate_final_plot(p,locations)
        self.ggbio.ggsave(join(output_dir,'{}.png'.format('_'.join([k for k in self.top_cpgs]))))
Plot top CpGs location in genome.

        Parameters
        ----------
        top_cpgs : type
            Input dataframe of top CpG name and SHAP scores. Future: Plot SHAP scores in locations?
        output_dir : type
            Where to output plots.

        
Plot top CpGs location in genome.
Parameters

top_cpgs : type
Input dataframe of top CpG name and SHAP scores. Future: Plot SHAP scores in locations.
output_dir : type
Where to output plots.
Plot top CpGs location in genome . Parameters top_cpgs : type Input dataframe of top CpG name and SHAP scores . Future : Plot SHAP scores in locations . output_dir : type Where to output plots .
def plot_cpgs(self, top_cpgs, output_dir='./'):
        import rpy2.robjects as robjects
        from rpy2.robjects import pandas2ri
        from collections import defaultdict
        pandas2ri.activate()
        self.top_cpgs = top_cpgs
        cpg_locations = pandas2ri.ri2py(robjects.r['as'](robjects.r('getAnnotation(IlluminaHumanMethylation450kanno.ilmn12.hg19)'),'data.frame')).set_index(keys='Name',drop=False)
        print(cpg_locations)
        cpgs_grange = robjects.r('makeGRangesFromDataFrame')(pandas2ri.py2ri(cpg_locations),start_field='pos',end_field='pos',starts_in_df_are_0based=False)
        output_dfs = {}
        plots={}
        p=self.generate_base_plot()
        for i,k in enumerate(list(self.top_cpgs.keys())):
            list_cpgs=np.squeeze(self.top_cpgs[k].values[:,0])
            cpg_location_subset = cpg_locations.loc[list_cpgs,:]
            location_subset = robjects.r('makeGRangesFromDataFrame')(pandas2ri.py2ri(cpg_location_subset),start_field='pos',end_field='pos',starts_in_df_are_0based=False)
            locations=self.add_plot_data(location_subset,locations) if i>0 else self.add_plot_data(location_subset)
        self.generate_final_plot(p,locations)
        self.ggbio.ggsave(join(output_dir,'{}.png'.format('_'.join([k for k in self.top_cpgs]))))
def plot_cpgs ( self , top_cpgs , output_dir = './' ) : import rpy2 . robjects as robjects from rpy2 . robjects import pandas2ri from collections import defaultdict pandas2ri . activate ( ) self . top_cpgs = top_cpgs cpg_locations = pandas2ri . ri2py ( robjects . r [ 'as' ] ( robjects . r ( 'getAnnotation(IlluminaHumanMethylation450kanno.ilmn12.hg19)' ) , 'data.frame' ) ) . set_index ( keys = 'Name' , drop = False ) print ( cpg_locations ) cpgs_grange = robjects . r ( 'makeGRangesFromDataFrame' ) ( pandas2ri . py2ri ( cpg_locations ) , start_field = 'pos' , end_field = 'pos' , starts_in_df_are_0based = False ) output_dfs = { } plots = { } p = self . generate_base_plot ( ) for i , k in enumerate ( list ( self . top_cpgs . keys ( ) ) ) : list_cpgs = np . squeeze ( self . top_cpgs [ k ] . values [ : , 0 ] ) cpg_location_subset = cpg_locations . loc [ list_cpgs , : ] location_subset = robjects . r ( 'makeGRangesFromDataFrame' ) ( pandas2ri . py2ri ( cpg_location_subset ) , start_field = 'pos' , end_field = 'pos' , starts_in_df_are_0based = False ) locations = self . add_plot_data ( location_subset , locations ) if i > 0 else self . add_plot_data ( location_subset ) self . generate_final_plot ( p , locations ) self . ggbio . ggsave ( join ( output_dir , '{}.png' . format ( '_' . join ( [ k for k in self . top_cpgs ] ) ) ) )
Plot top CpGs location in genome.
Plot top CpGs location in genome .
"""Plot top CpGs location in genome.

        Parameters
        ----------
        top_cpgs : type
            Input dataframe of top CpG name and SHAP scores. Future: Plot SHAP scores in locations?
        output_dir : type
            Where to output plots.

        """ #ggsave = robjects.r("""function (file.name, p) {ggsave(file.name,p)}""") #self.add_plot(p,location_subset)
self
top_cpgs
output_dir