input: Write a function to calculate the percentage of transcripts mapping to rRNA based on an HTseq_counts file and a reference transcriptome GTF file. The function should return a dictionary containing the total number of rRNA transcripts, the total number of MT transcripts, the total number of reads, and the percentages of rRNA and MT mapped reads. The function should handle missing files appropriately by returning an empty dictionary. If either the HTseq_counts file or the GTF file is missing, the function should return an empty dictionary.
  assert calculate_rRNA_percentage("/path/to/GTF/file", "/path/to/HTseq_counts/file") == {'total_rRNA_transcripts': 12345, 'total_MT_transcripts': 678, 'total_reads': 100000, 'percent_rRNA': 12.35, 'percent_MT': 0.68}
  assert calculate_rRNA_percentage("/nonexistent/GTF/file", "/nonexistent/HTseq_counts/file") == {}
output: 
  def calculate_rRNA_percentage(gtf_file, htseq_counts_file):
      if not os.path.exists(gtf_file) or not os.path.exists(htseq_counts_file):
          return {}
      
      rRNA_transcripts = set()
      MT_transcripts = set()
      total_reads = 0
      rRNA_reads = 0
      MT_reads = 0
      
      with open(gtf_file, 'r') as gtf:
          for line in gtf:
              if line.startswith('#'):
                  continue
              fields = line.strip().split('\t')
              if fields[2] == 'transcript':
                  attributes = fields[8].split(';')
                  transcript_id = None
                  for attr in attributes:
                      if 'transcript_id' in attr:
                          transcript_id = attr.split()[1].strip('"')
                          break
                  if 'rRNA' in fields[8]:
                      rRNA_transcripts.add(transcript_id)
                  if 'MT' in fields[8]:
                      MT_transcripts.add(transcript_id)
      
      with open(htseq_counts_file, 'r') as htseq:
          for line in htseq:
              if line.startswith('__'):
                  continue
              transcript_id, count = line.strip().split('\t')
              count = int(count)
              total_reads += count
              if transcript_id in rRNA_transcripts:
                  rRNA_reads += count
              if transcript_id in MT_transcripts:
                  MT_reads += count
      
      percent_rRNA = (rRNA_reads / total_reads) * 100 if total_reads > 0 else 0
      percent_MT = (MT_reads / total_reads) * 100 if total_reads > 0 else 0
      
      return {
          'total_rRNA_transcripts': len(rRNA_transcripts),
          'total_MT_transcripts': len(MT_transcripts),
          'total_reads': total_reads,
          'percent_rRNA': round(percent_rRNA, 2),
          'percent_MT': round(percent_MT, 2)
      }
  