-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added compare_tree command to ghost-tree script and did unit tests
- Loading branch information
1 parent
010e742
commit 72ae793
Showing
5 changed files
with
70 additions
and
29 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import unittest | ||
from StringIO import StringIO | ||
|
||
import numpy as np | ||
|
||
from ghosttree.util import compare_tip_to_tip_distances | ||
|
||
|
||
# name of class corresponds to the function we are testing | ||
# we test library code NOT command line so we use the library code function | ||
# names | ||
class TestCompareTipToTipDistances(unittest.TestCase): | ||
def setUp(self): | ||
self.tree1 = StringIO(tree1) | ||
self.tree1_copy = StringIO(tree1) | ||
self.tree2 = StringIO(tree2) | ||
|
||
def test_same_trees(self): | ||
np.random.seed(1234) # remove randomness for sake of testing p-value | ||
result = compare_tip_to_tip_distances(self.tree1, self.tree1_copy) | ||
self.assertEqual(result, (1.0, 0.042, 4)) | ||
|
||
def test_different_trees(self): | ||
np.random.seed(1234) # remove randomness for sake of testing p-value | ||
coeff, p_value, n = compare_tip_to_tip_distances(self.tree1, | ||
self.tree2) | ||
self.assertAlmostEqual(coeff, 0.59603956067926978) | ||
self.assertAlmostEqual(p_value, 0.69599999999999995) | ||
self.assertEqual(n, 3) | ||
|
||
tree1 = "[example](a:0.1, 'b_b''':0.2, (c:0.3, d_d:0.4)e:0.5)f:0.0;" | ||
tree2 = "[example](a:0.1, 'b_b''':0.2, (g:0.3, d_d:0.1)e:0.1)f:0.0;" | ||
|
||
# lets you run tests in this file individually, if you want to test one | ||
# piece at a time | ||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from skbio import TreeNode | ||
from skbio.stats.distance import mantel | ||
|
||
|
||
def compare_tip_to_tip_distances(tree_fh1, tree_fh2, method="pearson"): | ||
tree1 = TreeNode.read(tree_fh1) | ||
tree2 = TreeNode.read(tree_fh2) | ||
|
||
dm1 = tree1.tip_tip_distances() | ||
dm2 = tree2.tip_tip_distances() | ||
|
||
return mantel(dm1, dm2, strict=False, method=method) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters