Exemplo n.º 1
0
 def write(self, fout_xlsx=None, fout_txt=None, verbose=False):
     """Command-line interface for go_draw script."""
     sortby = self._get_fncsortnt(self.objgrpd.grprobj.gosubdag.prt_attr['flds'])
     kws_sort = {'sortby' if verbose else 'section_sortby': sortby}
     sortobj = Sorter(self.objgrpd.grprobj, **kws_sort)
     # KWS: hdrgo_prt=True section_prt=None top_n=None use_sections=True
     # RET: {sortobj, sections, hdrgo_prt} or {sortobj flat hdrgo_prt}
     desc2nts = sortobj.get_desc2nts_fnc(
         hdrgo_prt=verbose,
         section_prt=True,
         top_n=None,
         use_sections=True)
     # print('FFFF', desc2nts['flds'])
     # Write user GO IDs in sections
     objgowr = WrXlsxSortedGos("init", sortobj, self.objgrpd.ver_list)
     if fout_xlsx is not None:
         kws_xlsx = {'shade_hdrgos':verbose}
         if not verbose:
             kws_xlsx['prt_flds'] = [f for f in desc2nts['flds'] if f not in self.excl_flds]
         objgowr.wr_xlsx_nts(fout_xlsx, desc2nts, **kws_xlsx)
         fout_desc = '{BASE}_desc.txt'.format(BASE=os.path.splitext(fout_xlsx)[0])
         self._wr_ver_n_key(fout_desc, verbose)
     if fout_txt is not None:
         self._wr_txt_nts(fout_txt, desc2nts, objgowr, verbose)
     if fout_xlsx is None and fout_txt is None:
         self._prt_ver_n_key(sys.stdout, verbose)
         prtfmt = self._get_prtfmt(objgowr, verbose)
         summary_dct = objgowr.prt_txt_desc2nts(sys.stdout, desc2nts, prtfmt)
         self._prt_ver_n_key(sys.stdout, verbose)
         if summary_dct:
             print("\n{N} GO IDs in {S} sections".format(
                 N=desc2nts['num_items'], S=desc2nts['num_sections']))
Exemplo n.º 2
0
 def write(self, fout_xlsx=None, fout_txt=None, verbose=False):
     """Command-line interface for go_draw script."""
     sortby = self._get_fncsortnt(self.objgrpd.grprobj.gosubdag.prt_attr['flds'])
     kws_sort = {'sortby' if verbose else 'section_sortby': sortby}
     sortobj = Sorter(self.objgrpd.grprobj, **kws_sort)
     # KWS: hdrgo_prt=True section_prt=None top_n=None use_sections=True
     # RET: {sortobj, sections, hdrgo_prt} or {sortobj flat hdrgo_prt}
     desc2nts = sortobj.get_desc2nts_fnc(
         hdrgo_prt=verbose,
         section_prt=True,
         top_n=None,
         use_sections=True)
     # print('FFFF', desc2nts['flds'])
     # Write user GO IDs in sections
     objgowr = WrXlsxSortedGos("init", sortobj, self.objgrpd.ver_list)
     if fout_xlsx is not None:
         kws_xlsx = {'shade_hdrgos':verbose}
         if not verbose:
             kws_xlsx['prt_flds'] = [f for f in desc2nts['flds'] if f not in self.excl_flds]
         objgowr.wr_xlsx_nts(fout_xlsx, desc2nts, **kws_xlsx)
         fout_desc = '{BASE}_desc.txt'.format(BASE=os.path.splitext(fout_xlsx)[0])
         self._wr_ver_n_key(fout_desc, verbose)
     if fout_txt is not None:
         self._wr_txt_nts(fout_txt, desc2nts, objgowr, verbose)
     if fout_xlsx is None and fout_txt is None:
         self._prt_ver_n_key(sys.stdout, verbose)
         prtfmt = self._get_prtfmt(objgowr, verbose)
         summary_dct = objgowr.prt_txt_desc2nts(sys.stdout, desc2nts, prtfmt)
         self._prt_ver_n_key(sys.stdout, verbose)
         if summary_dct:
             print("\n{N} GO IDs in {S} sections".format(
                 N=desc2nts['num_items'], S=desc2nts['num_sections']))
