gseapy/gsea.py
def run(self):
        """main replot function"""
        assert self.min_size <= self.max_size
        assert self.fignum > 0
        import glob
        from bs4 import BeautifulSoup

        # parsing files.......
        try:
            results_path = glob.glob(self.indir+'*/edb/results.edb')[0]
            rank_path =  glob.glob(self.indir+'*/edb/*.rnk')[0]
            gene_set_path =  glob.glob(self.indir+'*/edb/gene_sets.gmt')[0]
        except IndexError as e:
            sys.stderr.write("Could not locate GSEA files in the given directory!")
            sys.exit(1)
        # extract sample names from .cls file
        cls_path = glob.glob(self.indir+'*/edb/*.cls')
        if cls_path:
            pos, neg, classes = gsea_cls_parser(cls_path[0])
        else:
            # logic for prerank results
            pos, neg = '',''
        # start reploting
        self.gene_sets=gene_set_path
        # obtain gene sets
        gene_set_dict = self.parse_gmt(gmt=gene_set_path)
        # obtain rank_metrics
        rank_metric = self._load_ranking(rank_path)
        correl_vector =  rank_metric.values
        gene_list = rank_metric.index.values
        # extract each enriment term in the results.edb files and plot.
        database = BeautifulSoup(open(results_path), features='xml')
        length = len(database.findAll('DTG'))
        fig_num = self.fignum if self.fignum <= length else length
        for idx in range(fig_num):
            # extract statistical resutls from results.edb file
            enrich_term, hit_ind, nes, pval, fdr= gsea_edb_parser(results_path, index=idx)
            gene_set = gene_set_dict.get(enrich_term)
            # calculate enrichment score
            RES = enrichment_score(gene_list=gene_list, 
                                   correl_vector=correl_vector,
                                   gene_set=gene_set, 
                                   weighted_score_type=self.weighted_score_type,
                                   nperm=0)[-1]
            # plotting
            term = enrich_term.replace('/','_').replace(":","_")
            outfile = '{0}/{1}.{2}.{3}'.format(self.outdir, term, self.module, self.format)
            gseaplot(rank_metric=rank_metric, term=enrich_term, 
                         hits_indices=hit_ind, nes=nes, pval=pval, fdr=fdr, 
                         RES=RES, pheno_pos=pos, pheno_neg=neg, 
                         figsize=self.figsize, ofname=outfile)

        self._logger.info("Congratulations! Your plots have been reproduced successfully!\n")
def run(self):
        assert self.min_size <= self.max_size
        assert self.fignum > 0
        import glob
        from bs4 import BeautifulSoup

        # parsing files.......
        try:
            results_path = glob.glob(self.indir+'*/edb/results.edb')[0]
            rank_path =  glob.glob(self.indir+'*/edb/*.rnk')[0]
            gene_set_path =  glob.glob(self.indir+'*/edb/gene_sets.gmt')[0]
        except IndexError as e:
            sys.stderr.write("Could not locate GSEA files in the given directory!")
            sys.exit(1)
        # extract sample names from .cls file
        cls_path = glob.glob(self.indir+'*/edb/*.cls')
        if cls_path:
            pos, neg, classes = gsea_cls_parser(cls_path[0])
        else:
            # logic for prerank results
            pos, neg = '',''
        # start reploting
        self.gene_sets=gene_set_path
        # obtain gene sets
        gene_set_dict = self.parse_gmt(gmt=gene_set_path)
        # obtain rank_metrics
        rank_metric = self._load_ranking(rank_path)
        correl_vector =  rank_metric.values
        gene_list = rank_metric.index.values
        # extract each enriment term in the results.edb files and plot.
        database = BeautifulSoup(open(results_path), features='xml')
        length = len(database.findAll('DTG'))
        fig_num = self.fignum if self.fignum <= length else length
        for idx in range(fig_num):
            # extract statistical resutls from results.edb file
            enrich_term, hit_ind, nes, pval, fdr= gsea_edb_parser(results_path, index=idx)
            gene_set = gene_set_dict.get(enrich_term)
            # calculate enrichment score
            RES = enrichment_score(gene_list=gene_list, 
                                   correl_vector=correl_vector,
                                   gene_set=gene_set, 
                                   weighted_score_type=self.weighted_score_type,
                                   nperm=0)[-1]
            # plotting
            term = enrich_term.replace('/','_').replace(":","_")
            outfile = '{0}/{1}.{2}.{3}'.format(self.outdir, term, self.module, self.format)
            gseaplot(rank_metric=rank_metric, term=enrich_term, 
                         hits_indices=hit_ind, nes=nes, pval=pval, fdr=fdr, 
                         RES=RES, pheno_pos=pos, pheno_neg=neg, 
                         figsize=self.figsize, ofname=outfile)

        self._logger.info("Congratulations! Your plots have been reproduced successfully!\n")
def run ( self ) : assert self . min_size <= self . max_size assert self . fignum > 0 import glob from bs4 import BeautifulSoup # parsing files....... try : results_path = glob . glob ( self . indir + '*/edb/results.edb' ) [ 0 ] rank_path = glob . glob ( self . indir + '*/edb/*.rnk' ) [ 0 ] gene_set_path = glob . glob ( self . indir + '*/edb/gene_sets.gmt' ) [ 0 ] except IndexError as e : sys . stderr . write ( "Could not locate GSEA files in the given directory!" ) sys . exit ( 1 ) # extract sample names from .cls file cls_path = glob . glob ( self . indir + '*/edb/*.cls' ) if cls_path : pos , neg , classes = gsea_cls_parser ( cls_path [ 0 ] ) else : # logic for prerank results pos , neg = '' , '' # start reploting self . gene_sets = gene_set_path # obtain gene sets gene_set_dict = self . parse_gmt ( gmt = gene_set_path ) # obtain rank_metrics rank_metric = self . _load_ranking ( rank_path ) correl_vector = rank_metric . values gene_list = rank_metric . index . values # extract each enriment term in the results.edb files and plot. database = BeautifulSoup ( open ( results_path ) , features = 'xml' ) length = len ( database . findAll ( 'DTG' ) ) fig_num = self . fignum if self . fignum <= length else length for idx in range ( fig_num ) : # extract statistical resutls from results.edb file enrich_term , hit_ind , nes , pval , fdr = gsea_edb_parser ( results_path , index = idx ) gene_set = gene_set_dict . get ( enrich_term ) # calculate enrichment score RES = enrichment_score ( gene_list = gene_list , correl_vector = correl_vector , gene_set = gene_set , weighted_score_type = self . weighted_score_type , nperm = 0 ) [ - 1 ] # plotting term = enrich_term . replace ( '/' , '_' ) . replace ( ":" , "_" ) outfile = '{0}/{1}.{2}.{3}' . format ( self . outdir , term , self . module , self . format ) gseaplot ( rank_metric = rank_metric , term = enrich_term , hits_indices = hit_ind , nes = nes , pval = pval , fdr = fdr , RES = RES , pheno_pos = pos , pheno_neg = neg , figsize = self . figsize , ofname = outfile ) self . _logger . info ( "Congratulations! Your plots have been reproduced successfully!\n" )
main replot function
main replot function