Ejemplo n.º 1
0
 def _init_fld2col_widths():
     """Return default column widths for writing an Excel Spreadsheet."""
     # GO info namedtuple fields: NS dcnt level depth GO D1 name
     # GO header namedtuple fields: format_txt hdr_idx
     fld2col_widths = GoSubDagWr.fld2col_widths.copy()
     for fld, wid in GOEnrichmentStudy.default_fld2col_widths.items():
         fld2col_widths[fld] = wid
     for fld in get_hdridx_flds():
         fld2col_widths[fld] = 2
     return fld2col_widths
Ejemplo n.º 2
0
 def _init_fld2col_widths(self):
     """Return default column widths for writing an Excel Spreadsheet."""
     # GO info namedtuple fields: NS dcnt level depth GO D1 name
     # GO header namedtuple fields: format_txt hdr_idx
     fld2col_widths = GoSubDagWr.fld2col_widths.copy()
     for fld, wid in self.oprtfmt.default_fld2col_widths.items():
         fld2col_widths[fld] = wid
     for fld in get_hdridx_flds():
         fld2col_widths[fld] = 2
     return fld2col_widths
Ejemplo n.º 3
0
 def get_go2nt(self, usr_go2nt):
     """Combine user namedtuple fields, GO object fields, and format_txt."""
     gos_all = self.get_gos_all()
     # Minimum set of namedtuple fields available for use with Sorter on grouped GO IDs
     prt_flds_all = get_hdridx_flds() + self.gosubdag.prt_attr['flds']
     if not usr_go2nt:
         return self.__init_go2nt_dflt(gos_all, prt_flds_all)
     usr_nt_flds = next(iter(usr_go2nt.values()))._fields
     # If user namedtuple already contains all fields available, then return usr_go2nt
     if not set(prt_flds_all).difference(usr_nt_flds):
         return self._init_go2nt_aug(usr_go2nt)
     # Otherwise, combine user fields and default Sorter fields
     return self.__init_go2nt_w_usr(gos_all, usr_go2nt, prt_flds_all)
Ejemplo n.º 4
0
    class NtMaker:
        """Make namedtuples for GO IDs in grouper."""

        ntobj = cx.namedtuple("NtHdrIdx", " ".join(get_hdridx_flds()))

        def __init__(self, obj):
            self.grpname = obj.grpname
            self.usrgos = obj.usrgos
            self.hdrgos = obj.hdrobj.hdrgos
            ## assert "GO:0008150" in self.hdrgos
            self.go2obj = obj.gosubdag.go2obj
            self.hdrgo2usrgos = obj.hdrgo2usrgos
            self.hdrgo_is_usrgo = obj.hdrgo_is_usrgo

        def get_nt(self, goid_user):
            """Get Grouper namedtuple for user GO ID."""
            goid_main = self.go2obj[goid_user].id
            goid_in_hdrgos = goid_main in self.hdrgo2usrgos
            goid_in_usrgos = goid_user in self.hdrgo_is_usrgo
            # format_txt = int(goid_in_hdrgos or goobj.id in self.hdrgos)
            format_txt = int(goid_in_hdrgos)
            # namedtuple grouping fields
            hdr1usr01 = self._get_hdr1usr01(goid_in_hdrgos, goid_in_usrgos)
            return self.ntobj(format_txt=format_txt,
                              hdr_idx=format_txt,
                              is_hdrgo=goid_in_hdrgos,
                              is_usrgo=goid_in_usrgos,
                              num_usrgos=self._get_num_usrgos(
                                  goid_user, goid_in_hdrgos, goid_in_usrgos),
                              hdr1usr01=hdr1usr01)

        def _get_num_usrgos(self, goid_main, goid_in_hdrgos, goid_in_usrgos):
            """Get the number of user GO IDs under a header GO ID."""
            if not goid_in_hdrgos:
                return "."
            num_goids = len(self.hdrgo2usrgos[goid_main]) + int(goid_in_usrgos)
            assert num_goids != 0, "{NAME} MAIN({GO}) num_goids({N})\n{HDRUSR}".format(
                NAME=self.grpname,
                GO=goid_main,
                N=num_goids,
                HDRUSR="******".join(sorted(self.hdrgos)))
            return num_goids

        @staticmethod
        def _get_hdr1usr01(goid_in_hdrgos, goid_in_usrgos):
            """Get string indicating if GO is also a header GO."""
            if goid_in_hdrgos:
                return "**" if goid_in_usrgos else "*"
            return ""