input: Write a function to calculate the percent of transcripts mapping to rRNA and MT genes from an HTseq_counts file. The function should take two inputs: an HTseq_counts file and a GTF (Gene Transfer Format) file. It should return a dictionary containing the total number of rRNA and MT transcripts found, as well as the percentage of reads mapped to these transcripts. If either file does not exist, the function should raise a FileNotFoundError. The function should also produce an output file named "HTseq_counts_file_rRNAmtRNACounts.txt" containing the summary of the mapping results.
  assert calculate_rRNA_MT_percent("/path/to/HTseq_counts/file", "/path/to/GTF/file") == {"rRNA_transcripts": 500, "MT_transcripts": 200, "percent_rRNA": 25.0, "percent_MT": 10.0}
  assert calculate_rRNA_MT_percent("/path/to/nonexistent_file", "/path/to/GTF/file") == FileNotFoundError
  assert calculate_rRNA_MT_percent("/path/to/HTseq_counts/file", "/path/to/nonexistent_file") == FileNotFoundError
output: 
  def calculate_rRNA_MT_percent(htseq_counts_file, gtf_file):
      import os
      if not os.path.exists(htseq_counts_file):
          raise FileNotFoundError(f"File not found: {htseq_counts_file}")
      if not os.path.exists(gtf_file):
          raise FileNotFoundError(f"File not found: {gtf_file}")
  
      rRNA_transcripts = 0
      MT_transcripts = 0
      total_reads = 0
  
      with open(gtf_file, 'r') as gtf:
          gene_types = {}
          for line in gtf:
              if line.startswith('#'):
                  continue
              fields = line.strip().split('\t')
              if fields[2] == 'gene':
                  info = fields[8].split(';')
                  gene_id = [x.strip().split(' ')[1].strip('"') for x in info if 'gene_id' in x][0]
                  gene_type = [x.strip().split(' ')[1].strip('"') for x in info if 'gene_type' in x][0]
                  gene_types[gene_id] = gene_type
  
      with open(htseq_counts_file, 'r') as htseq:
          for line in htseq:
              if line.startswith('_'):
                  continue
              gene_id, count = line.strip().split('\t')
              count = int(count)
              total_reads += count
              if gene_id in gene_types:
                  if gene_types[gene_id] == 'rRNA':
                      rRNA_transcripts += count
                  elif gene_types[gene_id] == 'Mt_tRNA':
                      MT_transcripts += count
  
      percent_rRNA = (rRNA_transcripts / total_reads) * 100 if total_reads > 0 else 0
      percent_MT = (MT_transcripts / total_reads) * 100 if total_reads > 0 else 0
  
      result = {
          "rRNA_transcripts": rRNA_transcripts,
          "MT_transcripts": MT_transcripts,
          "percent_rRNA": percent_rRNA,
          "percent_MT": percent_MT
      }
  
      with open(f"{htseq_counts_file}_rRNAmtRNACounts.txt", 'w') as outfile:
          outfile.write(f"rRNA_transcripts: {rRNA_transcripts}\n")
          outfile.write(f"MT_transcripts: {MT_transcripts}\n")
          outfile.write(f"percent_rRNA: {percent_rRNA}\n")
          outfile.write(f"percent_MT: {percent_MT}\n")
  
      return result
  