nodes: 0, module; 1, function_definition; 2, function_name:linkage_group_ordering; 3, parameters; 4, block; 5, identifier:linkage_records; 6, expression_statement; 7, expression_statement; 8, for_statement; 9, return_statement; 10, comment:"""Convert degenerate linkage records into ordered info_frags-like records
      for comparison purposes.
  
      Simple example:
  
          >>> linkage_records = [
          ... ['linkage_group_1', 31842, 94039, 'sctg_207'],
          ... ['linkage_group_1', 95303, 95303, 'sctg_207'],
          ... ['linkage_group_2', 15892, 25865, 'sctg_308'],
          ... ['linkage_group_2', 41893, 41893, 'sctg_486'],
          ... ['linkage_group_3', 36614, 50582, 'sctg_516'],
          ... ]
          >>> ordering = linkage_group_ordering(linkage_records)
  
      Each key of the record is a newly-formed 'scaffold' (linkage group):
  
          >>> sorted(ordering.keys())
          ['linkage_group_1', 'linkage_group_2', 'linkage_group_3']
  
      Records are in the form [init_contig, frag_id, start, end, orientation].
      Since fragment ids are meaningless in non-HiC contexts a negative
      identifier is set so it is understood that region was added due to
      linkage data (-1 is for recovering data after first-pass polishing and -2
      is for sequence insertions after long read based polishing).
  
          >>> ordering['linkage_group_1']
          [['sctg_207', -3, 31842, 94039, 1], ['sctg_207', -3, 95303, 95303, 1]]
          >>> ordering['linkage_group_2']
          [['sctg_308', -3, 15892, 25865, 1], ['sctg_486', -3, 41893, 41893, 1]]
  
      Orientations are always set to 1 by default.
  
          >>> ordering['linkage_group_3']
          [['sctg_516', -3, 36614, 50582, 1]]
  
  
      """; 11, assignment; 12, pattern_list; 13, call; 14, block; 15, identifier:new_records; 16, identifier:new_records; 17, call; 18, identifier:lg_name; 19, identifier:linkage_group; 20, attribute; 21, argument_list; 22, expression_statement; 23, for_statement; 24, identifier:dict; 25, argument_list; 26, identifier:itertools; 27, identifier:groupby; 28, identifier:linkage_records; 29, call; 30, assignment; 31, identifier:record; 32, identifier:linkage_group; 33, block; 34, attribute; 35, argument_list; 36, subscript; 37, list; 38, expression_statement; 39, expression_statement; 40, expression_statement; 41, expression_statement; 42, expression_statement; 43, identifier:operator; 44, identifier:itemgetter; 45, integer:0; 46, identifier:new_records; 47, identifier:lg_name; 48, assignment; 49, assignment; 50, assignment; 51, assignment; 52, call; 53, identifier:init_contig; 54, subscript; 55, identifier:start; 56, subscript; 57, identifier:end; 58, subscript; 59, identifier:new_record; 60, list; 61, attribute; 62, argument_list; 63, identifier:record; 64, unary_operator; 65, identifier:record; 66, integer:1; 67, identifier:record; 68, integer:2; 69, identifier:init_contig; 70, unary_operator; 71, identifier:start; 72, identifier:end; 73, integer:1; 74, subscript; 75, identifier:append; 76, identifier:new_record; 77, integer:1; 78, integer:3; 79, identifier:new_records; 80, identifier:lg_name
code: def linkage_group_ordering(linkage_records):
      """Convert degenerate linkage records into ordered info_frags-like records
      for comparison purposes.
  
      Simple example:
  
          >>> linkage_records = [
          ... ['linkage_group_1', 31842, 94039, 'sctg_207'],
          ... ['linkage_group_1', 95303, 95303, 'sctg_207'],
          ... ['linkage_group_2', 15892, 25865, 'sctg_308'],
          ... ['linkage_group_2', 41893, 41893, 'sctg_486'],
          ... ['linkage_group_3', 36614, 50582, 'sctg_516'],
          ... ]
          >>> ordering = linkage_group_ordering(linkage_records)
  
      Each key of the record is a newly-formed 'scaffold' (linkage group):
  
          >>> sorted(ordering.keys())
          ['linkage_group_1', 'linkage_group_2', 'linkage_group_3']
  
      Records are in the form [init_contig, frag_id, start, end, orientation].
      Since fragment ids are meaningless in non-HiC contexts a negative
      identifier is set so it is understood that region was added due to
      linkage data (-1 is for recovering data after first-pass polishing and -2
      is for sequence insertions after long read based polishing).
  
          >>> ordering['linkage_group_1']
          [['sctg_207', -3, 31842, 94039, 1], ['sctg_207', -3, 95303, 95303, 1]]
          >>> ordering['linkage_group_2']
          [['sctg_308', -3, 15892, 25865, 1], ['sctg_486', -3, 41893, 41893, 1]]
  
      Orientations are always set to 1 by default.
  
          >>> ordering['linkage_group_3']
          [['sctg_516', -3, 36614, 50582, 1]]
  
  
      """
  
      new_records = dict()
  
      for lg_name, linkage_group in itertools.groupby(
          linkage_records, operator.itemgetter(0)
      ):
          new_records[lg_name] = []
          for record in linkage_group:
              init_contig = record[-1]
              start = record[1]
              end = record[2]
  
              new_record = [init_contig, -3, start, end, 1]
  
              new_records[lg_name].append(new_record)
  
      return new_records