input: Write a function to calculate the percent of transcripts mapping to rRNA and MT genes based on an HTseq_counts file and a GTF file. The function should return a dictionary with the percent of rRNA and MT mapped reads. The function should handle file existence checks and handle the calculation of counts.
  
  def calculate_rRNA_MT_percent(htseq_file, gtf_file):
      try:
          handle = open(gtf_file, "rU")
          handle.close()
      except:
          print("\nError->\tGTF File: %s does not exist\n" % gtf_file)
          return None
  
      try:
          handle = open(htseq_file, "rU")
          handle.close()
      except:
          print("\nError->\tFile: %s does not exist\n" % htseq_file)
          return None
  
      rRNA_identifiers = {}
      MT_identifiers = {}
  
      with open(gtf_file, "rU") as handle:
          for line in handle:
              line = line.rstrip('\n')
              if 'gene_biotype "rRNA"' in line:
                  identifier = re.sub('.*gene_id "', '', line)
                  identifier = re.sub('"; gene_version.*\n', '', identifier)
                  rRNA_identifiers[identifier] = 1
              if 'MT' in line:
                  identifier = re.sub('.*gene_id "', '', line)
                  identifier = re.sub('"; gene_version.*\n', '', identifier)
                  MT_identifiers[identifier] = 1
      handle.close()
  
      Cummulative_rRNA_Count = 0
      Cummulative_MT_Count = 0
      ReadCount = 0
      line_number = 0
  
      with open(htseq_file, "rU") as handle:
          for line in handle:
              line = line.rstrip('\n')
              split_line = line.split("\t")
              if line_number > 0:
                  if split_line[0] in rRNA_identifiers.keys():
                      Cummulative_rRNA_Count += int(split_line[1])
                  if split_line[0] in MT_identifiers.keys():
                      Cummulative_MT_Count += int(split_line[1])
                  ReadCount += int(split_line[1])
              line_number += 1
      handle.close()
  
      perc_rRNA = 100 * float(Cummulative_rRNA_Count) / float(ReadCount)
      perc_MT = 100 * float(Cummulative_MT_Count) / float(ReadCount)
  
      return {
          "percent_rRNA": round(perc_rRNA, 3),
          "percent_MT": round(perc_MT, 3)
      }
  
  assert calculate_rRNA_MT_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") == {"percent_rRNA": 5.234, "percent_MT": 2.123}
output: def calculate_rRNA_MT_percent(htseq_file, gtf_file):
      try:
          with open(gtf_file, "r") as handle:
              pass
      except FileNotFoundError:
          print("\nError->\tGTF File: %s does not exist\n" % gtf_file)
          return None
  
      try:
          with open(htseq_file, "r") as handle:
              pass
      except FileNotFoundError:
          print("\nError->\tFile: %s does not exist\n" % htseq_file)
          return None
  
      rRNA_identifiers = set()
      MT_identifiers = set()
  
      with open(gtf_file, "r") as handle:
          for line in handle:
              if 'gene_biotype "rRNA"' in line:
                  identifier = re.search(r'gene_id "([^"]+)"', line).group(1)
                  rRNA_identifiers.add(identifier)
              if 'MT' in line:
                  identifier = re.search(r'gene_id "([^"]+)"', line).group(1)
                  MT_identifiers.add(identifier)
  
      Cummulative_rRNA_Count = 0
      Cummulative_MT_Count = 0
      ReadCount = 0
  
      with open(htseq_file, "r") as handle:
          for line in handle:
              split_line = line.strip().split("\t")
              if split_line[0] in rRNA_identifiers:
                  Cummulative_rRNA_Count += int(split_line[1])
              if split_line[0] in MT_identifiers:
                  Cummulative_MT_Count += int(split_line[1])
              ReadCount += int(split_line[1])
  
      perc_rRNA = 100 * float(Cummulative_rRNA_Count) / float(ReadCount)
      perc_MT = 100 * float(Cummulative_MT_Count) / float(ReadCount)
  
      return {
          "percent_rRNA": round(perc_rRNA, 3),
          "percent_MT": round(perc_MT, 3)
      }