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. It will extract all the identifiers of genes/transcripts mapping to the rRNA and MT genes, count reads matching the rRNA identifiers, and write the output to a file named "HTseq_counts_file_rRNAmtRNACounts.txt". If the input files do not exist, the function should return an error message and exit.
  assert calculate_rRNA_percent("C17_3_S20_Aligned.out.srt.bam_htseq_combined_counts.txt", "/Users/malwina/Documents/CTR-Data/genomes/Mus_musculus/mm10/Mus_musculus.GRCm38.84.gtf")==None
  assert os.path.exists("C17_3_S20_Aligned.out.srt.bam_htseq_combined_counts_rRNAmtRNACounts.txt")==True
  assert calculate_rRNA_percent("nonexistent_file.txt", "/Users/malwina/Documents/CTR-Data/genomes/Mus_musculus/mm10/Mus_musculus.GRCm38.84.gtf")=="Error->\tFile: nonexistent_file.txt does not exist"
output: 
  def calculate_rRNA_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->\tFile: {gtf_file} does not exist"
      
      rRNA_mtRNA_ids = set()
      with open(gtf_file, 'r') as gtf:
          for line in gtf:
              if line.startswith('#'):
                  continue
              fields = line.split('\t')
              if fields[2] == 'gene':
                  gene_info = fields[8]
                  if 'gene_biotype "rRNA"' in gene_info or 'gene_biotype "Mt_rRNA"' in gene_info:
                      gene_id = gene_info.split('gene_id "')[1].split('";')[0]
                      rRNA_mtRNA_ids.add(gene_id)
      
      rRNA_mtRNA_counts = 0
      total_counts = 0
      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_counts += count
              if gene_id in rRNA_mtRNA_ids:
                  rRNA_mtRNA_counts += count
      
      output_file = f"{htseq_counts_file}_rRNAmtRNACounts.txt"
      with open(output_file, 'w') as out:
          out.write(f"rRNA_mtRNA_counts\t{rRNA_mtRNA_counts}\n")
          out.write(f"total_counts\t{total_counts}\n")
          out.write(f"percent_rRNA_mtRNA\t{(rRNA_mtRNA_counts / total_counts) * 100}\n")
  