Changeset 303:f07b0f2805f7 in orange-bioinformatics


Ignore:
Timestamp:
05/19/08 12:47:24 (6 years ago)
Author:
ales_erjavec <ales.erjavec@…>
Branch:
default
Convert:
3e4e874d50e60f841e74663e3184608a6bf165a2
Message:

-added Update class to orngKEGG

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • orngGenomicsUpdate.py

    r301 r303  
    11import shelve 
    2 import DateTime 
     2import datetime 
     3 
     4from functools import wraps 
    35 
    46class Update(object): 
     
    68        self.local_database_path = local_database_path 
    79        self.progressCallback = progressCallback 
    8         self.shelve = shelve.open(self.local_database_path+"updates.shelve") 
     10        self.shelve = shelve.open(self.local_database_path+"//updates.shelve") 
    911 
    1012    def GetUpdatable(self): 
     
    1517     
    1618    def GetLastUpdateTime(self, callable, args): 
    17         return self.shelve.get((callable, args), None) 
     19        return self.shelve.get(str((callable.func_name, args)), None) 
    1820 
    1921    def _update(self, callable, args): 
    20         self.shelve[(callable, args)] = DateTime.DateTime.now() 
     22        self.shelve[str((callable.func_name, args))] = datetime.datetime.now() 
     23 
     24    @classmethod 
     25    def _auto_updater(cls, f): 
     26        @wraps(f) 
     27        def mywrapper(self, *args): 
     28            r = f(self, *args) 
     29            self._update(f, args) 
     30            return r 
     31        return mywrapper 
     32         
    2133     
    2234     
  • orngKEGG.py

    r295 r303  
    256256                           "_compounds":"ligand/compound/_compounds.pickle", 
    257257                           "_from_enzyme_to_compounds":"ligand/compound/_from_enzyme_to_compounds.pickle"} 
    258         self.downloader = orngData.FtpDownloader("ftp.genome.jp", self.local_database_path, "/pub/kegg/", numOfThreads=1) 
     258        self.downloader = orngData.FtpDownloader("ftp.genome.jp", self.local_database_path, "/pub/kegg/", numOfThreads=10) 
    259259 
    260260    def download_organism_data(self, org): 
     
    285285            time.sleep(0.1) 
    286286 
     287    def download_reference_data(self): 
     288        rel_path = "pathway/map/" 
     289        descr = dict(map(lambda line:tuple(line.strip().split("\t")), self._retrieve("pathway/map_title.tab").readlines())) 
     290        ends = [".conf", ".gif", ".map"] 
     291        files = [rel_path+"map"+pathNum+ext for pathNum in descr.keys() for ext in ends] 
     292        self.downloader.massRetrieve(files, progressCallback=self.download_progress_callback) 
     293         
    287294    def __getattr__(self, name): 
    288295        if name=="_enzymes" or name=="_from_gene_to_enzymes" : 
     
    752759        self.ko_class_id = self.class_name[:5] 
    753760 
     761import orngGenomicsUpdate 
     762 
     763class Update(orngGenomicsUpdate.Update): 
     764    def __init__(self, local_database_path=None, progressCallback=None): 
     765        orngGenomicsUpdate.Update.__init__(self, local_database_path, progressCallback) 
     766        self.api = KEGGInterfaceLocal(True, local_database_path, progressCallback) 
     767 
     768    def GetUpdatable(self): 
     769        orgs = [org for org in self.api.list_organisms() if str((Update.UpdateOrganism.im_func.func_name, (org,))) in self.shelve] 
     770        return [(self.UpdateOrganism, "Update organism pathways and genes" , orgs), 
     771                (self.UpdateReference, "Update reference pathways", []), 
     772                (self.UpdateEnzymeAndCompounds, "Update enzyme and compounds", [])] 
     773         
     774 
     775    def GetDownloadable(self): 
     776        orgs = [org for org in self.api.list_organisms() if str((Update.UpdateOrganism.im_func.func_name, (org,))) not in self.shelve] 
     777        return [(self.UpdateOrganism, "Update organism pathways and genes" , orgs), 
     778                (self.UpdateReference, "Update reference pathways", []), 
     779                (self.UpdateEnzymeAndCompounds, "Update enzyme and compounds", [])] 
     780 
     781    @orngGenomicsUpdate.Update._auto_updater 
     782    def UpdateOrganism(self, org): 
     783        self.api.download_organism_data(org) 
     784 
     785    @orngGenomicsUpdate.Update._auto_updater 
     786    def UpdateReference(self): 
     787        self.api.download_reference_data() 
     788         
     789    @orngGenomicsUpdate.Update._auto_updater 
     790    def UpdateEnzymeAndCompounds(self): 
     791        self.api.massDownloader.retrieve(["ligand//compound//compound", "ligand/enzyme/enzyme"], progressCallback=self.progressCallback) 
    754792 
    755793if __name__=="__main__": 
Note: See TracChangeset for help on using the changeset viewer.