input: 
  import re
  
  def rRNA_MT_count(htseq_file: str, gtf_file: str) -> str:
      """ Calculate the percent of transcripts mapping to rRNA and MT genes from an HTseq counts file and a GTF file.
      The script will extract all the identifiers of genes/transcripts mapping to the rRNA and MT genes and count the reads matching those identifiers.
      The output will be a summary file named "HTseq_counts_file_rRNAmtRNACounts.txt".
      >>> rRNA_MT_count("C17_3_S20_Aligned.out.srt.bam_htseq_combined_counts.txt", "/path/to/Mus_musculus.GRCm38.84.gtf")
      "C17_3_S20_Aligned.out.srt.bam_htseq_combined_counts_rRNAmtRNACounts.txt"
      """
      
      # Check if files exist
      try:
          with open(gtf_file, "r") as f:
              pass
      except FileNotFoundError:
          print(f"Error-> GTF File: {gtf_file} does not exist")
          return
  
      try:
          with open(htseq_file, "r") as f:
              pass
      except FileNotFoundError:
          print(f"Error-> HTseq File: {htseq_file} does not exist")
          return
  
      rRNA_identifiers = {}
      MT_identifiers = {}
  
      # Extract identifiers from GTF file
      with open(gtf_file, "r") as handle:
          for line in handle:
              if 'gene_biotype "rRNA"' in line:
                  identifier = re.sub(r'.*gene_id "', '', line)
                  identifier = re.sub(r'"; gene_version.*\n', '', identifier)
                  rRNA_identifiers[identifier] = 1
              if 'MT' in line:
                  identifier = re.sub(r'.*gene_id "', '', line)
                  identifier = re.sub(r'"; gene_version.*\n', '', identifier)
                  MT_identifiers[identifier] = 1
  
      Cummulative_rRNA_Count = 0
      Cummulative_MT_Count = 0
      ReadCount = 0
      line_number = 0
  
      # Count reads matching identifiers from HTseq file
      with open(htseq_file, "r") as handle:
          for line in handle:
              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
  
      # Write summary output file
      out_file = re.sub(r'.txt_', '_', htseq_file + '_rRNAmtRNACounts.txt')
      with open(out_file, "w") as OUT:
          OUT.write(f'HT-SEQ file name: \t{htseq_file}\n\n')
          OUT.write(f'GTF file name: \t\t{gtf_file}\n\n\n')
          OUT.write('---------------------------------------------------------------------------------\n')
          OUT.write('  rRNA and MT identifiers\n')
          OUT.write('---------------------------------------------------------------------------------\n')
          OUT.write(f'No. of rRNA identifiers: {len(rRNA_identifiers.keys())}\n')
          OUT.write(f'No. of MT identifiers: {len(MT_identifiers.keys())}\n\n\n')
          OUT.write('---------------------------------------------------------------------------------\n')
          OUT.write('  HTSEQ mapping summary\n')
          OUT.write('---------------------------------------------------------------------------------\n')
          OUT.write(f'ReadCount: {ReadCount}\n\n')
          OUT.write(f'Total no. of rRNA transcripts: {Cummulative_rRNA_Count}\n')
          perc_rRNA = round(100 * Cummulative_rRNA_Count / ReadCount, 3)
          OUT.write(f'Percent rRNA mapped reads: {Cummulative_rRNA_Count} / {ReadCount} * 100 = {perc_rRNA}%\n\n')
          OUT.write(f'Total no. of MT transcripts: {Cummulative_MT_Count}\n')
          perc_MT = round(100 * Cummulative_MT_Count / ReadCount, 3)
          OUT.write(f'Percent MT mapped reads: {Cummulative_MT_Count} / {ReadCount} * 100 = {perc_MT}%\n\n')
  
      return out_file
  
output:     
      # Calculate the percent of transcripts mapping to rRNA and MT genes
      total_rRNA_MT_count = Cummulative_rRNA_Count + Cummulative_MT_Count
      perc_rRNA_MT = round(100 * total_rRNA_MT_count / ReadCount, 3)
  
      # Append the final summary to the output file
      with open(out_file, "a") as OUT:
          OUT.write('---------------------------------------------------------------------------------\n')
          OUT.write('  Final Summary\n')
          OUT.write('---------------------------------------------------------------------------------\n')
          OUT.write(f'Total no. of rRNA and MT transcripts: {total_rRNA_MT_count}\n')
          OUT.write(f'Percent rRNA and MT mapped reads: {total_rRNA_MT_count} / {ReadCount} * 100 = {perc_rRNA_MT}%\n')
  
      return out_file
  