Skip to content

Commit

Permalink
tiny tweak to prevent plots from spewing in jupyter
Browse files Browse the repository at this point in the history
  • Loading branch information
harmsm committed Dec 22, 2022
1 parent dff114d commit 0fcddda
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Features
Try it out on Google Colab
==========================

+ `Go from a few initial sequences to a full alignment <https://githubtocolab.com/harmslab/topiary-examples/blob/main/notebooks/01_seed_to_alignment.ipynb>`_
+ `Go from a few initial sequences to a full alignment <https://githubtocolab.com/harmslab/topiary-examples/blob/main/notebooks/seed-to-alignment.ipynbb>`_
+ `Build a phylogenetic tree and reconstruct ancestors <https://githubtocolab.com/harmslab/topiary-examples/blob/main/notebooks/03_alignment_to_ancestors.ipynb>`_


Expand Down
8 changes: 7 additions & 1 deletion topiary/draw/ancestor_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ def plot_ancestor_data(df_anc,
alt_anc_pp=0.25,
width_ratio=5,
anc_name=None,
anc_data_string=None):
anc_data_string=None,
close_plot=False):
"""
Create a summary plot for an ancestor.
Expand All @@ -82,6 +83,8 @@ def plot_ancestor_data(df_anc,
name of ancestor (title on graph and output file {anc_name}.pdf)
anc_data_string : str, optional
data to dump in subtitle
close_plot : bool, False
whether or not to close plot when complete
Returns
-------
Expand Down Expand Up @@ -199,4 +202,7 @@ def plot_ancestor_data(df_anc,
if anc_name is not None:
fig.savefig(f"{anc_name}.pdf",bbox_inches="tight")

if close_plot:
plt.close(fig)

return fig, ax
11 changes: 6 additions & 5 deletions topiary/raxml/ancestors.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,11 +407,12 @@ def _parse_raxml_anc_output(df,
f"# ambig gaps: {num_ambig_gaps}"]

# Plot a summary of the ancestor
topiary.draw.plot_ancestor_data(df_list[-1],
alt_anc_pp=alt_cutoff,
width_ratio=plot_width_ratio,
anc_name=anc_name,
anc_data_string=", ".join(anc_data_string))
_ = topiary.draw.plot_ancestor_data(df_list[-1],
alt_anc_pp=alt_cutoff,
width_ratio=plot_width_ratio,
anc_name=anc_name,
anc_data_string=", ".join(anc_data_string),
close_plot=True)


# Write final fasta file
Expand Down
6 changes: 5 additions & 1 deletion topiary/reports/cards.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import pandas as pd
import numpy as np
from matplotlib import pyplot as plt

import shutil
import os
Expand Down Expand Up @@ -79,10 +80,13 @@ def create_ancestor_card(anc_dict,

fig, ax = plot_ancestor_data(df,
width_ratio=6,
alt_anc_pp=alt_cutoff)
alt_anc_pp=alt_cutoff,
close_plot=False)
fig.savefig(os.path.join(output_directory,f"{a}.svg"),bbox_inches = "tight")
fig.savefig(os.path.join(output_directory,f"{a}_pp.pdf"),bbox_inches = "tight")

plt.close(fig)

taxonomic = anc_dict[a]["taxonomic_dist"]
paralog_call = anc_dict[a]["paralog_call"]

Expand Down

0 comments on commit 0fcddda

Please sign in to comment.