gseapy/enrichr.py
def get_background(self):
        """get background gene"""

        # input is a file
        if os.path.isfile(self.background):
            with open(self.background) as b:
                bg2 = b.readlines() 
            bg = [g.strip() for g in bg2]  
            return set(bg)
        
        # package included data
        DB_FILE = resource_filename("gseapy", "data/{}.background.genes.txt".format(self.background))
        filename = os.path.join(DEFAULT_CACHE_PATH, "{}.background.genes.txt".format(self.background))  
        if os.path.exists(filename):
            df = pd.read_csv(filename,sep="\t")
        elif os.path.exists(DB_FILE):
            df = pd.read_csv(DB_FILE,sep="\t")
        else:
            # background is a biomart database name
            self._logger.warning("Downloading %s for the first time. It might take a couple of miniutes."%self.background)
            bm = Biomart()
            df = bm.query(dataset=self.background)
            df.dropna(subset=['go_id'], inplace=True)
        self._logger.info("using all annotated genes with GO_ID as background genes")
        df.dropna(subset=['entrezgene'], inplace=True)     
        # input id type: entrez or gene_name
        if self._isezid:
            bg = df['entrezgene'].astype(int)
        else:
            bg = df['external_gene_name']

        return set(bg)
def get_background(self):
        # input is a file
        if os.path.isfile(self.background):
            with open(self.background) as b:
                bg2 = b.readlines() 
            bg = [g.strip() for g in bg2]  
            return set(bg)
        
        # package included data
        DB_FILE = resource_filename("gseapy", "data/{}.background.genes.txt".format(self.background))
        filename = os.path.join(DEFAULT_CACHE_PATH, "{}.background.genes.txt".format(self.background))  
        if os.path.exists(filename):
            df = pd.read_csv(filename,sep="\t")
        elif os.path.exists(DB_FILE):
            df = pd.read_csv(DB_FILE,sep="\t")
        else:
            # background is a biomart database name
            self._logger.warning("Downloading %s for the first time. It might take a couple of miniutes."%self.background)
            bm = Biomart()
            df = bm.query(dataset=self.background)
            df.dropna(subset=['go_id'], inplace=True)
        self._logger.info("using all annotated genes with GO_ID as background genes")
        df.dropna(subset=['entrezgene'], inplace=True)     
        # input id type: entrez or gene_name
        if self._isezid:
            bg = df['entrezgene'].astype(int)
        else:
            bg = df['external_gene_name']

        return set(bg)
def get_background ( self ) : # input is a file if os . path . isfile ( self . background ) : with open ( self . background ) as b : bg2 = b . readlines ( ) bg = [ g . strip ( ) for g in bg2 ] return set ( bg ) # package included data DB_FILE = resource_filename ( "gseapy" , "data/{}.background.genes.txt" . format ( self . background ) ) filename = os . path . join ( DEFAULT_CACHE_PATH , "{}.background.genes.txt" . format ( self . background ) ) if os . path . exists ( filename ) : df = pd . read_csv ( filename , sep = "\t" ) elif os . path . exists ( DB_FILE ) : df = pd . read_csv ( DB_FILE , sep = "\t" ) else : # background is a biomart database name self . _logger . warning ( "Downloading %s for the first time. It might take a couple of miniutes." % self . background ) bm = Biomart ( ) df = bm . query ( dataset = self . background ) df . dropna ( subset = [ 'go_id' ] , inplace = True ) self . _logger . info ( "using all annotated genes with GO_ID as background genes" ) df . dropna ( subset = [ 'entrezgene' ] , inplace = True ) # input id type: entrez or gene_name if self . _isezid : bg = df [ 'entrezgene' ] . astype ( int ) else : bg = df [ 'external_gene_name' ] return set ( bg )
get background gene
get background gene