nodes: 0, module; 1, function_definition; 2, function_name:primary_mrna; 3, parameters; 4, block; 5, identifier:entrystream; 6, default_parameter; 7, expression_statement; 8, for_statement; 9, identifier:parenttype; 10, string; 11, comment:"""
      Select a single mRNA as a representative for each protein-coding gene.
  
      The primary mRNA is the one with the longest translation product. In cases
      where multiple isoforms have the same translated length, the feature ID is
      used for sorting.
  
      This function **does not** return only mRNA features, it returns all GFF3
      entry types (pragmas, features, sequences, etc). The function **does**
      modify the gene features that pass through to ensure that they have at most
      a single mRNA feature.
  
      >>> reader = tag.GFF3Reader(tag.pkgdata('pdom-withseq.gff3'))
      >>> filter = tag.transcript.primary_mrna(reader)
      >>> for gene in tag.select.features(filter, type='gene'):
      ...    assert gene.num_children == 1
      """; 12, identifier:entry; 13, identifier:entrystream; 14, block; 15, string_content:gene; 16, if_statement; 17, for_statement; 18, expression_statement; 19, not_operator; 20, block; 21, identifier:parent; 22, call; 23, block; 24, yield; 25, call; 26, expression_statement; 27, continue_statement; 28, attribute; 29, argument_list; 30, expression_statement; 31, if_statement; 32, expression_statement; 33, identifier:entry; 34, identifier:isinstance; 35, argument_list; 36, yield; 37, attribute; 38, identifier:features; 39, identifier:entry; 40, identifier:parenttype; 41, keyword_argument; 42, assignment; 43, comparison_operator:len(mrnas) == 0; 44, block; 45, call; 46, identifier:entry; 47, attribute; 48, identifier:entry; 49, identifier:tag; 50, identifier:select; 51, identifier:traverse; 52, True; 53, identifier:mrnas; 54, list_comprehension; 55, call; 56, integer:0; 57, continue_statement; 58, identifier:_emplace_pmrna; 59, argument_list; 60, identifier:tag; 61, identifier:Feature; 62, identifier:f; 63, for_in_clause; 64, if_clause; 65, identifier:len; 66, argument_list; 67, identifier:mrnas; 68, identifier:parent; 69, identifier:f; 70, attribute; 71, comparison_operator:f.type == 'mRNA'; 72, identifier:mrnas; 73, identifier:parent; 74, identifier:children; 75, attribute; 76, string; 77, identifier:f; 78, identifier:type; 79, string_content:mRNA
code: def primary_mrna(entrystream, parenttype='gene'):
      """
      Select a single mRNA as a representative for each protein-coding gene.
  
      The primary mRNA is the one with the longest translation product. In cases
      where multiple isoforms have the same translated length, the feature ID is
      used for sorting.
  
      This function **does not** return only mRNA features, it returns all GFF3
      entry types (pragmas, features, sequences, etc). The function **does**
      modify the gene features that pass through to ensure that they have at most
      a single mRNA feature.
  
      >>> reader = tag.GFF3Reader(tag.pkgdata('pdom-withseq.gff3'))
      >>> filter = tag.transcript.primary_mrna(reader)
      >>> for gene in tag.select.features(filter, type='gene'):
      ...    assert gene.num_children == 1
      """
      for entry in entrystream:
          if not isinstance(entry, tag.Feature):
              yield entry
              continue
  
          for parent in tag.select.features(entry, parenttype, traverse=True):
              mrnas = [f for f in parent.children if f.type == 'mRNA']
              if len(mrnas) == 0:
                  continue
              _emplace_pmrna(mrnas, parent)
          yield entry