code: def align(args):
      
      valid_modes = ("bwasw", "aln", "mem")
      p = OptionParser(align.__doc__)
      p.add_option("--mode", default="mem", choices=valid_modes, help="BWA mode")
      set_align_options(p)
      p.set_sam_options()
  
      opts, args = p.parse_args(args)
      mode = opts.mode
      nargs = len(args)
  
      if nargs not in (2, 3):
          sys.exit(not p.print_help())
  
      tag = "bwa-{0}: ".format(mode)
      c = mem
      if nargs == 2:
          tag += "Single-end alignment"
          if mode == "bwasw":
              c = bwasw
          elif mode == "aln":
              c = samse
      else:
          assert mode != "bwasw", "Cannot use --bwasw with paired-end mode"
          tag += "Paired-end alignment"
          if mode == "aln":
              c = sampe
  
      logging.debug(tag)
      cmd, samfile = c(args, opts)
      if cmd:
          cmd = output_bam(cmd, samfile)
  
      bam = opts.bam
      unmapped = opts.unmapped
  
      sh(cmd)
      if unmapped:
          dbfile, readfile = args[:2]
          mopts = [samfile, "--unmapped"]
          if not bam:
              mopts += ["--sam"]
          mapped(mopts)
          FileShredder([samfile])
  
      return samfile, None
docs: %prog align database.fasta read1.fq [read2.fq]
  
      Wrapper for three modes of BWA - mem (default), aln, bwasw (long reads).