Changeset 16015

Show
Ignore:
Timestamp:
05/30/12 10:36:57 (13 months ago)
Author:
coissac
Message:
 
Location:
trunk/src
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/obitools/sample.py

    r14635 r16015  
    44@author: coissac 
    55''' 
    6 from random import shuffle, randrange 
     6from random import shuffle, randrange, sample 
     7from obitools.utils import Counter 
     8import random 
    79 
    810def lookfor(x,cumsum): 
     
    5355 
    5456def weigthedSampleWithoutReplacement(events,size): 
    55     entries = [k for k in events.iterkeys() if events[k]>0] 
    56     shuffle(entries) 
    57     cumul=[] 
     57    # entries = [k for k in events.iterkeys() if events[k]>0] 
     58    entries = events.keys() 
     59    cumul=[0] * len(entries) 
    5860    s=0 
     61    i=0 
    5962    for e in entries: 
    6063        s+=events[e] 
    61         cumul.append(s) 
     64        cumul[i]=s 
     65        i+=1 
    6266     
    63     #print cumul 
    64     result={} 
     67    c = random.sample(xrange(s),size) 
     68    c.sort() 
    6569     
    66     for t in xrange(size): 
    67         # print s,cumul, 
    68         e=lookfor(randrange(s), cumul) 
    69         # print e 
    70         k=entries[e] 
    71         for x in xrange(e,len(cumul)): 
    72             cumul[x]-=1 
    73         s-=1 
    74         result[k]=result.get(k,0)+1 
     70    i = 0 
     71    for j in xrange(len(c)): 
     72        v = c[j] 
     73        while (v > cumul[i]): 
     74            i+=1 
     75        c[j]=entries[i] 
     76         
     77    result=Counter(c) 
    7578 
    7679    return result 
  • trunk/src/obitools/utils/__init__.py

    r15764 r16015  
    1616from _utils import progressBar 
    1717 
     18from collections import Counter 
    1819 
    1920 
  • trunk/src/obiuniq.py

    r15764 r16015  
    1515                             type="string", 
    1616                             default=[], 
    17                              help="ecoPCR taxonomy Database " 
    18                                   "name") 
     17                             help="attributes to merge") 
    1918     
    2019    optionManager.add_option('-c','--category-attribute',