diff --git a/phykit/services/tree/dvmc.py b/phykit/services/tree/dvmc.py index 6db626f..246a743 100644 --- a/phykit/services/tree/dvmc.py +++ b/phykit/services/tree/dvmc.py @@ -1,71 +1,5 @@ -# import math -# from typing import Tuple - -# from .base import Tree - - -# class DVMC(Tree): -# def __init__(self, args) -> None: -# super().__init__(**self.process_args(args)) - -# def run(self): -# tree = self.read_tree_file() -# dvmc = self.determine_dvmc(tree) - -# print(round(dvmc, 4)) - -# def process_args(self, args): -# return dict(tree_file_path=args.tree) - -# def get_term_to_root_dist_and_sum_of_distances(self, tree) -> Tuple[float, float]: -# """ -# calculate root to tip distances and -# the sum of root to tip distances -# """ -# dist = [] -# sum_dist = 0 -# for term in tree.get_terminals(): -# # append root to tip distance to dist -# dist.append((tree.distance(term))) -# # keep running sum of tree distances -# sum_dist += tree.distance(term) - -# return dist, sum_dist - -# def calculate_dvmc(self, dist: float, sum_dist: float, num_spp: int) -> float: -# """ -# calculate dvmc from tip to root distances -# """ -# # determine dvmc -# # calculate average tree distance -# avg_dist = sum_dist / num_spp - -# # determine the sum of i=1 to N for (x_i-x_bar)^2 -# sumi2N = float(0.0) -# for x_i in dist: -# sumi2N += (x_i - avg_dist) ** 2 - -# # multiply sumi2N by 1/(N-1) where N is the number of spp -# # and then take the square root -# dvmc = float(0.0) -# dvmc = math.sqrt((1 / (num_spp - 1)) * sumi2N) - -# return dvmc - -# def determine_dvmc(self, tree: Tree): -# # loop through terminal branches and store -# # distances from the root to the tip in a list. -# # Also, calc the sum of all tip to root distances -# dist, sum_dist = self.get_term_to_root_dist_and_sum_of_distances(tree) - -# # determine number of taxa in the tree -# num_spp = tree.count_terminals() - -# # calculate and return dvmc -# return self.calculate_dvmc(dist, sum_dist, num_spp) - - import math +from typing import Dict from Bio.Phylo import Newick @@ -81,7 +15,7 @@ def run(self): dvmc = self.determine_dvmc(tree) print(round(dvmc, 4)) - def process_args(self, args): + def process_args(self, args) -> Dict[str, str]: return dict(tree_file_path=args.tree) def determine_dvmc(self, tree: Newick.Tree) -> float: diff --git a/phykit/services/tree/evolutionary_rate.py b/phykit/services/tree/evolutionary_rate.py index 715baaa..c0f208e 100644 --- a/phykit/services/tree/evolutionary_rate.py +++ b/phykit/services/tree/evolutionary_rate.py @@ -1,3 +1,5 @@ +from typing import Dict + from .base import Tree @@ -5,18 +7,11 @@ class EvolutionaryRate(Tree): def __init__(self, args) -> None: super().__init__(**self.process_args(args)) - def run(self): + def run(self) -> None: tree = self.read_tree_file() - total_tree_length = self.calculate_total_tree_length(tree) + total_tree_length = tree.total_branch_length() num_terminals = tree.count_terminals() print(round(total_tree_length / num_terminals, 4)) - def process_args(self, args): + def process_args(self, args) -> Dict[str, str]: return dict(tree_file_path=args.tree) - - def calculate_total_tree_length(self, tree): - total_len = float(0.0) - total_len = tree.total_branch_length() - - if isinstance(total_len, (int, float)): - return total_len diff --git a/tests/integration/tree/test_evolutionary_rate.py b/tests/integration/tree/test_evolutionary_rate.py index 4119034..1f38f3b 100644 --- a/tests/integration/tree/test_evolutionary_rate.py +++ b/tests/integration/tree/test_evolutionary_rate.py @@ -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 from phykit.phykit import Phykit