Skip to content

Commit

Permalink
small fix to cover
Browse files Browse the repository at this point in the history
  • Loading branch information
JLSteenwyk committed Apr 30, 2022
1 parent 0281608 commit 535bf23
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 58 deletions.
66 changes: 25 additions & 41 deletions phykit/services/tree/covarying_evolutionary_rates.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ def run(self):

# obtain corrected branch lengths where branch lengths
# are corrected by the species tree branch length
tree_zero_corr_branch_lengths = self.correct_branch_lengths(tree_zero, tree_ref)
tree_one_corr_branch_lengths = self.correct_branch_lengths(tree_one, tree_ref)
tree_zero_corr_branch_lengths, tree_one_corr_branch_lengths = self.correct_branch_lengths(tree_zero, tree_one, tree_ref)

# remove corrected BLs greater than 5
outlier_indices = []
Expand Down Expand Up @@ -102,32 +101,7 @@ def remove_outliers_based_on_indices(self, corr_branch_lengths, outlier_indices)
"""
corr_branch_lengths = [i for j, i in enumerate(corr_branch_lengths) if j not in outlier_indices]
return corr_branch_lengths

# def shared_tips(
# self,
# a,
# b
# ):
# """
# Determines what tips are shared between two trees
# -------------------------------------------------
# argv: a
# list of tips from one tree
# argv: b
# list of tips from a second tree
# """

# a_set = set(a)
# b_set = set(b)

# # check length
# if len(a_set.intersection(b_set)) > 0:
# return(list(a_set.intersection(b_set)))
# else:
# print("no common tips")
# sys.exit()


def prune_tips(
self, tree, tips
):
Expand Down Expand Up @@ -195,39 +169,49 @@ def determine_if_clade_differs(

def correct_branch_lengths(
self,
t,
t0,
t1,
sp
):
"""
obtain a list of corrected branch lengths
"""

l = []
for i, s in zip(t.get_terminals(), sp.get_terminals()):
newtree = copy.deepcopy(sp)

# get tree tip names
tree_zero_tips = self.get_tip_names_from_tree(i)
l0 = []
l1 = []
for i, s in zip(t0.get_terminals(), sp.get_terminals()):
for term in sp.get_terminals():
if set(term.name)==set(i.name):
l0.append(i.branch_length/s.branch_length)

for term in newtree.get_terminals():
for term in t1.get_terminals():
if set(term.name)==set(i.name):
l.append(i.branch_length/s.branch_length)
l1.append(i.branch_length/s.branch_length)

for i, s in zip(t.get_nonterminals(), sp.get_nonterminals()):
for i, s in zip(t0.get_nonterminals(), sp.get_nonterminals()):
newtree = copy.deepcopy(sp)
newtree1 = copy.deepcopy(t1)

# get tree tip names
tree_zero_tips = self.get_tip_names_from_tree(i)

newtree = newtree.common_ancestor(tree_zero_tips)

newtree1 = newtree1.common_ancestor(tree_zero_tips)

for nonterm in newtree.get_nonterminals():
try:
l.append(i.branch_length/nonterm.branch_length)
l0.append(i.branch_length/nonterm.branch_length)
except:
l0.append("NA")
break

for nonterm in newtree1.get_nonterminals():
try:
l1.append(i.branch_length/nonterm.branch_length)
except:
l.append("NA")
l1.append("NA")
break



return(l)
return(l0, l1)
2 changes: 1 addition & 1 deletion phykit/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.11.9'
__version__ = '1.11.10'
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class TestCovaryingEvolutionaryRates(object):
@patch("builtins.print")
def test_covarying_evolutionary_rates(self, mocked_print):
expected_result = "0.5436\t0.054828"
expected_result = "0.5755\t0.03959"
testargs = [
"phykit",
"covarying_evolutionary_rates",
Expand All @@ -29,7 +29,7 @@ def test_covarying_evolutionary_rates(self, mocked_print):

@patch("builtins.print")
def test_covarying_evolutionary_rates_alias(self, mocked_print):
expected_result = "0.5436\t0.054828"
expected_result = "0.5755\t0.03959"
testargs = [
"phykit",
"cover",
Expand All @@ -56,19 +56,19 @@ def test_covarying_evolutionary_rates_verbose(self, mocked_print):
with patch.object(sys, "argv", testargs):
Phykit()
assert mocked_print.mock_calls == [
call(f"{-0.333}\t{-1.3686}"),
call(f"{0.2747}\t{1.7774}"),
call(f"{0.2747}\t{0.0691}"),
call(f"{1.3905}\t{0.5971}"),
call(f"{0.2747}\t{-0.2188}"),
call(f"{0.2747}\t{0.0691}"),
call(f"{-0.3428}\t{-0.223}"),
call(f"{-3.1873}\t{-1.5688}"),
call(f"{0.2747}\t{0.0691}"),
call(f"{0.2747}\t{1.5686}"),
call(f"{0.2747}\t{-1.4737}"),
call(f"{0.2747}\t{0.0691}"),
call(f"{0.2747}\t{0.6333}")
call(f"{-0.333}\t{-0.2246}"),
call(f"{0.2747}\t{0.1191}"),
call(f"{0.2747}\t{0.1191}"),
call(f"{1.3905}\t{0.7501}"),
call(f"{0.2747}\t{0.1191}"),
call(f"{0.2747}\t{0.1191}"),
call(f"{-0.3428}\t{-0.2302}"),
call(f"{-3.1873}\t{-1.8388}"),
call(f"{0.2747}\t{0.1191}"),
call(f"{0.2747}\t{-1.3055}"),
call(f"{0.2747}\t{2.6302}"),
call(f"{0.2747}\t{0.1191}"),
call(f"{0.2747}\t{-0.4956}")
]

@patch("builtins.print")
Expand Down Expand Up @@ -169,7 +169,7 @@ def test_covarying_evolutionary_rates_tree_topologies_do_not_match(self, mocked_

@patch("builtins.print")
def test_covarying_evolutionary_rates(self, mocked_print):
expected_result = "0.5874\t0.044626"
expected_result = "0.5755\t0.03959"
testargs = [
"phykit",
"covarying_evolutionary_rates",
Expand Down

0 comments on commit 535bf23

Please sign in to comment.