def draw_branch_mark(arg, layout, node=None, parent=None, pos=None, chroms=None, age=None, col=(0, 0, 1)): """Draw a mark on a branch of an ARG""" if node is None: node = arglib.split_to_arg_branch(arg, pos, chroms) if parent is None: assert pos is not None parent = arg.get_local_parent(node, pos) if node and parent: if age is None: t = random.uniform(layout[node][1], layout[parent][1]) else: t = layout[node][1] + (age - node.age) nx, ny = layout[node] return draw_mark(nx, t, col=col) else: return group()
def draw_branch(arg, layout, node=None, parent=None, chroms=None, pos=None, col=None): """Draw a mark on a branch of an ARG""" if node is None: node = arglib.split_to_arg_branch(arg, pos, chroms) if parent is None: assert pos is not None parent = arg.get_local_parent(node, pos) if node and parent: x1, y1, x2, y2 = get_branch_layout(layout, node, parent) if col is None: return lines(x1, y1, x2, y2) else: return lines(color(*col), x1, y1, x2, y2) else: return group()
def draw_branch_mark(arg, layout, node=None, parent=None, pos=None, chroms=None, age=None, col=(0,0,1)): """Draw a mark on a branch of an ARG""" if node is None: node = arglib.split_to_arg_branch(arg, pos, chroms) if parent is None: assert pos is not None parent = arg.get_local_parent(node, pos) if node and parent: if age is None: t = random.uniform(layout[node][1], layout[parent][1]) else: t = layout[node][1] + (age - node.age) nx, ny = layout[node] return draw_mark(nx, t, col=col) else: return group()
def draw_arg_threads(arg, blocks, layout, sites=None, chrom_colors=None, chrom_color=[.2,.2,.8,.8], snp_colors={"compat": [1, 0, 0], "noncompat": [0, 1, 0]}, spr_alpha=1, spr_trim=10, compat=False, draw_group=None, win=None): leaf_names = set(arg.leaf_names()) # TEST: rnodes = dict((r.pos, r) for r in arg if r.event == "recomb") if draw_group is None: draw_group = group() # set chromosome color if chrom_colors is None: chrom_colors = {} for name in leaf_names: chrom_colors[name] = chrom_color spr_colors = {} for name in leaf_names: spr_colors[name] = list(chrom_colors[name]) if len(spr_colors[name]) < 4: spr_colors[name].append(1.0) spr_colors[name][3] *= spr_alpha trims = [] for k, (x1, x2) in enumerate(blocks): # calc trims length = x2 - x1 minlen = 0 spr_trim2 = min(spr_trim, (length - minlen) / 2.0) trims.append((x1 + spr_trim2, x2 - spr_trim2)) trim = trims[-1] # horizontal lines l = [] for name in leaf_names: c = chrom_colors[name] y = layout[k][name] l.extend([color(*c), trim[0], y, trim[1], y]) draw_group.append(lines(*l)) # SPRs if k > 0: l = [] # TEST: #rnode = rnodes.get(x1, None) #young = (rnode is not None and rnode.age < 500) for name in leaf_names: #c = [1,0,0] if young else spr_colors[name] c = spr_colors[name] y1 = layout[k-1][name] y2 = layout[k][name] l.extend([color(*c), trims[k-1][1], y1, trims[k][0], y2]) draw_group.append(lines(*l)) # hotspots g = group() for name in leaf_names: y = layout[k][name] g.append(hotspot("click", x1+spr_trim, y+.4, x2-spr_trim, y-.4, chrom_click(win, name, (x1, x2)))) draw_group.append(g) # SNPs tree = None if sites: l = [] for pos, col in sites.iter_region(x1, x2): split = set(sites.get_minor(pos)) & leaf_names if len(split) == 0: continue if compat: if tree is None: tree = arg.get_marginal_tree((x1+x2)/2.0) arglib.remove_single_lineages(tree) node = arglib.split_to_arg_branch(tree, pos-.5, split) if node is not None: derived = list(tree.leaf_names(node)) c = color(*snp_colors["compat"]) else: c = color(*snp_colors["noncompat"]) derived = split else: c = color(*snp_colors["compat"]) derived = split for d in derived: if d in layout[k]: y = layout[k][d] l.extend([c, pos, y+.4, pos, y-.4]) draw_group.append(lines(*l)) return draw_group
def draw_arg_threads(arg, blocks, layout, sites=None, chrom_colors=None, chrom_color=[.2, .2, .8, .8], snp_colors={ "compat": [1, 0, 0], "noncompat": [0, 1, 0] }, get_snp_color=None, spr_alpha=1, spr_trim=10, compat=False, draw_group=None, win=None): leaf_names = set(arg.leaf_names()) # TEST: rnodes = dict((r.pos, r) for r in arg if r.event == "recomb") if draw_group is None: draw_group = group() # set chromosome color if chrom_colors is None: chrom_colors = {} for name in leaf_names: chrom_colors[name] = chrom_color spr_colors = {} for name in leaf_names: spr_colors[name] = list(chrom_colors[name]) if len(spr_colors[name]) < 4: spr_colors[name].append(1.0) spr_colors[name][3] *= spr_alpha trims = [] for k, (x1, x2) in enumerate(blocks): # calc trims length = x2 - x1 minlen = 0 spr_trim2 = min(spr_trim, (length - minlen) / 2.0) trims.append((x1 + spr_trim2, x2 - spr_trim2)) trim = trims[-1] # horizontal lines l = [] for name in leaf_names: c = chrom_colors[name] y = layout[k][name] l.extend([color(*c), trim[0], y, trim[1], y]) draw_group.append(lines(*l)) # SPRs if k > 0: l = [] # TEST: #rnode = rnodes.get(x1, None) #young = (rnode is not None and rnode.age < 500) for name in leaf_names: #c = [1,0,0] if young else spr_colors[name] c = spr_colors[name] y1 = layout[k - 1][name] y2 = layout[k][name] l.extend([color(*c), trims[k - 1][1], y1, trims[k][0], y2]) draw_group.append(lines(*l)) # hotspots g = group() for name in leaf_names: y = layout[k][name] g.append( hotspot("click", x1 + spr_trim, y + .4, x2 - spr_trim, y - .4, chrom_click(win, name, (x1, x2)))) draw_group.append(g) # SNPs tree = None if sites: l = [] for pos, col in sites.iter_region(x1, x2): split = set(sites.get_minor(pos)) & leaf_names if len(split) == 0: continue if compat: if tree is None: tree = arg.get_marginal_tree((x1 + x2) / 2.0) arglib.remove_single_lineages(tree) node = arglib.split_to_arg_branch(tree, pos - .5, split) if node is not None: derived = list(tree.leaf_names(node)) c = color(*snp_colors["compat"]) else: c = color(*snp_colors["noncompat"]) derived = split else: c = color(*snp_colors["compat"]) derived = split if get_snp_color and derived: allele = sites.get(pos, next(iter(derived))) c = color(*get_snp_color(arg.chrom, pos, allele)) for d in derived: if d in layout[k]: y = layout[k][d] l.extend([c, pos, y + .4, pos, y - .4]) draw_group.append(lines(*l)) return draw_group