code: def fasta(args):
      
      from jcvi.formats.sizes import Sizes
  
      p = OptionParser(fasta.__doc__)
      p.add_option("--extend", default=1000, type="int",
                   help="Extend seq flanking the gaps [default: %default]")
      opts, args = p.parse_args(args)
  
      if len(args) != 2:
          sys.exit(not p.print_help())
  
      mapout, sfasta = args
      Flank = opts.extend
      pf = mapout.split(".")[0]
      mapbed = pf + ".bed"
      bm = BinMap(mapout)
      bm.print_to_bed(mapbed)
  
      bed = Bed(mapbed, sorted=False)
      markersbed = pf + ".markers.bed"
      fw = open(markersbed, "w")
      sizes = Sizes(sfasta).mapping
      for b in bed:
          accn = b.accn
          scf, pos = accn.split(".")
          pos = int(pos)
          start = max(0, pos - Flank)
          end = min(pos + Flank, sizes[scf])
          print("\t".join(str(x) for x in \
                      (scf, start, end, accn)), file=fw)
  
      fw.close()
  
      fastaFromBed(markersbed, sfasta, name=True)
docs: %prog fasta map.out scaffolds.fasta
  
      Extract marker sequences based on map.