예제 #1
0
def extract_clades(newick_file, processed_newick_out=None):
    """ the outer logic for tree splitting """
    # preprocess tree
    print("Pre-processing tree ({})".format(newick_file))
    tree = PhyloTree(newick_file)
    R = tree.get_midpoint_outgroup()
    tree.set_outgroup(R)
    tree.ladderize()
    tree.convert_to_ultrametric()
    if (processed_newick_out is not None):
        tree.write(format=1, outfile=processed_newick_out)
    # calculate clades
    print("Calling clades ({})".format(newick_file))

    def get_branch_length(node):
        for l in node:
            return l.get_distance(node)

    len_tree = len(tree)
    dist_tree = get_branch_length(tree)

    def condition_discard(node, tree):
        return (len(node) < 3)

    def condition_ok(node, tree):
        return len(node) < max(10, len_tree / 50)

    branches = get_pruned_branch(tree, tree, condition_discard, condition_ok,
                                 [])
    clades = {}
    for i, branch in enumerate(
            sorted(branches, key=lambda nodes: -1 * len(nodes))):
        clades[str(i + 1)] = [node.name for node in branch]
    return clades
예제 #2
0
파일: pdf_tree.py 프로젝트: nickloman/ebov
def main(args):
	if args.alignment:
		t = PhyloTree(args.tree, alignment=args.alignment, alg_format='fasta')
	else:
		t = PhyloTree(args.tree)

	if args.highlight_new:
		runs = read_runs(args.highlight_new)

	t.set_outgroup('EM_079422')
	t.ladderize()

	ts = TreeStyle()
	ts.show_leaf_name = False
	ts.show_branch_support = False
	ts.layout_fn = layout

	thick_hz_line = NodeStyle()
	thick_hz_line["hz_line_width"] = 8
	t.set_style(thick_hz_line)
	#t.children[0].set_style(thick_hz_line)
	#t.children[1].set_style(thick_hz_line)

	thick_vt_line = NodeStyle()
	thick_vt_line["vt_line_width"] = 4
	t.set_style(thick_vt_line)

	# header
	if not args.hide_annotations:
		ts.aligned_header.add_face(MyTextFace('Sample identifier', fstyle='Bold', fsize=8, tight_text=False), column = 1)
		ts.aligned_header.add_face(MyTextFace('Prefecture', fstyle='Bold', fsize=8, tight_text=False), column = 2)
		ts.aligned_header.add_face(MyTextFace('Sous-prefecture', fstyle='Bold', fsize=8, tight_text=False), column = 3)
		ts.aligned_header.add_face(MyTextFace('Village', fstyle='Bold', fsize=8, tight_text=False), column = 4)
		ts.aligned_header.add_face(MyTextFace('Sample received', fstyle='Bold', fsize=8, tight_text=False), column = 5)

	if args.positions:
		positions = read_positions(args.positions)

		alg_header = RulerFace(positions,
                              col_width=11,
                              height=0, # set to 0 if dont want to use values
                              kind="stick",
                              hlines = [0],
                              hlines_col = ["white"], # trick to hide hz line
                              )

		ts.aligned_header.add_face(alg_header, 6)

	#legend
	if args.legend:
		legend = {}
		for s in samples.values():
			legend[s['prefec']] = s['prefec__colour']
		for p in sorted(legend.keys()):
			ts.legend.add_face(CircleFace(4, legend[p]), column=0)
			ts.legend.add_face(MyTextFace(p, fsize=6, tight_text=False), column=1)	
		ts.legend_position=1

	if args.circular:
		ts.mode = "c"
		ts.arc_start = -180 # 0 degrees = 3 o'clock
		ts.arc_span = 180

#	t.show(tree_style=ts)
	t.render(args.output, tree_style=ts, w=1024)
예제 #3
0
def main(args):
    if args.alignment:
        t = PhyloTree(args.tree, alignment=args.alignment, alg_format='fasta')
    else:
        t = PhyloTree(args.tree)

    if args.highlight_new:
        runs = read_runs(args.highlight_new)

    t.set_outgroup('EM_079422')
    t.ladderize()

    ts = TreeStyle()
    ts.show_leaf_name = False
    ts.show_branch_support = False
    ts.layout_fn = layout

    thick_hz_line = NodeStyle()
    thick_hz_line["hz_line_width"] = 8
    t.set_style(thick_hz_line)
    #t.children[0].set_style(thick_hz_line)
    #t.children[1].set_style(thick_hz_line)

    thick_vt_line = NodeStyle()
    thick_vt_line["vt_line_width"] = 4
    t.set_style(thick_vt_line)

    # header
    if not args.hide_annotations:
        ts.aligned_header.add_face(MyTextFace('Sample identifier', fstyle='Bold', fsize=8, tight_text=False), column = 1)
        ts.aligned_header.add_face(MyTextFace('Prefecture', fstyle='Bold', fsize=8, tight_text=False), column = 2)
        ts.aligned_header.add_face(MyTextFace('Sous-prefecture', fstyle='Bold', fsize=8, tight_text=False), column = 3)
        ts.aligned_header.add_face(MyTextFace('Village', fstyle='Bold', fsize=8, tight_text=False), column = 4)
        ts.aligned_header.add_face(MyTextFace('Sample received', fstyle='Bold', fsize=8, tight_text=False), column = 5)

    if args.positions:
        positions = read_positions(args.positions)

        alg_header = RulerFace(positions,
                              col_width=11,
                              height=0, # set to 0 if dont want to use values
                              kind="stick",
                              hlines = [0],
                              hlines_col = ["white"], # trick to hide hz line
                              )

        ts.aligned_header.add_face(alg_header, 6)

    #legend
    if args.legend:
        legend = {}
        for s in list(samples.values()):
            legend[s['prefec']] = s['prefec__colour']
        for p in sorted(legend.keys()):
            ts.legend.add_face(CircleFace(4, legend[p]), column=0)
            ts.legend.add_face(MyTextFace(p, fsize=6, tight_text=False), column=1)    
        ts.legend_position=1

    if args.circular:
        ts.mode = "c"
        ts.arc_start = -180 # 0 degrees = 3 o'clock
        ts.arc_span = 180

#    t.show(tree_style=ts)
    t.render(args.output, tree_style=ts, w=1024)