Commits

Marko Toplak  committed e58b015

obiKEGG: added pathway search by genes.

  • Participants
  • Parent commits 4a6f881

Comments (0)

Files changed (2)

File orangecontrib/bio/obiKEGG/__init__.py

         return KEGGPathway(pathway_id).compounds()
 
     def get_pathways_by_genes(self, gene_ids):
-        return self.api.get_pathways_by_genes(gene_ids)
+        """ Pathways that include all genes in gene_ids. """
+        l = self.api.get_genes_pathway_organism(self.org_code)
         gene_ids = set(gene_ids)
-        pathways = [self.genes[id].pathway for id in gene_ids
-                    if self.genes[id].pathway]
-        pathways = reduce(set.union, pathways, set())
-        return [id for id in pathways
-                if gene_ids.issubset(KEGGPathway(id).genes())]
+        gtp = defaultdict(set)
+        for a,b in l:
+            gtp[a].add(b)
+        pathways = [ gtp[g] for g in gene_ids ]
+        pathways = reduce(set.intersection, pathways)
+        return sorted(pathways)
 
     def get_pathways_by_enzymes(self, enzyme_ids):
         enzyme_ids = set(enzyme_ids)

File orangecontrib/bio/obiKEGG/api.py

     def get_kos_by_pathway(self, pathway_id):
         return _link_targets(self.link("ko", ids=[pathway_id]))
 
+    #############################################
+    # Pathways and genes of a specific organism #
+    #############################################
+
+    def get_genes_pathway_organism(self, organism):
+        l = self.link("pathway", organism)
+        return map(tuple, l)
+
     #####################
     # Pathways by objects
     #####################
     def get_kos_by_pathway(self, pathway_id):
         return KeggApi.get_kos_by_pathway(self, pathway_id)
 
+    @cached_method
+    def get_genes_pathway_organism(self, org):
+        return KeggApi.get_genes_pathway_organism(self, org)
+
+
 
 def match_by_ids(ids, entries):
     """