code: def _piped_bamprep_region_gatk(data, region, prep_params, out_file, tmp_dir):
      
      broad_runner = broad.runner_from_config(data["config"])
      cur_bam, cl = _piped_input_cl(data, region, tmp_dir, out_file, prep_params)
      if not prep_params["realign"]:
          prerecal_bam = None
      elif prep_params["realign"] == "gatk":
          prerecal_bam, cl = _piped_realign_gatk(data, region, cl, out_file, tmp_dir,
                                                 prep_params)
      else:
          raise NotImplementedError("Realignment method: %s" % prep_params["realign"])
      with file_transaction(data, out_file) as tx_out_file:
          out_flag = ("-o" if (prep_params["realign"] == "gatk"
                               or not prep_params["realign"])
                      else ">")
          cmd = "{cl} {out_flag} {tx_out_file}".format(**locals())
          do.run(cmd, "GATK: realign {0}".format(region), data)
          _cleanup_tempfiles(data, [cur_bam, prerecal_bam])
docs: Perform semi-piped BAM preparation using Picard/GATK tools.