python/methylnet/interpretation_classes.py
def gometh(self, collection='GO', allcpgs=[], length_output=20, gsea_analyses=[], gsea_pickle=''):# consider turn into generator go or kegg # add rgreat, lola, roadmap-chromatin hmm, atac-seq, chip-seq, gometh, Hi-C, bedtools, Owen's analysis
        """Run GO, KEGG, GSEA analyses or return nearby genes.

        Parameters
        ----------
        collection : type
            GO, KEGG, GSEA, GENE overlaps?
        allcpgs : type
            All CpGs defines CpG universe, empty if use all CpGs, smaller group of CpGs may yield more significant results.
        length_output : type
            How many lines should the output be, maximum number of results to print.
        gsea_analyses : type
            GSEA analyses/collections to target.
        gsea_pickle : type
            Location of gsea pickle containing gene sets, may need to run download_help_data to acquire.

        Returns
        -------
        Dict
            Dictionary containing results from each test run on all of the keys in top_cpgs.

        """
        import rpy2.robjects as robjects
        from rpy2.robjects import pandas2ri
        #robjects.packages.importr('org.Hs.eg.db')
        pandas2ri.activate()
        output_dfs={}
        if allcpgs:
            allcpgs=robjects.vectors.StrVector(allcpgs)
        else:
            allcpgs=robjects.r('NULL')
        if gsea_analyses:
            gsea_collections=pickle.load(open(gsea_pickle,'rb'))
            gene_sets=[]
            for analysis in gsea_analyses:
                gene_sets.extend(list(gsea_collections[analysis].items()))
            gene_sets=robjects.ListVector(dict(gene_sets))
        for k in self.top_cpgs:
            list_cpgs=self.top_cpgs[k].values
            print('Start Prediction {} BIO'.format(k))
            list_cpgs=robjects.vectors.StrVector(list_cpgs[:,0].tolist())
            if collection == 'GENE':
                mappedEz = self.missMethyl.getMappedEntrezIDs(sig_cpg=list_cpgs, all_cpg = allcpgs, array_type='450K')
                gometh_output = robjects.r('function (mappedEz, length.output) {data.frame(mappedEz$sig.eg[1:length.output])}')(mappedEz,length_output) # sig.eg[1:10]
                print(gometh_output)
            elif collection in ['GO','KEGG']:
                gometh_output = self.missMethyl.gometh(sig_cpg=list_cpgs,all_cpg=allcpgs,collection=collection,prior_prob=True)
                gometh_output = self.limma.topKEGG(gometh_output, number=length_output) if collection=='KEGG' else self.limma.topGO(gometh_output, number=length_output)
            else:
                gometh_output = self.missMethyl.gsameth(sig_cpg=list_cpgs,all_cpg=allcpgs,collection=gene_sets,prior_prob=True)
                gometh_output = robjects.r('as.table')(self.missMethyl.topGSA(gometh_output, number=length_output))
                #robjects.r('print')(gometh_output)
            # FIXME add get genes
            # genes = self.missMethyl.getMappedEntrezIDs(sig.cpg, all.cpg = NULL, array.type, anno = NULL)
            output_dfs['prediction_{}'.format(k)]=pandas2ri.ri2py(robjects.r['as'](gometh_output,'data.frame')) if not gsea_analyses else pandas2ri.ri2py(robjects.r('as.data.frame')(gometh_output)).pivot(index='Var1',columns='Var2',values='Freq').sort_values('P.DE')
            print(output_dfs['prediction_{}'.format(k)].head())
            #print('GO/KEGG/GSEA Computed for Prediction {} Cpgs: {}'.format(k, ' '.join(list_cpgs)))
        return output_dfs
