Changeset 1539:4d0cb852d2cd in orange-bioinformatics for obiKEGG2/api.py


Ignore:
Timestamp:
02/02/12 13:52:00 (2 years ago)
Author:
ales_erjavec
Branch:
default
Message:

If the batch has invalid ids try bisection of the ids.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • obiKEGG2/api.py

    r1532 r1539  
    408408                 
    409409        if uncached: 
     410            # in case there are duplicate ids 
     411            uncached = sorted(set(uncached)) 
    410412            rval = KeggApi.bget(self, uncached) 
    411413            if rval is not None: 
     
    418420                del entrys[-1] 
    419421             
    420 #            if len(entrys) != len(uncached): 
    421 #                raise ValueError("Batch contains invalid ids") 
    422          
    423             with closing(bget.cache_store()) as store: 
    424                 for id, entry in zip(uncached, entrys): 
    425                     key = bget.key_from_args((id,)) 
    426                     if entry is not None: 
    427                         entry = entry + "///\n" 
    428                     store[key] = cache_entry(entry, mtime=datetime.now()) 
     422            if len(entrys) == len(uncached): 
     423                with closing(bget.cache_store()) as store: 
     424                    for id, entry in zip(uncached, entrys): 
     425                        key = bget.key_from_args((id,)) 
     426                        if entry is not None: 
     427                            entry = entry + "///\n" 
     428                        store[key] = cache_entry(entry, mtime=datetime.now()) 
     429                         
     430            else: 
     431                # Try to bisect the uncached list 
     432                if len(uncached) > 1 and len(uncached) - len(entrys) < 4: 
     433                    split = len(uncached) / 2 
     434                    self._batch_bget(uncached[:split]) 
     435                    self._batch_bget(uncached[split:]) 
     436                else: 
     437                    import warnings 
     438                    warnings.warn("Batch contains invalid ids", UserWarning) 
    429439         
    430440        # Finally join all the results, but drop all None objects 
Note: See TracChangeset for help on using the changeset viewer.