def parse_bed(bed_file):
    """Import a BED file (where the data entries are analogous to what may be
    expected in an info_frags.txt file) and return a scaffold dictionary,
    similarly to parse_info_frags.
    """

    new_scaffolds = {}
    with open(bed_file) as bed_handle:
        for line in bed_handle:
            chrom, start, end, query, qual, strand = line.split()[:7]
            if strand == "+":
                ori = 1
            elif strand == "-":
                ori = -1
            else:
                raise ValueError(
                    "Error when parsing strand "
                    "orientation: {}".format(strand)
                )

            if int(qual) > 0:
                bed_bin = [query, -2, int(start), int(end), ori]
                try:
                    new_scaffolds[chrom].append(bed_bin)
                except KeyError:
                    new_scaffolds[chrom] = [bed_bin]

    return new_scaffolds
def parse_bed ( bed_file ) : new_scaffolds = { } with open ( bed_file ) as bed_handle : for line in bed_handle : chrom , start , end , query , qual , strand = line . split ( ) [ : 7 ] if strand == "+" : ori = 1 elif strand == "-" : ori = - 1 else : raise ValueError ( "Error when parsing strand " "orientation: {}" . format ( strand ) ) if int ( qual ) > 0 : bed_bin = [ query , - 2 , int ( start ) , int ( end ) , ori ] try : new_scaffolds [ chrom ] . append ( bed_bin ) except KeyError : new_scaffolds [ chrom ] = [ bed_bin ] return new_scaffolds
Import a BED file (where the data entries are analogous to what may be
    expected in an info_frags.txt file) and return a scaffold dictionary,
    similarly to parse_info_frags.