docs: def compare_orderings(info_frags_records, linkage_orderings):
  
      """Given linkage groups and info_frags records, link pseudo-chromosomes to
      scaffolds based on the initial contig composition of each group. Because
      info_frags records are usually richer and may contain contigs not found
      in linkage groups, those extra sequences are discarded.
  
      Example with two linkage groups and two chromosomes:
  
          >>> linkage_orderings = {
          ...     'linkage_group_1': [
          ...         ['sctg_516', -3, 36614, 50582, 1],
          ...         ['sctg_486', -3, 41893, 41893, 1],
          ...         ['sctg_486', -3, 50054, 62841, 1],
          ...         ['sctg_207', -3, 31842, 94039, 1],
          ...         ['sctg_558', -3, 51212, 54212, 1],
          ...     ],
          ...     'linkage_group_2': [
          ...         ['sctg_308', -3, 15892, 25865, 1],
          ...         ['sctg_842', -3, 0, 8974, 1],
          ...         ['sctg_994', -3, 0, 81213, 1],
          ...     ],
          ... }
          >>> info_frags = {
          ...     'scaffold_A': [
          ...         ['sctg_308', 996, 15892, 25865, 1],
          ...         ['sctg_778', 1210, 45040, 78112, -1],
          ...         ['sctg_842', 124, 0, 8974, 1],
          ...     ],
          ...     'scaffold_B': [
          ...         ['sctg_516', 5, 0, 38000, 1],
          ...         ['sctg_486', 47, 42050, 49000, 1],
          ...         ['sctg_1755', 878, 95001, 10844, -1],
          ...         ['sctg_842', 126, 19000, 26084, 1],
          ...         ['sctg_207', 705, 45500, 87056, 1],
          ...     ],
          ...     'scaffold_C': [
          ...        ['sctg_558', 745, 50045, 67851, 1],
          ...        ['sctg_994', 12, 74201, 86010, -1],
          ...     ],
          ... }
          >>> matching_pairs = compare_orderings(info_frags, linkage_orderings)
          >>> matching_pairs['scaffold_B']
          (3, 'linkage_group_1', {'sctg_558': 'sctg_207'})
          >>> matching_pairs['scaffold_A']
          (2, 'linkage_group_2', {'sctg_994': 'sctg_842'})
  
      """
  
      scaffolds = info_frags_records.keys()
      linkage_groups = linkage_orderings.keys()
  
      best_matching_table = dict()
  
      for scaffold, linkage_group in itertools.product(
          scaffolds, linkage_groups
      ):
          lg_ordering = [
              init_contig
              for init_contig, _ in itertools.groupby(
                  linkage_orderings[linkage_group], operator.itemgetter(0)
              )
          ]
          scaffold_ordering = [
              init_contig
              for init_contig, bin_group in itertools.groupby(
                  info_frags_records[scaffold], operator.itemgetter(0)
              )
              if init_contig in lg_ordering
          ]
  
          overlap = set(lg_ordering).intersection(set(scaffold_ordering))
          missing_locations = dict()
          for missing_block in sorted(set(lg_ordering) - set(overlap)):
              for i, init_contig in enumerate(lg_ordering):
                  if init_contig == missing_block:
                      try:
                          block_before = lg_ordering[i - 1]
                      except IndexError:
                          block_before = "beginning"
                      missing_locations[missing_block] = block_before
  
          try:
              if len(overlap) > best_matching_table[scaffold][0]:
                  best_matching_table[scaffold] = (
                      len(overlap),
                      linkage_group,
                      missing_locations,
                  )
  
          except KeyError:
              best_matching_table[scaffold] = (
                  len(overlap),
                  linkage_group,
                  missing_locations,
              )
  
      return best_matching_table