input: Write a function to calculate the percent of transcripts mapping to rRNA and MT given an HTseq_counts file and a GTF file. The function should check if the input files exist, extract identifiers of rRNA and MT genes, count reads matching these identifiers, and output a summary file with rRNA and MT counts for each sample. If the files do not exist, the function should return an error.
  
  assert rrna_mt_percent("test_counts.txt", "test_gtf.gtf") == "test_counts_rRNAmtRNACounts.txt"
  assert rrna_mt_percent("nonexistent_counts.txt", "test_gtf.gtf") == "Error->\tFile: nonexistent_counts.txt does not exist"
  assert rrna_mt_percent("test_counts.txt", "nonexistent_gtf.gtf") == "Error->\tGTF File: nonexistent_gtf.gtf does not exist"
  
output: 
  def rrna_mt_percent(htseq_counts_file, gtf_file):
      import os
      if not os.path.exists(htseq_counts_file):
          return f"Error->\tFile: {htseq_counts_file} does not exist"
      if not os.path.exists(gtf_file):
          return f"Error->\tGTF File: {gtf_file} does not exist"
      
      rrna_ids = set()
      mt_ids = set()
      
      with open(gtf_file, 'r') as gtf:
          for line in gtf:
              if line.startswith('#'):
                  continue
              fields = line.strip().split('\t')
              if fields[2] == 'gene':
                  gene_info = fields[8]
                  gene_id = gene_info.split(';')[0].split('"')[1]
                  if 'rRNA' in gene_info:
                      rrna_ids.add(gene_id)
                  if 'MT' in gene_info:
                      mt_ids.add(gene_id)
      
      rrna_counts = {}
      mt_counts = {}
      
      with open(htseq_counts_file, 'r') as counts:
          for line in counts:
              if line.startswith('__'):
                  continue
              gene_id, count = line.strip().split('\t')
              count = int(count)
              if gene_id in rrna_ids:
                  rrna_counts[gene_id] = count
              if gene_id in mt_ids:
                  mt_counts[gene_id] = count
      
      output_file = htseq_counts_file.replace('.txt', '_rRNAmtRNACounts.txt')
      with open(output_file, 'w') as out:
          out.write("Gene\tType\tCount\n")
          for gene_id, count in rrna_counts.items():
              out.write(f"{gene_id}\trRNA\t{count}\n")
          for gene_id, count in mt_counts.items():
              out.write(f"{gene_id}\tMT\t{count}\n")
      
      return output_file
  