code: def picard_bam_to_fastq(picard, in_bam, fastq_one, fastq_two=None):
      
      if not file_exists(fastq_one):
          with tx_tmpdir(picard._config) as tmp_dir:
              with file_transaction(picard._config, fastq_one) as tx_out1:
                  opts = [("INPUT", in_bam),
                          ("FASTQ", tx_out1),
                          ("TMP_DIR", tmp_dir)]
                  if fastq_two is not None:
                      opts += [("SECOND_END_FASTQ", fastq_two)]
                  picard.run("SamToFastq", opts)
      return (fastq_one, fastq_two)
docs: Convert BAM file to fastq.