Run GO, KEGG, GSEA analyses or return nearby genes.

        Parameters
        ----------
        collection : type
            GO, KEGG, GSEA, GENE overlaps?
        allcpgs : type
            All CpGs defines CpG universe, empty if use all CpGs, smaller group of CpGs may yield more significant results.
        length_output : type
            How many lines should the output be, maximum number of results to print.
        gsea_analyses : type
            GSEA analyses/collections to target.
        gsea_pickle : type
            Location of gsea pickle containing gene sets, may need to run download_help_data to acquire.

        Returns
        -------
        Dict
            Dictionary containing results from each test run on all of the keys in top_cpgs.

        
Run GO, KEGG, GSEA analyses or return nearby genes.
Parameters

collection : type
GO, KEGG, GSEA, GENE overlaps.
allcpgs : type
All CpGs defines CpG universe, empty if use all CpGs, smaller group of CpGs may yield more significant results.
length_output : type
How many lines should the output be, maximum number of results to print.
gsea_analyses : type
GSEA analyses/collections to target.
gsea_pickle : type
Location of gsea pickle containing gene sets, may need to run download_help_data to acquire.

Returns

Dict
Dictionary containing results from each test run on all of the keys in top_cpgs.
Run GO KEGG GSEA analyses or return nearby genes . Parameters collection : type GO KEGG GSEA GENE overlaps . allcpgs : type All CpGs defines CpG universe empty if use all CpGs smaller group of CpGs may yield more significant results . length_output : type How many lines should the output be maximum number of results to print . gsea_analyses : type GSEA analyses / collections to target . gsea_pickle : type Location of gsea pickle containing gene sets may need to run download_help_data to acquire . Returns Dict Dictionary containing results from each test run on all of the keys in top_cpgs .
def gometh(self, collection='GO', allcpgs=[], length_output=20, gsea_analyses=[], gsea_pickle=''):
        import rpy2.robjects as robjects
        from rpy2.robjects import pandas2ri
        pandas2ri.activate()
        output_dfs={}
        if allcpgs:
            allcpgs=robjects.vectors.StrVector(allcpgs)
        else:
            allcpgs=robjects.r('NULL')
        if gsea_analyses:
            gsea_collections=pickle.load(open(gsea_pickle,'rb'))
            gene_sets=[]
            for analysis in gsea_analyses:
                gene_sets.extend(list(gsea_collections[analysis].items()))
            gene_sets=robjects.ListVector(dict(gene_sets))
        for k in self.top_cpgs:
            list_cpgs=self.top_cpgs[k].values
            print('Start Prediction {} BIO'.format(k))
            list_cpgs=robjects.vectors.StrVector(list_cpgs[:,0].tolist())
            if collection == 'GENE':
                mappedEz = self.missMethyl.getMappedEntrezIDs(sig_cpg=list_cpgs, all_cpg = allcpgs, array_type='450K')
                gometh_output = robjects.r('function (mappedEz, length.output) {data.frame(mappedEz$sig.eg[1:length.output])}')(mappedEz,length_output) 
                print(gometh_output)
            elif collection in ['GO','KEGG']:
                gometh_output = self.missMethyl.gometh(sig_cpg=list_cpgs,all_cpg=allcpgs,collection=collection,prior_prob=True)
                gometh_output = self.limma.topKEGG(gometh_output, number=length_output) if collection=='KEGG' else self.limma.topGO(gometh_output, number=length_output)
            else:
                gometh_output = self.missMethyl.gsameth(sig_cpg=list_cpgs,all_cpg=allcpgs,collection=gene_sets,prior_prob=True)
                gometh_output = robjects.r('as.table')(self.missMethyl.topGSA(gometh_output, number=length_output))
            output_dfs['prediction_{}'.format(k)]=pandas2ri.ri2py(robjects.r['as'](gometh_output,'data.frame')) if not gsea_analyses else pandas2ri.ri2py(robjects.r('as.data.frame')(gometh_output)).pivot(index='Var1',columns='Var2',values='Freq').sort_values('P.DE')
            print(output_dfs['prediction_{}'.format(k)].head())
        return output_dfs
