def histogram(self, breaks, chrom=''):
        """Return a histogram as a dictionary of {'bin':[], 'count':[]}
        
        Parameters:
        1. breaks: this can be a list (bins) or an integer (number of bins). If integer, it will be split the range from min to max to 'breaks' bins.
        2. chrom: if NULL string, return the histogram of the whole WIG.
        
        WARNING: this method might take too much memory if the Wig object is large.
        """
        
        if type(breaks)==list:      # if bins are given
            histogram = {'bin':breaks[:-1]}
            if chrom:
                try:
                    histogram['count']=bin(self[chrom][1], breaks)
                    return histogram
                except __HOLE__:
                    return None
            else:
                w = []
                for chrom in self.get_chroms():
                    w += self[chrom][1]
                histogram['count'] = bin(w, breaks)
                
                return histogram
                
        elif type(breaks)==int: # only number of bins are given
            histogram = {}
            if chrom:
                min_this_chr = self.min(chrom)
                max_this_chr = self.max(chrom)
                
                bins = linspace(min_this_chr, max_this_chr, breaks+1)
                histogra['bin'] = bins[:-1]
                try:
                    histogram['count'] = bin(self[chrom][1], bins)
                    return histogram
                except KeyError:
                    return None   
            else:
                w = []
                for chrom in self.get_chroms():
                    w += self[chrom][1]
                min_all = min(w)
                max_all = max(w)
                
                bins = linspace(min_this_chr, max_this_chr, breaks+1)
                histogram['bin'] = bins
                histogram['count'] = bin(w, bins)
                return histogram
        else:
            return None
dataset/ETHPy150Open taoliu/taolib/Assoc/inout.py/Wig.histogram