def test_nri(self): """tests nri returns correct result with sorted/unsorted taxa list,seed0""" # define nec components seed(0) all_ids = [0,1,2,3,4] group_ids = [0,2,3,4] iters = 3 datamtx = array([[0., 19., 2., 13., 1.], [19., 0., 15., 8., 9.], [2., 15., 0., 10., 7.], [13., 8., 10., 0., 12.], [1., 9., 7., 12., 0.]]) expected_out = 2.70454608694765 actual_out = nri(datamtx, all_ids, group_ids, iters) self.assertFloatEqual(expected_out, actual_out) # test that an unsorted list of ids returns same result unsorted_group_ids = [2,0,4,3] seed(0) actual_out = nri(datamtx, all_ids, unsorted_group_ids, iters) self.assertFloatEqual(expected_out, actual_out) # test for situations where standard deviation would be close to zero # but not actually zero due to floating point arithmetic errors datamtx = array([[0.0, 0.1, 0.1, 0.1], [0.1, 0.0, 0.1, 0.1], [0.1, 0.1, 0.0, 0.1], [0.1, 0.1, 0.1, 0.0]]) all_ids = [0,1,2,3] ids_to_keep = [0,1,2,3] self.assertRaises(ValueError, nri, datamtx, all_ids, ids_to_keep, iters)
def test_nri(self): """tests nri returns correct result with sorted/unsorted taxa list,seed0""" # define nec components seed(0) all_ids = [0, 1, 2, 3, 4] group_ids = [0, 2, 3, 4] iters = 3 datamtx = array([[0., 19., 2., 13., 1.], [19., 0., 15., 8., 9.], [2., 15., 0., 10., 7.], [13., 8., 10., 0., 12.], [1., 9., 7., 12., 0.]]) expected_out = 2.70454608694765 actual_out = nri(datamtx, all_ids, group_ids, iters) self.assertFloatEqual(expected_out, actual_out) # test that an unsorted list of ids returns same result unsorted_group_ids = [2, 0, 4, 3] seed(0) actual_out = nri(datamtx, all_ids, unsorted_group_ids, iters) self.assertFloatEqual(expected_out, actual_out) # test for situations where standard deviation would be close to zero # but not actually zero due to floating point arithmetic errors datamtx = array([[0.0, 0.1, 0.1, 0.1], [0.1, 0.0, 0.1, 0.1], [0.1, 0.1, 0.0, 0.1], [0.1, 0.1, 0.1, 0.0]]) all_ids = [0, 1, 2, 3] ids_to_keep = [0, 1, 2, 3] self.assertRaises(ValueError, nri, datamtx, all_ids, ids_to_keep, iters)
def test_nri(self): """Test that nri works correctly.""" # using the input of the distance matrix generated from this tree # '(((sp1:.06,sp2:.1)A:.031,(sp3:.001,sp4:.01)B:.2)AB:.4,((sp5:.03,sp6:.02)C:.13,(sp7:.01,sp8:.005)D:.1)CD:.3)root;' # using this tree and this clumping we get almost exact agreement # between phylocom and relatedness.py distmat = array([[ 0. , 0.16 , 0.292, 0.301, 0.951, 0.941, 0.901, 0.896], [ 0.16 , 0. , 0.332, 0.341, 0.991, 0.981, 0.941, 0.936], [ 0.292, 0.332, 0. , 0.011, 1.061, 1.051, 1.011, 1.006], [ 0.301, 0.341, 0.011, 0. , 1.07 , 1.06 , 1.02 , 1.015], [ 0.951, 0.991, 1.061, 1.07 , 0. , 0.05 , 0.27 , 0.265], [ 0.941, 0.981, 1.051, 1.06 , 0.05 , 0. , 0.26 , 0.255], [ 0.901, 0.941, 1.011, 1.02 , 0.27 , 0.26 , 0. , 0.015], [ 0.896, 0.936, 1.006, 1.015, 0.265, 0.255, 0.015, 0. ]]) seed(0) obs_nri = nri(distmat, list(arange(8)), [0,1,3,6],1000) self.assertFloatEqual(0.45181900877903675, obs_nri)
def test_nri(self): """Test that nri works correctly.""" # using the input of the distance matrix generated from this tree # '(((sp1:.06,sp2:.1)A:.031,(sp3:.001,sp4:.01)B:.2)AB:.4,((sp5:.03,sp6:.02)C:.13,(sp7:.01,sp8:.005)D:.1)CD:.3)root;' # using this tree and this clumping we get almost exact agreement # between phylocom and relatedness.py distmat = array([[0., 0.16, 0.292, 0.301, 0.951, 0.941, 0.901, 0.896], [0.16, 0., 0.332, 0.341, 0.991, 0.981, 0.941, 0.936], [0.292, 0.332, 0., 0.011, 1.061, 1.051, 1.011, 1.006], [0.301, 0.341, 0.011, 0., 1.07, 1.06, 1.02, 1.015], [0.951, 0.991, 1.061, 1.07, 0., 0.05, 0.27, 0.265], [0.941, 0.981, 1.051, 1.06, 0.05, 0., 0.26, 0.255], [0.901, 0.941, 1.011, 1.02, 0.27, 0.26, 0., 0.015], [0.896, 0.936, 1.006, 1.015, 0.265, 0.255, 0.015, 0.]]) seed(0) obs_nri = nri(distmat, list(arange(8)), [0, 1, 3, 6], 1000) assert_almost_equal(0.45181900877903675, obs_nri)