<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def read_bed(file_path, restricted_genes=None):
 """Reads BED file and populates a dictionary separating genes by chromosome. Parameters file_path : str path to BED file filtered_genes: list list of gene names to not use Returns ------- bed_dict: dict dictionary mapping chromosome keys to a list of BED lines """

    # read in entire bed file into a dict with keys as chromsomes
    bed_dict = OrderedDict()
    for bed_row in bed_generator(file_path):
        is_restrict_flag = restricted_genes is None or bed_row.gene_name in restricted_genes
        if is_restrict_flag:
            bed_dict.setdefault(bed_row.chrom, [])
            bed_dict[bed_row.chrom].append(bed_row)
    sort_chroms = sorted(bed_dict.keys(), key=lambda x: len(bed_dict[x]), reverse=True)
    bed_dict = OrderedDict((chrom, bed_dict[chrom]) for chrom in sort_chroms)
    return bed_dict