def get_percent_from_BED(bed, percentage, twoside=False):
    """Get the lower and upper bondaries of scores given a percentage
    
    Parameters:
    1. bed: a bed object
    2. percentage: integer from 0 to 100
    3. twosided: If True, get the middle part of scores within the percentage; otherwise, started with the lowest score.
    
    WARNING: bed must have 'score'; otherwise, just [] will be returned.
    WARNING: there must be an enough number of elements
    """
    
    # 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 []
    
    # put percentage into the right range
    percentage = min(100, percentage)
    percentage = max(0, percentage)
    
    # concatenate the scores and sort
    scores = []
    for chrom in chroms:
        scores += bed[chrom]['score']
    scores.sort()
    
    l = len(scores)
    if twoside:
        left = int(((100-percentage)/200.0)*(l-1))
        right = l - left
    else:
        left = 0
        right = int((100.0/percentage)*(l-1))
    
    return scores[left], scores[right]
dataset/ETHPy150Open taoliu/taolib/Assoc/inout.py/get_percent_from_BED/swapped operands of `/`