input: Write a function to calculate the percent of transcripts mapping to rRNA. The function should take two inputs: an HTseq_counts file and a GTF file, and it should return a summary output file named "HTseq_counts_file_rRNAmtRNACounts.txt". If the input files do not exist, the function should print an error message and terminate. The function will extract identifiers of genes/transcripts mapping to rRNA and MT genes, count reads matching these identifiers, and write the results to the output file.
  assert calculate_percent_rRNA("/path/to/GTF/file", "/path/to/HTseq_counts/file") == "HTseq_counts_file_rRNAmtRNACounts.txt"
  assert calculate_percent_rRNA("/nonexistent/GTF/file", "/path/to/HTseq_counts/file") == "Error: GTF File: /nonexistent/GTF/file does not exist"
  assert calculate_percent_rRNA("/path/to/GTF/file", "/nonexistent/HTseq_counts/file") == "Error: File: /nonexistent/HTseq_counts/file does not exist"
output: 
  def calculate_percent_rRNA(GTF_file, HTseq_counts_file):
      import os
      if not os.path.exists(GTF_file):
          return f"Error: GTF File: {GTF_file} does not exist"
      if not os.path.exists(HTseq_counts_file):
          return f"Error: File: {HTseq_counts_file} does not exist"
      
      rRNA_mtRNA_ids = set()
      with open(GTF_file, 'r') as gtf:
          for line in gtf:
              if 'rRNA' in line or 'Mt_rRNA' in line or 'Mt_tRNA' in line:
                  fields = line.split('\t')
                  if len(fields) > 8:
                      attributes = fields[8]
                      if 'gene_id' in attributes:
                          gene_id = attributes.split('gene_id "')[1].split('";')[0]
                          rRNA_mtRNA_ids.add(gene_id)
      
      rRNA_mtRNA_counts = {}
      with open(HTseq_counts_file, 'r') as htseq:
          for line in htseq:
              fields = line.split('\t')
              if len(fields) == 2:
                  gene_id, count = fields[0], int(fields[1])
                  if gene_id in rRNA_mtRNA_ids:
                      rRNA_mtRNA_counts[gene_id] = count
      
      output_file = f"{HTseq_counts_file}_rRNAmtRNACounts.txt"
      with open(output_file, 'w') as out:
          for gene_id, count in rRNA_mtRNA_counts.items():
              out.write(f"{gene_id}\t{count}\n")
      
      return output_file
  