code: def batch(args):
      
      p = OptionParser(batch.__doc__)
      set_align_options(p)
      p.set_sam_options()
      opts, args = p.parse_args(args)
  
      if len(args) != 3:
          sys.exit(not p.print_help())
  
      ref_fasta, proj_dir, outdir = args
      outdir = outdir.rstrip("/")
      s3dir = None
      if outdir.startswith("s3://"):
          s3dir = outdir
          outdir = op.basename(outdir)
          mkdir(outdir)
  
      mm = MakeManager()
      for p, pf in iter_project(proj_dir):
          targs = [ref_fasta] + p
          cmd1, bamfile = mem(targs, opts)
          if cmd1:
              cmd1 = output_bam(cmd1, bamfile)
          nbamfile = op.join(outdir, bamfile)
          cmd2 = "mv {} {}".format(bamfile, nbamfile)
          cmds = [cmd1, cmd2]
  
          if s3dir:
              cmd = "aws s3 cp {} {} --sse".format(nbamfile,
                                                op.join(s3dir, bamfile))
              cmds.append(cmd)
  
          mm.add(p, nbamfile, cmds)
  
      mm.write()
docs: %proj batch database.fasta project_dir output_dir
  
      Run bwa in batch mode.