Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • orangecontrib/bio/obiGeneSets.py

    r1873 r1877  
    2323 
    2424from Orange.bio.geneset import GeneSet, GeneSets, GenesetRegException 
     25 
     26class NoGenesetsException(Exception): pass 
    2527 
    2628def goGeneSets(org): 
     
    360362 
    361363def load_local(hierarchy, organism): 
    362     files = map(lambda x: x[:2], list_local()) 
    363     hierd = build_hierarchy_dict(files) 
    364  
    365     out = GeneSets() 
    366     for (h, o) in [ files[i] for i in hierd[(hierarchy, organism)]]: 
    367         fname = os.path.join(local_path(), filename(h, o)) 
    368         out.update(pickle.load(open(fname, 'r'))) 
    369     return out 
     364    return load_fn(hierarchy, organism, list_local,  
     365        lambda h,o: os.path.join(local_path(), filename(h, o))) 
    370366 
    371367def load_serverfiles(hierarchy, organism): 
    372     files = map(lambda x: x[:2], list_serverfiles()) 
     368    return load_fn(hierarchy, organism, list_serverfiles,  
     369        lambda h,o: orngServerFiles.localpath_download(sfdomain, filename(h, o))) 
     370 
     371def load_fn(hierarchy, organism, fnlist, fnget): 
     372    files = map(lambda x: x[:2], fnlist()) 
    373373    hierd = build_hierarchy_dict(files) 
    374374    out = GeneSets() 
     375    matches = hierd[(hierarchy, organism)] 
     376    if not matches: 
     377        exstr = "No gene sets for " + str(hierarchy) + \ 
     378                " (org " + str(organism) + ")" 
     379        raise NoGenesetsException(exstr) 
    375380    for (h, o) in [ files[i] for i in hierd[(hierarchy, organism)]]: 
    376         fname = orngServerFiles.localpath_download(sfdomain, 
    377             filename(h, o)) 
     381        fname = fnget(h, o) 
    378382        out.update(pickle.load(open(fname, 'r'))) 
    379383    return out 
     
    382386    """ First try to load from the local registred folder. If the file 
    383387    is not available, load it from the server files. """ 
    384     ret = load_local(hierarchy, organism) 
    385     if len(ret) == 0: 
    386         ret.update(load_serverfiles(hierarchy, organism)) 
    387     return ret 
     388    try: 
     389        return load_local(hierarchy, organism) 
     390    except NoGenesetsException: 
     391        return load_serverfiles(hierarchy, organism) 
    388392 
    389393def collections(*args): 
Note: See TracChangeset for help on using the changeset viewer.