Skip to content

Commit

Permalink
cleaned up logic in tip to tip distances function
Browse files Browse the repository at this point in the history
  • Loading branch information
JLSteenwyk committed Sep 15, 2024
1 parent 88b234e commit f5f8855
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
15 changes: 9 additions & 6 deletions phykit/services/tree/tip_to_tip_distance.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sys
from typing import Dict

from Bio.Phylo.BaseTree import TreeMixin

Expand All @@ -12,21 +13,23 @@ def __init__(self, args) -> None:
def run(self):
tree_zero = self.read_tree_file()

# determine is leaves exists
self.check_leaves(tree_zero, self.tip_1, self.tip_2)

# print distance
print(round(TreeMixin.distance(tree_zero, self.tip_1, self.tip_2), 4))

def check_leaves(self, tree_zero, tip_1, tip_2):
leaf1 = TreeMixin.find_any(tree_zero, tip_1)
if (bool(leaf1)) == False:
if not bool(leaf1):
print(tip_1, "not on tree\nExiting...")
sys.exit()
leaf2 = TreeMixin.find_any(tree_zero, tip_2)
if (bool(leaf2)) == False:
if not bool(leaf2):
print(tip_2, "not on tree\nExiting...")
sys.exit()

def process_args(self, args):
return dict(tree_file_path=args.tree_zero, tip_1=args.tip_1, tip_2=args.tip_2)
def process_args(self, args) -> Dict[str, str]:
return dict(
tree_file_path=args.tree_zero,
tip_1=args.tip_1,
tip_2=args.tip_2,
)
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import pytest
import sys
from math import isclose
from mock import patch, call
from pathlib import Path
from textwrap import dedent
import pytest
import sys

from phykit.phykit import Phykit

Expand Down Expand Up @@ -96,4 +94,4 @@ def test_tip_to_tip_distance_bad_file_path(self, mocked_print):
Phykit()

assert pytest_wrapped_e.type == SystemExit
assert pytest_wrapped_e.value.code == 2
assert pytest_wrapped_e.value.code == 2

0 comments on commit f5f8855

Please sign in to comment.