docs: def collapse_degenerate_markers(linkage_records):
  
      """Group all markers with no genetic distance as distinct features
      to generate a BED file with.
  
      Simple example with sixteen degenerate markers:
  
          >>> marker_features = [
          ... ['36915_sctg_207_31842', 1, 0, 207, 31842],
          ... ['36941_sctg_207_61615', 1, 0, 207, 61615],
          ... ['36956_sctg_207_77757', 1, 0, 207, 77757],
          ... ['36957_sctg_207_78332', 1, 0, 207, 78332],
          ... ['36972_sctg_207_94039', 1, 0, 207, 94039],
          ... ['36788_sctg_207_116303', 1, 0.652, 207, 116303],
          ... ['36812_sctg_207_158925', 1, 1.25, 207, 158925],
          ... ['36819_sctg_207_165424', 1, 1.25, 207, 165424],
          ... ['36828_sctg_207_190813', 1, 1.25, 207, 190813],
          ... ['36830_sctg_207_191645', 1, 1.25, 207, 191645],
          ... ['36834_sctg_207_195961', 1, 1.25, 207, 195961],
          ... ['36855_sctg_207_233632', 1, 1.25, 207, 233632],
          ... ['36881_sctg_207_258658', 1, 1.25, 207, 258658],
          ... ['82072_sctg_486_41893', 1, 3.756, 486, 41893],
          ... ['85634_sctg_516_36614', 1,	3.756, 516, 36614],
          ... ['85638_sctg_516_50582', 1, 3.756, 516, 50582]]
  
          >>> len(marker_features)
          16
  
          >>> collapsed_features = collapse_degenerate_markers(marker_features)
          >>> len(collapsed_features)
          5
  
      The degenerate features (identical linkage group, genetic distance and
      original scaffold) are collapsed into a region:
  
          >>> collapsed_features[0]
          [1, 31842, 94039, 207]
  
      The format is [linkage group, start, end, original scaffold].
  
      If a singleton (non-degenerate) feature is found, the region is simply
      a single point in the genome:
  
          >>> collapsed_features[1]
          [1, 116303, 116303, 207]
  
      so 'start' and 'end' are identical.
  
      Two markers are not considered degenerate if they belong to different
      original scaffolds, even if they are in terms of genetic linkage:
  
          >>> collapsed_features[2]
          [1, 158925, 258658, 207]
          >>> collapsed_features[3:]
          [[1, 41893, 41893, 486], [1, 36614, 50582, 516]]
      """
  
      def degeneracy(linkage_record):
          linkage_group, genetic_distance, scaffold = (
              linkage_record[1],
              linkage_record[2],
              linkage_record[3],
          )
          return (linkage_group, genetic_distance, scaffold)
  
      degenerate_records = []
      for _, degenerate_group in itertools.groupby(
          linkage_records, key=degeneracy
      ):
          group_list = list(degenerate_group)
          start_record, end_record = group_list[0], group_list[-1]
  
          assert (start_record[1], start_record[2], start_record[3]) == (
              end_record[1],
              end_record[2],
              end_record[3],
          )
  
          start_position = start_record[-1]
          end_position = end_record[-1]
  
          scaffold = start_record[3]
          linkage_group = start_record[1]
          record = [linkage_group, start_position, end_position, scaffold]
  
          degenerate_records.append(record)
  
      return degenerate_records