def _chk_sections(sections): """Check format of user-provided 'sections' variable""" if sections: assert len(sections[0]) == 2, \ "SECTIONS DATA MUST BE A 2-D LIST. FOUND: {S}".format(S=sections) for _, hdrgos in sections: chk_goids(hdrgos, "HdrgosSections::_chk_sections()")
def internal_get_goids_or_sections(self): """Return GO IDs, Sections/GOs, or None.""" if self.goids_fin: chk_goids(self.goids_fin, "read_goids") return {'goids' : self.goids_fin} else: # Convert dict into 2D list retaining original section order sections_2d = [] for section_name in self.sections_seen: if section_name in self.section2goids: goids = self.section2goids.get(section_name) chk_goids(goids, "GO IDs IN SECTION({S})".format(S=section_name)) sections_2d.append((section_name, goids)) return {'sections' : sections_2d}
def internal_get_goids_or_sections(self): """Return GO IDs, Sections/GOs, or None.""" if self.goids_fin: chk_goids(self.goids_fin, "read_goids") return {'goids': self.goids_fin} else: # Convert dict into 2D list retaining original section order sections_2d = [] for section_name in self.sections_seen: if section_name in self.section2goids: goids = self.section2goids.get(section_name) chk_goids(goids, "GO IDs IN SECTION({S})".format(S=section_name)) sections_2d.append((section_name, goids)) return {'sections': sections_2d}
def get_nts(self, goids=None, sortby=None): """Given GO IDs, get a list of namedtuples.""" nts = [] # User GO IDs if goids is None: goids = self.go_sources else: chk_goids(goids, "GoSubDag::get_nts") if goids: ntobj = cx.namedtuple("NtGo", " ".join(self.prt_attr['flds'])) go2nt = self.get_go2nt(goids) for goid, ntgo in self._get_sorted_go2nt(go2nt, sortby): assert ntgo is not None, "{GO} NOT IN go2nt".format(GO=goid) if goid == ntgo.GO: nts.append(ntgo) else: fld2vals = ntgo._asdict() fld2vals['GO'] = goid nts.append(ntobj(**fld2vals)) return nts
def _init_hdrgos(self, hdrgos_dflt, hdrgos_usr=None, add_dflt=True): """Initialize GO high""" # Use default GO group header values if (hdrgos_usr is None or hdrgos_usr is False) and not self.sections: return set(hdrgos_dflt) # Get GO group headers provided by user hdrgos_init = set() if hdrgos_usr: chk_goids(hdrgos_usr, "User-provided GO group headers") hdrgos_init |= set(hdrgos_usr) if self.sections: self._chk_sections(self.sections) hdrgos_sec = set([hg for _, hdrgos in self.sections for hg in hdrgos]) chk_goids(hdrgos_sec, "User-provided GO group headers in sections") hdrgos_init |= hdrgos_sec # Add default depth-01 GOs to headers, if desired if add_dflt: return set(hdrgos_init).union(hdrgos_dflt) # Return user-provided GO grouping headers return hdrgos_init
def _init_hdrgos(self, hdrgos_dflt, hdrgos_usr=None, add_dflt=True): """Initialize GO high""" # Use default GO group header values if (hdrgos_usr is None or hdrgos_usr is False) and not self.sections: return set(hdrgos_dflt) # Get GO group headers provided by user hdrgos_init = set() if hdrgos_usr: chk_goids(hdrgos_usr, "User-provided GO group headers") hdrgos_init |= set(hdrgos_usr) if self.sections: self._chk_sections(self.sections) hdrgos_sec = set( [hg for _, hdrgos in self.sections for hg in hdrgos]) chk_goids(hdrgos_sec, "User-provided GO group headers in sections") hdrgos_init |= hdrgos_sec # Add default depth-01 GOs to headers, if desired if add_dflt: return set(hdrgos_init).union(hdrgos_dflt) # Return user-provided GO grouping headers return hdrgos_init