def select_regions(localqc_table, genomeinfo, resolution, elongation=150, maxdisp=2.5):
    """
    Select regions to display based on their dispersion and their read count intensity
    :param localqc_table:   LocalQC regions file
    :param genomeinfo:      Dictionary of chromosomes' size
    :param resolution:      Total size of the desired regions (bp)
    :param elongation:      Length (bp) to stretch the region in both directions
    :param maxdisp:         Dispersion filtering (the lower the better)
    :return:                A list of regions and the total number of reads in all selected regions
    """
    regions = {}
    total_reads = []

    with open(localqc_table) as f:
        for line in f:
            cols = line.rstrip().split('\t')
            chrm = cols[0]

            # Dispersion 10% for 50% sampling
            # Use the new localqc table format (10 columns instead of 13)!
            disp = abs(float(cols[9]))

            if disp <= maxdisp and not chrm.lower().startswith(('chrx', 'chry', 'chrm')):
                total_reads.append(int(cols[3]))
                bin_start = int(cols[1])
                start = bin_start - resolution / 2 - elongation
                end = int(cols[2]) + resolution / 2 + elongation

                # Shift region start/end if it's outside of the chromosome
                if 0 <= start < end <= genomeinfo[chrm]:
                    # Region entirely in the chromosome

                    if chrm not in regions:
                        regions[chrm] = []

                    # Store chrm, start, end, reads, bin_start
                    regions[chrm].append([start, end, int(cols[3]), bin_start])

    return regions, total_reads