def get_histogram_BED_scores(bed, breaks, chrom=''):
    """Get the histogram of bed scores
    
    Parameters:
    1. bed: a Bed object
    2. breaks: bins for the histogram
    """
    
    # if no chroms, just return None
    chroms = bed.get_chroms()
    if not chroms: return {}
    
    # if any of chroms does not have 'score', just return None
    YESSCORE = True
    for chrom in chroms:
        YESSCORE = YESSCORE and bed[chrom].has_key('score')
    if not YESSCORE: return {}
    
    
    if type(breaks)==list:      # if bins are given
        histogram = {'bin':breaks[:-1]}
        if chrom:
            try:
                histogram['count']=bin(bed[chrom]['score'], breaks)
            except __HOLE__:
                histogram = {}
        else:
            w = []
            for chrom in chroms:
                try:
                    w += bed[chrom]['score']
                except KeyError:
                    pass
            try:
                histogram['count'] = bin(w, breaks)
            except:
                histogram = {}
                
        return histogram
                
    elif type(breaks)==int: # only number of bins are given
        histogram = {}
        if chrom:
            try:
                min_this_chr = min(bed[chrom]['score'])
                max_this_chr = max(bed[chrom]['score'])
            except KeyError:
                return {}
                
            try:
                bins = linspace(min_this_chr, max_this_chr, breaks+1)
                histogra['bin'] = bins[:-1]
                histogram['count'] = bin(bed[chrom]['score'], bins)
                return histogram
            except:
                return {}
               
        else:
            w = []
            for chrom in chroms:
                try:
                    w += bed[chrom]['score']
                except KeyError:
                    pass
        
            try:   
                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
            except:
                return {}
    else:
        return {}
dataset/ETHPy150Open taoliu/taolib/Assoc/inout.py/get_histogram_BED_scores