Changeset 1356:a531fa6d7ae4 in orange-bioinformatics


Ignore:
Timestamp:
03/28/11 14:36:42 (3 years ago)
Author:
ales_erjavec <ales.erjavec@…>
Branch:
default
Convert:
7cf99b1111ac58f0803ffad37f4a30f5af7217f8
Message:

Added listdir method to obiData.FtpDownloader.
Use listdir in obiKEGG.KEGGPathway.download_pathways to get a list of all pathways for organism.

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • obiData.py

    r1343 r1356  
    33import urllib, urllib2 
    44import threading 
    5 import os 
     5import os, sys 
    66import time 
    77import socket 
     
    182182        stat = os.stat(filename) 
    183183        return stat.st_size, datetime.fromtimestamp(stat.st_mtime) 
     184     
     185    def listdir(self, ftp_dir): 
     186        """ List the contents of a remote ftp directory (similar to os.listdir) 
     187        """ 
     188        if not self.ftp: 
     189            self.connect() 
     190        lines = [] 
     191        self.ftp.dir(ftp_dir, lines.append) 
     192        self.statCache[dir] = dict([(line.split()[-1].strip(), line.strip()) for line in lines if line.strip()]) 
     193        contents = [line.split()[-1] for line in lines] 
     194        return [name for name in contents if name not in [".", ".."]]  
     195         
    184196 
    185197class FtpThreadWorker(threading.Thread, FtpWorker): 
     
    192204        while True: 
    193205            filename, local, update, retryCount, progressCallback = self.queue.get() 
    194             self.retrieve(filename, local, update, progressCallback) 
     206            try: 
     207                self.retrieve(filename, local, update, progressCallback) 
     208            except Exception, ex: 
     209                sys.excepthook(*sys.exc_info()) 
    195210            self.queue.task_done() 
    196211 
     
    252267            time.sleep(0.1) 
    253268        self.queue.join() 
    254  
    255 ##class HTTPDownloader(DownloaderBase): 
    256 ##    def __init__(self, *args, **kwargs): 
    257 ##        DownloaderBase.__init__(self, *args, **kwargs) 
    258 ## 
    259 ##    def retrieve(self, filename): 
    260 ##         
     269         
     270    def listdir(self, ftp_dir): 
     271        """ List the contents of the remote ftp dir (similar to os.listdir) 
     272        """ 
     273        return self.ftpWorker.listdir(self.ftpDir + ftp_dir) 
     274     
  • obiKEGG.py

    r1348 r1356  
    1 """obiKEGG is an interface to Kyoto Encyclopedia of Genes and Genomes (http://www.genome.jp/kegg/) that allows easy access to KEGG pathway and genes data. 
    2  
     1""" 
     2======= 
     3obiKEGG 
     4======= 
     5obiKEGG module is an interface to `Kyoto Encyclopedia of Genes and Genomes 
     6<http://www.genome.jp/kegg/>`_ that allows easy access to KEGG pathway 
     7and genes data. 
     8 
     9Example :: 
     10     
     11    >>> genes = KEGGOrganism("human") 
     12    >>> genes 
    313""" 
    414try: 
     
    10191029        ftp = FtpDownloader("ftp.genome.jp", _join(), "pub/kegg/", numOfThreads=15) 
    10201030        ftp.massRetrieve([png_path + pathway + ".png" for pathway in pathways]) 
     1031             
    10211032        if org != "map" : 
    1022             ftp.massRetrieve([xml_path + pathway + ".xml" for pathway in pathways]) 
    1023             ftp.massRetrieve([xml_path.replace("metabolic", "non-metabolic") + pathway + ".xml" for pathway in pathways])  
     1033            pathways = ftp.listdir(xml_path) 
     1034            pathways = [p for p in pathways if p.endswith(".xml")] 
     1035            ftp.massRetrieve([xml_path + pathway for pathway in pathways]) 
     1036            if org not in ["ec", "rn"]: # Add non-metabolic pathways to the download list 
     1037                xml_path = xml_path.replace("metabolic", "non-metabolic") 
     1038                pathways = ftp.listdir(xml_path) 
     1039                pathways = [p for p in pathways if p.endswith(".xml")]  
     1040                ftp.massRetrieve([xml_path + pathway for pathway in pathways]) 
    10241041        ftp.massRetrieve([png_path + org + ".list"]) 
    10251042        return [] 
Note: See TracChangeset for help on using the changeset viewer.