def sample(self, wig, resolution):
        """Sample a wig file at the given resolution. 
        
        Parameters:
        1. wig: a wig object (see inout.py)
        2. resolution: sampling resolution
        
        Return:
        sampWig: the sampled wig object
        
        """
        
        # parameter checking
            
        try:
            chroms=wig.get_chroms()
        except AttributeError:
            raise Exception("Argument 'wig' must be given")
        
        sampWig=Wig()
        for chrom in chroms:
            try:
                standardchrom=self.standard_chroms[chrom]
            except KeyError:
                standardchrom=chrom
            
            try:
                start  = wig[chrom][0][0]
                end = wig[chrom][0][-1]
            except IndexError:
                continue
            
            samp=[array('l',[]),array('d',[])]
            cor = wig[chrom][0]
            val = wig[chrom][1]
            init = 0
            prev = -1000
            for sc in xrange(start, end, resolution):
                # get the closest one to the sampled point and save
                gotya = bisect_left(cor[init:], sc)
                
                if prev == (init+gotya): continue
                else: prev = (init+gotya)
                
                try:
                    samp[0].append(cor[init+gotya])
                    samp[1].append(val[init+gotya])
                    init += gotya
                except __HOLE__:
                    continue
        
            #added to sampWig only if there are some point(s)
            if samp[0]: sampWig.wig[standardchrom]=samp
                
        return sampWig
dataset/ETHPy150Open taoliu/taolib/Assoc/sampler.py/WigSamplerFast.sample