nodes: 0, module; 1, function_definition; 2, function_name:get_sorted_hdrgo2usrgos; 3, parameters; 4, block; 5, identifier:self; 6, identifier:hdrgos; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, expression_statement; 11, comment:# Return user-specfied sort or default sort of header and user GO IDs; 12, expression_statement; 13, expression_statement; 14, comment:# Sort GO group headers using GO info in go2nt; 15, expression_statement; 16, if_statement; 17, for_statement; 18, return_statement; 19, identifier:flat_list; 20, None; 21, identifier:hdrgo_prt; 22, True; 23, identifier:hdrgo_sort; 24, True; 25, comment:"""Return GO IDs sorting using go2nt's namedtuple."""; 26, assignment; 27, assignment; 28, assignment; 29, comparison_operator:hdrgo_sort is True; 30, block; 31, pattern_list; 32, identifier:hdr_go2nt; 33, block; 34, call; 35, identifier:sorted_hdrgos_usrgos; 36, list; 37, identifier:h2u_get; 38, attribute; 39, identifier:hdr_go2nt; 40, call; 41, identifier:hdrgo_sort; 42, True; 43, expression_statement; 44, identifier:hdrgo_id; 45, identifier:hdrgo_nt; 46, if_statement; 47, comment:# Sort user GOs which are under the current GO header; 48, expression_statement; 49, if_statement; 50, attribute; 51, argument_list; 52, attribute; 53, identifier:get; 54, attribute; 55, argument_list; 56, assignment; 57, comparison_operator:flat_list is not None; 58, block; 59, assignment; 60, identifier:usrgos_unsorted; 61, block; 62, else_clause; 63, identifier:cx; 64, identifier:OrderedDict; 65, identifier:sorted_hdrgos_usrgos; 66, attribute; 67, identifier:hdrgo2usrgos; 68, identifier:self; 69, identifier:_get_go2nt; 70, identifier:hdrgos; 71, identifier:hdr_go2nt; 72, call; 73, identifier:flat_list; 74, None; 75, if_statement; 76, identifier:usrgos_unsorted; 77, call; 78, expression_statement; 79, expression_statement; 80, expression_statement; 81, if_statement; 82, expression_statement; 83, block; 84, identifier:self; 85, identifier:grprobj; 86, identifier:sorted; 87, argument_list; 88, boolean_operator; 89, block; 90, identifier:h2u_get; 91, argument_list; 92, assignment; 93, assignment; 94, assignment; 95, comparison_operator:flat_list is not None; 96, block; 97, call; 98, expression_statement; 99, call; 100, keyword_argument; 101, identifier:hdrgo_prt; 102, comparison_operator:hdrgo_id in self.grprobj.usrgos; 103, expression_statement; 104, identifier:hdrgo_id; 105, identifier:usrgo2nt; 106, call; 107, identifier:usrgont_sorted; 108, call; 109, pattern_list; 110, call; 111, identifier:flat_list; 112, None; 113, expression_statement; 114, attribute; 115, argument_list; 116, call; 117, attribute; 118, argument_list; 119, identifier:key; 120, lambda; 121, identifier:hdrgo_id; 122, attribute; 123, call; 124, attribute; 125, argument_list; 126, identifier:sorted; 127, argument_list; 128, identifier:usrgos_sorted; 129, identifier:usrnts_sorted; 130, identifier:zip; 131, argument_list; 132, call; 133, identifier:sorted_hdrgos_usrgos; 134, identifier:append; 135, tuple; 136, attribute; 137, argument_list; 138, identifier:hdr_go2nt; 139, identifier:items; 140, lambda_parameters; 141, call; 142, attribute; 143, identifier:usrgos; 144, attribute; 145, argument_list; 146, identifier:self; 147, identifier:_get_go2nt; 148, identifier:usrgos_unsorted; 149, call; 150, keyword_argument; 151, list_splat; 152, attribute; 153, argument_list; 154, identifier:hdrgo_id; 155, identifier:usrgos_sorted; 156, identifier:sorted_hdrgos_usrgos; 157, identifier:append; 158, tuple; 159, identifier:t; 160, attribute; 161, argument_list; 162, identifier:self; 163, identifier:grprobj; 164, identifier:flat_list; 165, identifier:append; 166, identifier:hdrgo_nt; 167, attribute; 168, argument_list; 169, identifier:key; 170, lambda; 171, identifier:usrgont_sorted; 172, identifier:flat_list; 173, identifier:extend; 174, identifier:usrnts_sorted; 175, identifier:hdrgo_id; 176, list; 177, identifier:self; 178, identifier:hdrgo_sortby; 179, subscript; 180, identifier:usrgo2nt; 181, identifier:items; 182, lambda_parameters; 183, call; 184, identifier:t; 185, integer:1; 186, identifier:t; 187, attribute; 188, argument_list; 189, identifier:self; 190, identifier:usrgo_sortby; 191, subscript; 192, identifier:t; 193, integer:1
code: def get_sorted_hdrgo2usrgos(self, hdrgos, flat_list=None, hdrgo_prt=True, hdrgo_sort=True):
          """Return GO IDs sorting using go2nt's namedtuple."""
          # Return user-specfied sort or default sort of header and user GO IDs
          sorted_hdrgos_usrgos = []
          h2u_get = self.grprobj.hdrgo2usrgos.get
          # Sort GO group headers using GO info in go2nt
          hdr_go2nt = self._get_go2nt(hdrgos)
          if hdrgo_sort is True:
              hdr_go2nt = sorted(hdr_go2nt.items(), key=lambda t: self.hdrgo_sortby(t[1]))
          for hdrgo_id, hdrgo_nt in hdr_go2nt:
              if flat_list is not None:
                  if hdrgo_prt or hdrgo_id in self.grprobj.usrgos:
                      flat_list.append(hdrgo_nt)
              # Sort user GOs which are under the current GO header
              usrgos_unsorted = h2u_get(hdrgo_id)
              if usrgos_unsorted:
                  usrgo2nt = self._get_go2nt(usrgos_unsorted)
                  usrgont_sorted = sorted(usrgo2nt.items(), key=lambda t: self.usrgo_sortby(t[1]))
                  usrgos_sorted, usrnts_sorted = zip(*usrgont_sorted)
                  if flat_list is not None:
                      flat_list.extend(usrnts_sorted)
                  sorted_hdrgos_usrgos.append((hdrgo_id, usrgos_sorted))
              else:
                  sorted_hdrgos_usrgos.append((hdrgo_id, []))
          return cx.OrderedDict(sorted_hdrgos_usrgos)