Skip to content

Commit

Permalink
create parent folders if necessary in render
Browse files Browse the repository at this point in the history
  • Loading branch information
willdumm committed Aug 26, 2024
1 parent 10eabc7 commit ee0bc22
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions gctree/branching_processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import numpy as np
import warnings
import random
import os
import scipy.special as scs
import scipy.optimize as sco
import ete3
Expand All @@ -36,6 +35,7 @@
from typing import Tuple, Dict, List, Union, Set, Callable, Mapping, Sequence, Optional
from decimal import Decimal
import math
from pathlib import Path

sequence_resolutions = hdag.parsimony_utils.standard_nt_ambiguity_map_gap_as_char.get_sequence_resolution_func(
"sequence"
Expand Down Expand Up @@ -485,6 +485,10 @@ def render(
show_nuc_muts: If True, annotate branches with nucleotide mutations. If False, and frame is provided, then branches
will be annotated with amino acid mutations.
"""
# Create parent directories of outfile if they don't exist
outfile = Path(outfile)
outfile.parent.mkdir(parents=True, exist_ok=True)

if frame is not None and frame not in (1, 2, 3):
raise RuntimeError("frame must be 1, 2, or 3")

Expand Down Expand Up @@ -675,10 +679,10 @@ def my_layout(node):
description=f"abundance={node.abundance}",
)
)
AlignIO.write(
aln, open(os.path.splitext(outfile)[0] + ".fasta", "w"), "fasta"
)
return tree_copy.render(outfile, tree_style=ts)
with open(outfile.with_suffix(".fasta"), "w") as fh:
AlignIO.write(aln, fh, "fasta")

return tree_copy.render(str(outfile), tree_style=ts)

def feature_colormap(
self,
Expand Down

0 comments on commit ee0bc22

Please sign in to comment.