Commits

Aleš Erjavec  committed c91658a

Removed uses of obiGenomicsUpdate and obiData from obiTaxonomy.

Moved update code to server_update/updateTaxonomy.py

  • Participants
  • Parent commits 06fcc6b

Comments (0)

Files changed (2)

File orangecontrib/bio/obiTaxonomy.py

 
 from Orange.orng import orngEnviron, orngServerFiles
 
-from . import obiData, obiGenomicsUpdate
-
 # list of common organisms from http://www.ncbi.nlm.nih.gov/Taxonomy
 def common_taxids():
     """Return taxonomy IDs for common organisms."""
                                        callback=callback, verbose=verbose)
 
 
-from . import obiGenomicsUpdate
-
-class Update(obiGenomicsUpdate.Update):
-    def GetDownloadable(self):
-        return [Update.UpdateTaxonomy]
-    
-    def IsUpdatable(self, func, args):
-        from datetime import datetime
-        from . import obiData
-        if func == Update.UpdateTaxonomy:
-##            stream = urllib2.urlopen("ftp://ftp.ncbi.nih.gov/pub/taxonomy/taxdump.tar.gz")
-##            date = datetime.strptime(stream.headers.get("Last-Modified"), "%a, %d %b %Y %H:%M:%S %Z")
-            ftp = obiData.FtpWorker("ftp.ncbi.nih.gov")
-            size, date = ftp.statFtp("pub/taxonomy/taxdump.tar.gz")
-            return date > self.GetLastUpdateTime(func, args)
-
-    def UpdateTaxonomy(self):
-        Taxonomy.ParseTaxdumpFile(outputdir=self.local_database_path)
-        import tarfile
-        tFile = tarfile.open(os.path.join(self.local_database_path, "ncbi_taxonomy.tar.gz"), "w:gz")
-        tFile.add(os.path.join(self.local_database_path, "ncbi_taxonomy.db"), "ncbi_taxonomy.db")
-        tFile.add(os.path.join(self.local_database_path, "ncbi_taxonomy_inf.db"), "ncbi_taxonomy_inf.db")
-        tFile.close()
-
 if __name__ == "__main__":
     ids = search("Homo sapiens")
     print ids
     print other_names(ids[0])
-    

File server_update/updateTaxonomy.py

 from common import *
 
 from Orange.bio import obiTaxonomy
-import Orange.utils.serverfiles as orngServerFiles
-import Orange.utils.environ
 
 import tarfile
-import socket
 
 path = os.path.join(environ.buffer_dir, "tmp_Taxonomy")
-u = obiTaxonomy.Update(local_database_path=path)
+
+try:
+    os.makedirs(path)
+except OSError:
+    pass
 
 uncompressedSize = lambda filename: sum(info.size for info in tarfile.open(filename).getmembers())
 
-if u.IsUpdatable(obiTaxonomy.Update.UpdateTaxonomy, ()):
-    for i in range(3):
-        try:
-            u.UpdateTaxonomy()
-            break
-        except socket.timeout, ex:
-            print ex
-            pass
-    sf_server.upload("Taxonomy", "ncbi_taxonomy.tar.gz", os.path.join(path, "ncbi_taxonomy.tar.gz"), title ="NCBI Taxonomy",
-                       tags=["NCBI", "taxonomy", "organism names", "essential", "#uncompressed:%i" % uncompressedSize(os.path.join(path, "ncbi_taxonomy.tar.gz"))])
-    sf_server.unprotect("Taxonomy", "ncbi_taxonomy.tar.gz")
+
+obiTaxonomy.Taxonomy.ParseTaxdumpFile(outputdir=path)
+tFile = tarfile.open(os.path.join(path, "ncbi_taxonomy.tar.gz"), "w:gz")
+tFile.add(os.path.join(path, "ncbi_taxonomy.db"), "ncbi_taxonomy.db")
+tFile.add(os.path.join(path, "ncbi_taxonomy_inf.db"), "ncbi_taxonomy_inf.db")
+tFile.close()
+
+
+sf_server.upload(
+    "Taxonomy", "ncbi_taxonomy.tar.gz",
+    os.path.join(path, "ncbi_taxonomy.tar.gz"),
+    title="NCBI Taxonomy",
+    tags=["NCBI", "taxonomy", "organism names", "essential",
+          "#uncompressed:%i" % uncompressedSize(os.path.join(path, "ncbi_taxonomy.tar.gz"))]
+)
+sf_server.unprotect("Taxonomy", "ncbi_taxonomy.tar.gz")