def test_nti(self): "test that nti returns the correct value when shuffle seeded at 0" # define nec components seed(0) datamtx = array([[0.0, 0.4, 2.0, 1.3], [0.4, 0.0, 1.6, 0.2], [2.0, 1.6, 0.0, 1.1], [1.3, 0.2, 1.1, 0.0]]) all_ids = [0,1,2,3] ids_to_keep = [0,1,2] iters = 3 expected_out = 0.08151391459392235 actual_out = nti(datamtx, all_ids, ids_to_keep, iters) self.assertFloatEqual(expected_out, actual_out) # test that an unsorted list of ids returns same result unsorted_ids_to_keep = [2,0,1] seed(0) actual_out = nti(datamtx, all_ids, ids_to_keep, 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, nti, datamtx, all_ids, ids_to_keep, iters)
def test_nti(self): "test that nti returns the correct value when shuffle seeded at 0" # define nec components seed(0) datamtx = array([[0.0, 0.4, 2.0, 1.3], [0.4, 0.0, 1.6, 0.2], [2.0, 1.6, 0.0, 1.1], [1.3, 0.2, 1.1, 0.0]]) all_ids = [0, 1, 2, 3] ids_to_keep = [0, 1, 2] iters = 3 expected_out = 0.08151391459392235 actual_out = nti(datamtx, all_ids, ids_to_keep, iters) self.assertFloatEqual(expected_out, actual_out) # test that an unsorted list of ids returns same result unsorted_ids_to_keep = [2, 0, 1] seed(0) actual_out = nti(datamtx, all_ids, ids_to_keep, 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, nti, datamtx, all_ids, ids_to_keep, iters)
def test_nti(self): """Test that nti 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_nti = nti(distmat, list(arange(8)), [0,1,3,6],1000) self.assertFloatEqual(-1.2046544711672049, obs_nti)
def test_nti(self): """Test that nti 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_nti = nti(distmat, list(arange(8)), [0, 1, 3, 6], 1000) assert_almost_equal(-1.2046544711672049, obs_nti)