Commits

Aleš Erjavec committed 9226929

Removed unneeded imports, fixed some errors.

Comments (0)

Files changed (1)

obiKEGG2/__init__.py

 """
 from __future__ import absolute_import
 
-import urllib2
 
 import os, sys
-from functools import wraps, partial
 from collections import defaultdict
 
-import re
 from datetime import datetime
 
 from Orange.misc import lru_cache, serverfiles
         return enzyme.genes.get(self.org_code, []) if enzyme.genes else []
     
     def get_genes_by_pathway(self, pathway_id):
-        return Pathway(pathway_id).genes()
+        return KEGGPathway(pathway_id).genes()
     
     def get_enzymes_by_pathway(self, pathway_id):
-        return Pathway(pathway_id).enzymes()
+        return KEGGPathway(pathway_id).enzymes()
     
     def get_compounds_by_pathway(self, pathway_id):
-        return Pathway(pathway_id).compounds()
+        return KEGGPathway(pathway_id).compounds()
     
     def get_pathways_by_genes(self, gene_ids):
         return self.api.get_pathways_by_genes(gene_ids)
 def from_taxid(taxid):
     genome = KEGGGenome()
     res = genome.search(taxid)
+    print taxid, res
     for r in res:
         e = genome[r]
-        if e.taxid == taxid:
+        
+        if e.taxid in [taxid,  genome.TAXID_MAP.get(taxid, taxid)]:
             return e.org_code()
         
     return None
 
 class MatcherAliasesKEGG(obiGene.MatcherAliasesPickled):
     DOMAIN = "KEGG"
+    VERSION = "v3.0"
     def create_aliases(self):
-        files = set(serverfiles.listfiles(self.DOMAIN))
-        ids_filename = "gene_matcher_kegg_ids_" + self.organism + ".pickle"
+        import cPickle
+        files = set(serverfiles.ServerFiles().listfiles(self.DOMAIN))
+        ids_filename = "kegg_gene_id_aliases_" + self.organism + ".pickle"
         if ids_filename in files:
             filename = serverfiles.localpath_download(self.DOMAIN, ids_filename)
-            import cPickle
+            
             aliases = cPickle.load(open(filename, "rb"))
         else:
             pb = ConsoleProgressBar("Retriving KEGG ids:")
             aliases = []
             for key, entry in genes.iteritems():
                 aliases.append(set([key]) | set(entry.alt_names))
+            filename = serverfiles.localpath_download(self.DOMAIN, ids_filename)
+            cPickle.dump(aliases, open(filename, "wb"))
+            
         return aliases
     
     def filename(self):
         return "kegg3_" + self.organism
     
+    def aliases_path(self):
+        ids_filename = "kegg_gene_id_aliases_" + self.organism + ".pickle"
+        return serverfiles.localpath(self.DOMAIN, ids_filename)
+    
     def create_aliases_version(self):
         files = set(serverfiles.listfiles(self.DOMAIN))
-        ids_filename = "gene_matcher_kegg_ids_" + self.organism + ".pickle"
+        ids_filename = "kegg_gene_id_aliases_" + self.organism + ".pickle"
         if ids_filename in files:
             version = serverfiles.info(self.DOMAIN, ids_filename)["datetime"]
         else:
         self.organism = organism
         sf = serverfiles.ServerFiles()
         files = set(sf.listfiles(self.DOMAIN))
-        ids_filename = "gene_matcher_kegg_ids_" + self.organism + ".pickle"
+        ids_filename = "kegg_gene_id_aliases_" + self.organism + ".pickle"
         if ids_filename in files:
             serverfiles.update(self.DOMAIN, ids_filename)
             
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.