code: def run_mrtrans(align_fasta, recs, work_dir, outfmt="paml"):
      
      align_file = op.join(work_dir, "prot-align.fasta")
      nuc_file = op.join(work_dir, "nuc.fasta")
      output_file = op.join(work_dir, "nuc-align.mrtrans")
  
      # make the prot_align file and nucleotide file
      align_h0 = open(align_file + "0", "w")
      align_h0.write(str(align_fasta))
      align_h0.close()
      prot_seqs = {}
      i = 0
      for rec in SeqIO.parse(align_h0.name, "fasta"):
          prot_seqs[i] = rec.seq
          i += 1
      align_h = open(align_file, "w")
      for i, rec in enumerate(recs):
          if len(rec.id) > 30:
              rec.id = rec.id[:28] + "_" + str(i)
              rec.description = ""
          print(">{0}\n{1}".format(rec.id, prot_seqs[i]), file=align_h)
      align_h.close()
      SeqIO.write(recs, file(nuc_file, "w"), "fasta")
  
      # run the program
      cl = MrTransCommandline(align_file, nuc_file, output_file, outfmt=outfmt)
      r, e = cl.run()
      if e is None:
          print("\tpal2nal:", cl, file=sys.stderr)
          return output_file
      elif e.read().find("could not translate") >= 0:
          print("***pal2nal could not translate", file=sys.stderr)
          return None
docs: Align nucleotide sequences with mrtrans and the protein alignment.