code: def picard_formatconverter(picard, align_sam):
      
      out_bam = "%s.bam" % os.path.splitext(align_sam)[0]
      if not file_exists(out_bam):
          with tx_tmpdir(picard._config) as tmp_dir:
              with file_transaction(picard._config, out_bam) as tx_out_bam:
                  opts = [("INPUT", align_sam),
                          ("OUTPUT", tx_out_bam),
                          ("TMP_DIR", tmp_dir)]
                  picard.run("SamFormatConverter", opts)
      return out_bam
docs: Convert aligned SAM file to BAM format.