goatools.grouper.sorter module

Sorts GO IDs or user-provided sections containing GO IDs.

class goatools.grouper.sorter.Sorter(grprobj, **kws)[source]

Bases: object

Sorts GO IDs or user-provided sections containing GO IDs.

User GO IDs grouped under header GO IDs are not sorted by the Grouper class. Sort both user GO IDs in a group and header GO IDs across groups with these:

S: use_sections
s: section_sortby (T=True, F=False, S=lambda sort function)
h: hdrgo_sortby Sorts hdr GO IDs
u: sortby       Sorts user GO IDs
P: hdrgo_prt    If True, Removes GO IDs used as GO group headers; Leaves list in
                sorted order, but removes header GO IDs which are not user GO IDs.

        rm_h     hdr_sort      usr_sort       S  s  h  u  p
         ---     ------------  ------------  -- -- -- -- --
case 1:   NO     hdrgo_sortby  usrgo_sortby   N  T  H  U  T
case 2:  YES     hdrgo_sortby  usrgo_sortby   N  T  H  U  F
case 3:   NO     section_order usrgo_sortby   S  F  -  U  T
case 4:  YES     section_order usrgo_sortby   S  F  -  U  F
case 5:  YES     |<--- section_sortby --->|   S  S  -  -  -

                                 |print|
  sec usesec prthdr prtsec 1d 2d hdr usr
 ---- ------ ------ ------ -- -- --- ---
 none      -   true      -  y  . hdr usr A
 none      -  false      -  y  . ... usr B

  yes  False   true      -  y  . hdr usr A
  yes  False  false      -  y  . ... usr B

  yes   True   True  False  .  y hdr usr
  yes   True  False  False  .  y ... usr
keys_nts = {'hdrgo_prt', 'section_prt', 'top_n', 'use_sections'}
prt_gos(prt=sys.stdout, **kws_usr)[source]

Sort user GO ids, grouped under broader GO terms or sections. Print to screen.

prt_nts(desc2nts, prt=sys.stdout, prtfmt=None)[source]

Print grouped and sorted GO IDs.

get_desc2nts(**kws_usr)[source]

Return grouped, sorted namedtuples in either format: flat, sections.

get_desc2nts_fnc(hdrgo_prt=True, section_prt=None, top_n=None, use_sections=True)[source]

Return grouped, sorted namedtuples in either format: flat, sections.

static get_sections_flattened(section_nts)[source]

Convert [(section0, nts0), (section1, nts1), ...] to [*nts0, *nts1, ...]

get_nts_flat(hdrgo_prt=True, use_sections=True)[source]

Return a flat list of sorted nts.

static get_fields(desc2nts)[source]

Return grouped, sorted namedtuples in either format: flat, sections.