def gometh ( self , collection = 'GO' , allcpgs = [ ] , length_output = 20 , gsea_analyses = [ ] , gsea_pickle = '' ) : import rpy2 . robjects as robjects from rpy2 . robjects import pandas2ri pandas2ri . activate ( ) output_dfs = { } if allcpgs : allcpgs = robjects . vectors . StrVector ( allcpgs ) else : allcpgs = robjects . r ( 'NULL' ) if gsea_analyses : gsea_collections = pickle . load ( open ( gsea_pickle , 'rb' ) ) gene_sets = [ ] for analysis in gsea_analyses : gene_sets . extend ( list ( gsea_collections [ analysis ] . items ( ) ) ) gene_sets = robjects . ListVector ( dict ( gene_sets ) ) for k in self . top_cpgs : list_cpgs = self . top_cpgs [ k ] . values print ( 'Start Prediction {} BIO' . format ( k ) ) list_cpgs = robjects . vectors . StrVector ( list_cpgs [ : , 0 ] . tolist ( ) ) if collection == 'GENE' : mappedEz = self . missMethyl . getMappedEntrezIDs ( sig_cpg = list_cpgs , all_cpg = allcpgs , array_type = '450K' ) gometh_output = robjects . r ( 'function (mappedEz, length.output) {data.frame(mappedEz$sig.eg[1:length.output])}' ) ( mappedEz , length_output ) print ( gometh_output ) elif collection in [ 'GO' , 'KEGG' ] : gometh_output = self . missMethyl . gometh ( sig_cpg = list_cpgs , all_cpg = allcpgs , collection = collection , prior_prob = True ) gometh_output = self . limma . topKEGG ( gometh_output , number = length_output ) if collection == 'KEGG' else self . limma . topGO ( gometh_output , number = length_output ) else : gometh_output = self . missMethyl . gsameth ( sig_cpg = list_cpgs , all_cpg = allcpgs , collection = gene_sets , prior_prob = True ) gometh_output = robjects . r ( 'as.table' ) ( self . missMethyl . topGSA ( gometh_output , number = length_output ) ) output_dfs [ 'prediction_{}' . format ( k ) ] = pandas2ri . ri2py ( robjects . r [ 'as' ] ( gometh_output , 'data.frame' ) ) if not gsea_analyses else pandas2ri . ri2py ( robjects . r ( 'as.data.frame' ) ( gometh_output ) ) . pivot ( index = 'Var1' , columns = 'Var2' , values = 'Freq' ) . sort_values ( 'P.DE' ) print ( output_dfs [ 'prediction_{}' . format ( k ) ] . head ( ) ) return output_dfs
Run GO, KEGG, GSEA analyses or return nearby genes.
Run GO KEGG GSEA analyses or return nearby genes .
# consider turn into generator go or kegg # add rgreat, lola, roadmap-chromatin hmm, atac-seq, chip-seq, gometh, Hi-C, bedtools, Owen's analysis """Run GO, KEGG, GSEA analyses or return nearby genes.

        Parameters
        ----------
        collection : type
            GO, KEGG, GSEA, GENE overlaps?
        allcpgs : type
            All CpGs defines CpG universe, empty if use all CpGs, smaller group of CpGs may yield more significant results.
        length_output : type
            How many lines should the output be, maximum number of results to print.
        gsea_analyses : type
            GSEA analyses/collections to target.
        gsea_pickle : type
            Location of gsea pickle containing gene sets, may need to run download_help_data to acquire.

        Returns
        -------
        Dict
            Dictionary containing results from each test run on all of the keys in top_cpgs.

        """ #robjects.packages.importr('org.Hs.eg.db') # sig.eg[1:10] #robjects.r('print')(gometh_output) # FIXME add get genes # genes = self.missMethyl.getMappedEntrezIDs(sig.cpg, all.cpg = NULL, array.type, anno = NULL) #print('GO/KEGG/GSEA Computed for Prediction {} Cpgs: {}'.format(k, ' '.join(list_cpgs)))
self
collection
allcpgs
length_output
gsea_analyses
gsea_pickle