def write_gaps_bed(inputfasta, prefix, mingap, cpus):
    from jcvi.apps.grid import WriteJobs
    from jcvi.formats.bed import sort

    bedfile = prefix + ".gaps.bed"
    f = Fasta(inputfasta)
    recs = list(rec for k, rec in f.iteritems())
    pool = WriteJobs(write_gaps_worker, recs, bedfile, cpus=cpus)
    pool.run()

    sort([bedfile, "-i"])

    bed = Bed(bedfile)
    nbedfile = prefix + ".{0}N.bed".format(mingap)

    gapnum = 0
    fw = open(nbedfile, "w")
    for b in bed:
        if mingap < b.span:
            continue
        gapnum += 1
        gapname = "gap.{0:05d}".format(gapnum)
        print >> fw, "\t".join(str(x) for x in (b, gapname, b.span))

    shutil.move(nbedfile, bedfile)
    logging.debug("Write gap (>={0}bp) locations to `{1}`.".\
                  format(mingap, bedfile))
dataset/ETHPy150Open tanghaibao/jcvi/formats/fasta.py/write_gaps_bed/swapped operands of `<`