From 59b1b494297d5c2cd7ac55c94c32ac46298acfc0 Mon Sep 17 00:00:00 2001 From: Merit Kayastha <90002479+mkayasth@users.noreply.github.com> Date: Fri, 10 May 2024 01:04:55 -0400 Subject: [PATCH] Update tree_maker.py --- .../neighborJoining/tree_maker.py | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/fullSequenceAnalysis/neighborJoining/tree_maker.py b/fullSequenceAnalysis/neighborJoining/tree_maker.py index b1461ea..056e174 100644 --- a/fullSequenceAnalysis/neighborJoining/tree_maker.py +++ b/fullSequenceAnalysis/neighborJoining/tree_maker.py @@ -3,23 +3,33 @@ from Bio import Phylo import matplotlib.pyplot as plt -# Parse the Newick string to create a Phylo tree object. +# Parsing the Newick string to create a Phylo tree object. tree = Phylo.read("fullSequence-output/tree.txt", "newick") -# Set up a matplotlib figure. -fig = plt.figure(figsize=(15, 10), dpi=100) + +fig = plt.figure(figsize=(20, 15), dpi=300) axes = fig.add_subplot(1, 1, 1) +# formatting the branch labels to 3 significant figures. +def format_branch_length(clade): + if clade.branch_length is not None: + return f"{clade.branch_length:.3g}" + + +Phylo.draw(tree, do_show=False, axes=axes, branch_labels=format_branch_length) -Phylo.draw(tree, do_show=False, axes=axes, branch_labels=lambda c: c.branch_length) -axes.set_title('Phylogenetic Tree', fontsize=24) +axes.set_title('Phylogenetic Tree', fontsize=26) -# setting style. +# Setting style for the tree lines. for line in axes.get_lines(): - line.set_linewidth(3) -plt.setp(axes.get_xticklabels(), fontsize=20) -plt.setp(axes.get_yticklabels(), fontsize=20) + line.set_linewidth(3) + +for lbl in axes.findobj(match=lambda obj: isinstance(obj, plt.Text)): + lbl.set_fontsize(16) + + + # Saving the figure to a JPEG file. plt.savefig("fullSequence-output/tree.jpg", format='jpg', dpi=300)