Changeset 1540:90209537a0e1 in orange-bioinformatics for obiKEGG2/__init__.py


Ignore:
Timestamp:
02/02/12 13:57:05 (2 years ago)
Author:
ales_erjavec
Branch:
default
Message:

Small speedup of get_enriched_pathways.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • obiKEGG2/__init__.py

    r1532 r1540  
    8585     
    8686    def get_enriched_pathways(self, genes, reference=None, prob=obiProb.Binomial(), callback=None): 
    87         """Return a dictionary with enriched pathways ids as keys and (list_of_genes, p_value, num_of_reference_genes) tuples as items.""" 
     87        """ Return a dictionary with enriched pathways ids as keys 
     88        and (list_of_genes, p_value, num_of_reference_genes) tuples  
     89        as items. 
     90         
     91        """ 
    8892        allPathways = defaultdict(lambda :[[], 1.0, []]) 
    8993        import orngMisc 
     
    9195        pathways_db = KEGGPathways() 
    9296         
     97        pathways_for_gene = [] 
    9398        for i, gene in enumerate(genes): 
    94             pathways = self.pathways([gene]) 
    95             pathways_db.pre_cache(pathways) 
     99            pathways_for_gene.append(self.pathways([gene])) 
     100            if callback and i in milestones: 
     101                callback(i*50.0/len(genes)) 
     102                 
     103        # precache for speed  
     104        pathways_db.pre_cache([pid for pfg in pathways_for_gene for pid in pfg])  
     105        for i, (gene, pathways) in enumerate(zip(genes, pathways_for_gene)): 
    96106            for pathway in pathways: 
    97107                if pathways_db.get_entry(pathway).gene:  
    98108                    allPathways[pathway][0].append(gene) 
    99109            if callback and i in milestones: 
    100                 callback(i*50.0/len(genes)) 
     110                callback(50.0 + i*50.0/len(genes)) 
    101111        reference = set(reference if reference is not None else self.genes.keys()) 
    102112         
Note: See TracChangeset for help on using the changeset viewer.