def print_events(self, node): """Prints the events that occur on a node""" print "-" * 20 print "%s (%.3f sub/site):" % (node.name, node.dist), if self.events: if self.events[node] == "dup": print "duplication" elif self.events[node] == "spec": print "speciation" elif self.events[node] == "gene": print "extant" losses = util.groupby(lambda x: x[0], self.losses) if node in losses: print len(losses[node]), "gene losses" for i, (node, schild) in enumerate(losses[node]): print "loss %d in species %s" % (i+1, str(schild.name)) for sleaf in schild.leaf_names(): print " %s" % sleaf else: print "no reconciliation available"
def draw_matches(self, sp, chrom, start, end, drawn=None): vis = [] if drawn is None: drawn = set() # build list of matches in order of drawing for gene in iter_chrom(self.db.get_regions(sp, chrom), start, end): # need to sort matches by genome order so that mult-genome synteny # is drawn top-down # get orthologs genes2 = [x for x in self.orth_lookup.get(gene.data["ID"], []) if x in self.region_layout] if len(genes2) == 0: continue rows = util.groupby(lambda x: self.region_layout[x].y, genes2) keys = util.sort(rows.keys(), reverse=True) rows = util.mget(rows, keys) l = self.region_layout for i in range(1, len(rows)): for botGene in rows[i]: gene1 = self.db.get_region(botGene) for topGene in rows[i-1]: if (botGene, topGene) in drawn: continue drawn.add((botGene, topGene)) gene2 = self.db.get_region(topGene) y1 = l[topGene].y y2 = l[botGene].y + 1 x1 = l[topGene].x x2 = l[topGene].x + gene2.length() x3 = l[botGene].x + gene1.length() x4 = l[botGene].x if self.fat_matches: vis.append(quads( self.colors["matches"], x1, y1, x2, y1, x3, y2, x4, y2)) vis.append(lines(self.colors["matches"], x1, y1, x4, y2)) return group(* vis)
def draw_matches(self, sp, chrom, start, end, drawn=None): vis = [] if drawn is None: drawn = set() # build list of matches in order of drawing for gene in iter_chrom(self.db.get_regions(sp, chrom), start, end): # need to sort matches by genome order so that mult-genome synteny # is drawn top-down # get orthologs genes2 = [ x for x in self.orth_lookup.get(gene.data["ID"], []) if x in self.region_layout ] if len(genes2) == 0: continue rows = util.groupby(lambda x: self.region_layout[x].y, genes2) keys = util.sort(rows.keys(), reverse=True) rows = util.mget(rows, keys) l = self.region_layout for i in range(1, len(rows)): for botGene in rows[i]: gene1 = self.db.get_region(botGene) for topGene in rows[i - 1]: if (botGene, topGene) in drawn: continue drawn.add((botGene, topGene)) gene2 = self.db.get_region(topGene) y1 = l[topGene].y y2 = l[botGene].y + 1 x1 = l[topGene].x x2 = l[topGene].x + gene2.length() x3 = l[botGene].x + gene1.length() x4 = l[botGene].x if self.fat_matches: vis.append( quads(self.colors["matches"], x1, y1, x2, y1, x3, y2, x4, y2)) vis.append( lines(self.colors["matches"], x1, y1, x4, y2)) return group(*vis)
def makeFamilyGeneNames(self): """Tries to name and describe a family using its genes""" self.cur.execute("""SELECT g.famid, g.common_name, g.description FROM Genes g """) fams = util.groupby(lambda x: x[0], self.cur) familyGeneNames = {} for famid, rows in fams.iteritems(): names = util.unique([ "".join([i for i in x if not i.isdigit() and i != "-"]) for x in util.cget(rows, 1) if x != "" ]) names.sort() description = self.getFamDescription(util.cget(rows, 2)) familyGeneNames[famid] = (",".join(names), description) return familyGeneNames
def makeFamilyGeneNames(self): """Tries to name and describe a family using its genes""" self.cur.execute("""SELECT g.famid, g.common_name, g.description FROM Genes g """) fams = util.groupby(lambda x: x[0], self.cur) familyGeneNames = {} for famid, rows in fams.iteritems(): names = util.unique(["".join([i for i in x if not i.isdigit() and i != "-"]) for x in util.cget(rows, 1) if x != ""]) names.sort() description = self.getFamDescription(util.cget(rows, 2)) familyGeneNames[famid] = (",".join(names), description) return familyGeneNames