gseapy/enrichr.py
def parse_genesets(self):
        """parse gene_sets input file type"""

        enrichr_library = self.get_libraries()
        if isinstance(self.gene_sets, list):
            gss = self.gene_sets
        elif isinstance(self.gene_sets, str):
            gss = [ g.strip() for g in self.gene_sets.strip().split(",") ]
        elif isinstance(self.gene_sets, dict):
            gss = [self.gene_sets]
        else:
            raise Exception("Error parsing enrichr libraries, please provided corrected one")
        
        # gss: a list contain .gmt, dict, enrichr_liraries.
        # now, convert .gmt to dict
        gss_exist = [] 
        for g in gss:
            if isinstance(g, dict): 
                gss_exist.append(g)
                continue

            if isinstance(g, str): 
                if g in enrichr_library: 
                    gss_exist.append(g)
                    continue
                if g.lower().endswith(".gmt") and os.path.exists(g):
                    self._logger.info("User Defined gene sets is given: %s"%g)
                    with open(g) as genesets:
                        g_dict = { line.strip().split("\t")[0]: line.strip().split("\t")[2:]
                                        for line in genesets.readlines() }
                    gss_exist.append(g_dict)
        return gss_exist
def parse_genesets(self):
        enrichr_library = self.get_libraries()
        if isinstance(self.gene_sets, list):
            gss = self.gene_sets
        elif isinstance(self.gene_sets, str):
            gss = [ g.strip() for g in self.gene_sets.strip().split(",") ]
        elif isinstance(self.gene_sets, dict):
            gss = [self.gene_sets]
        else:
            raise Exception("Error parsing enrichr libraries, please provided corrected one")
        
        # gss: a list contain .gmt, dict, enrichr_liraries.
        # now, convert .gmt to dict
        gss_exist = [] 
        for g in gss:
            if isinstance(g, dict): 
                gss_exist.append(g)
                continue

            if isinstance(g, str): 
                if g in enrichr_library: 
                    gss_exist.append(g)
                    continue
                if g.lower().endswith(".gmt") and os.path.exists(g):
                    self._logger.info("User Defined gene sets is given: %s"%g)
                    with open(g) as genesets:
                        g_dict = { line.strip().split("\t")[0]: line.strip().split("\t")[2:]
                                        for line in genesets.readlines() }
                    gss_exist.append(g_dict)
        return gss_exist
def parse_genesets ( self ) : enrichr_library = self . get_libraries ( ) if isinstance ( self . gene_sets , list ) : gss = self . gene_sets elif isinstance ( self . gene_sets , str ) : gss = [ g . strip ( ) for g in self . gene_sets . strip ( ) . split ( "," ) ] elif isinstance ( self . gene_sets , dict ) : gss = [ self . gene_sets ] else : raise Exception ( "Error parsing enrichr libraries, please provided corrected one" ) # gss: a list contain .gmt, dict, enrichr_liraries. # now, convert .gmt to dict gss_exist = [ ] for g in gss : if isinstance ( g , dict ) : gss_exist . append ( g ) continue if isinstance ( g , str ) : if g in enrichr_library : gss_exist . append ( g ) continue if g . lower ( ) . endswith ( ".gmt" ) and os . path . exists ( g ) : self . _logger . info ( "User Defined gene sets is given: %s" % g ) with open ( g ) as genesets : g_dict = { line . strip ( ) . split ( "\t" ) [ 0 ] : line . strip ( ) . split ( "\t" ) [ 2 : ] for line in genesets . readlines ( ) } gss_exist . append ( g_dict ) return gss_exist
parse gene_sets input file type
parse gene_sets input file type