Exemplo n.º 3
0
def _wr_xlsx(name, grprobj, **kws):
    """Group, sort, and print xlsx file."""
    # Exclude ungrouped "Misc." section of sections var(sec_rd)
    fout_xlsx = "{NAME}.xlsx".format(NAME=name)
    # kws Sorter: hdrgo_prt section_prt top_n use_sections
    sortobj = Sorter(grprobj)
    desc2nts = sortobj.get_desc2nts(**kws)
    objwr = WrXlsxSortedGos(name, sortobj)
    # kws WrXlsxSortedGos wr_xlsx_nts: title hdrs
    objwr.wr_xlsx_nts(fout_xlsx, desc2nts, **kws)
Exemplo n.º 4
0
def _wr_xlsx(name, grprobj, **kws):
    """Group, sort, and print xlsx file."""
    # print('\nTEST {} kws_sortobj: {}'.format(name, kws))
    # KWS SORT OBJ
    kws_sort = {'sortby', 'hdrgo_sortby', 'section_sortby'}
    # KWS SORT FUNC: hdrgo_prt section_prt top_n use_sections prtfmt
    # Exclude ungrouped "Misc." section of sections var(sec_rd)
    fout_xlsx = "{NAME}.xlsx".format(NAME=name)
    # kws Sorter: hdrgo_prt section_prt top_n use_sections
    sortobj = Sorter(grprobj, **{k:v for k, v in kws.items() if k in kws_sort})
    desc2nts = sortobj.get_desc2nts(**kws)
    objwr = WrXlsxSortedGos(name, sortobj)
    # kws WrXlsxSortedGos wr_xlsx_nts: title hdrs
    objwr.wr_xlsx_nts(fout_xlsx, desc2nts, **kws)
Exemplo n.º 5
0
 def wr_xlsx(self, fout_xlsx):
     """Print grouped GOEA results into an xlsx file."""
     objwr = WrXlsxSortedGos("GOEA", self.sortobj)
     #### fld2fmt['ratio_in_study'] = '{:>8}'
     #### fld2fmt['ratio_in_pop'] = '{:>12}'
     #### ntfld2wbfmtdict = {
     # ntfld_wbfmt = {
     #     'ratio_in_study': {'align':'right'},
     #     'ratio_in_pop':{'align':'right'}}
     kws_xlsx = {
         'title': self.ver_list,
         'fld2fmt': {f:'{:8.2e}' for f in self.flds_cur if f[:2] == 'p_'},
         #'ntfld_wbfmt': ntfld_wbfmt,
         #### 'ntval2wbfmtdict': ntval2wbfmtdict,
         #'hdrs': [],
         'prt_flds': self.flds_cur}
     objwr.wr_xlsx_nts(fout_xlsx, self.desc2nts, **kws_xlsx)
Exemplo n.º 6
0
 def wr_xlsx(self, fout_xlsx):
     """Print grouped GOEA results into an xlsx file."""
     objwr = WrXlsxSortedGos("GOEA", self.sortobj)
     #### fld2fmt['ratio_in_study'] = '{:>8}'
     #### fld2fmt['ratio_in_pop'] = '{:>12}'
     #### ntfld2wbfmtdict = {
     # ntfld_wbfmt = {
     #     'ratio_in_study': {'align':'right'},
     #     'ratio_in_pop':{'align':'right'}}
     kws_xlsx = {
         'title': self.ver_list,
         'fld2fmt': {f:'{:8.2e}' for f in self.flds_cur if f[:2] == 'p_'},
         #'ntfld_wbfmt': ntfld_wbfmt,
         #### 'ntval2wbfmtdict': ntval2wbfmtdict,
         #'hdrs': [],
         'prt_flds': self.flds_cur}
     objwr.wr_xlsx_nts(fout_xlsx, self.desc2nts, **kws_xlsx)
Exemplo n.º 7
0
 def wr_xlsx_nts(self, fout_xlsx, desc2nts, **kws):
     """Write grouped and sorted user GO IDs into an xlsx file."""
     # kws (content): hdrgo_prt section_prt use_sections
     # kws (prt fmt): title fld2col_widths ...
     xlsxobj = WrXlsxSortedGos("sortname", self)
     xlsxobj.wr_xlsx_nts(fout_xlsx, desc2nts, **kws)