def test_validate_counts_vectors_suppress_cast(self): # suppress_cast is passed through to _validate_counts_vector obs_u, obs_v = _validate_counts_vectors( [42.2, 42.1, 0], [42.2, 42.1, 1.0], suppress_cast=True) npt.assert_array_equal(obs_u, np.array([42.2, 42.1, 0])) npt.assert_array_equal(obs_v, np.array([42.2, 42.1, 1.0])) self.assertEqual(obs_u.dtype, float) self.assertEqual(obs_v.dtype, float) with self.assertRaises(TypeError): _validate_counts_vectors([0.0], [1], suppress_cast=False)
def test_validate_counts_vectors_suppress_cast(self): # suppress_cast is passed through to _validate_counts_vector obs_u, obs_v = _validate_counts_vectors([42.2, 42.1, 0], [42.2, 42.1, 1.0], suppress_cast=True) npt.assert_array_equal(obs_u, np.array([42.2, 42.1, 0])) npt.assert_array_equal(obs_v, np.array([42.2, 42.1, 1.0])) self.assertEqual(obs_u.dtype, float) self.assertEqual(obs_v.dtype, float) with self.assertRaises(TypeError): _validate_counts_vectors([0.0], [1], suppress_cast=False)
def test_validate_counts_vectors_invalid_input(self): # checks that are caught by the calls to _validate_counts_vector with self.assertRaises(ValueError): _validate_counts_vectors([0, 1, 1, 0, 2], [0, 0, 2, -1, 3]) with self.assertRaises(ValueError): _validate_counts_vectors([0, 0, 2, -1, 3], [0, 1, 1, 0, 2]) # len of vectors not equal u_counts = [1, 2] v_counts = [1, 1, 1] self.assertRaises(ValueError, _validate_counts_vectors, u_counts, v_counts) u_counts = [1, 2, 3] v_counts = [1, 1] self.assertRaises(ValueError, _validate_counts_vectors, u_counts, v_counts)
def test_validate_counts_vectors(self): # basic valid input (n=2) obs_u, obs_v = _validate_counts_vectors([0, 1, 1, 0, 2], [0, 0, 2, 1, 3]) npt.assert_array_equal(obs_u, np.array([0, 1, 1, 0, 2])) npt.assert_array_equal(obs_v, np.array([0, 0, 2, 1, 3])) # basic valid input (n=3) actual = _validate_counts_vectors([0, 1, 1, 0, 2], [0, 0, 2, 1, 3], [1, 1, 1, 1, 1]) npt.assert_array_equal(actual[0], np.array([0, 1, 1, 0, 2])) npt.assert_array_equal(actual[1], np.array([0, 0, 2, 1, 3])) npt.assert_array_equal(actual[2], np.array([1, 1, 1, 1, 1])) # empty counts vectors obs_u, obs_v = _validate_counts_vectors(np.array([], dtype=int), np.array([], dtype=int)) npt.assert_array_equal(obs_u, np.array([])) npt.assert_array_equal(obs_v, np.array([]))
def _validate(u_counts, v_counts, otu_ids, tree): _validate_counts_vectors(u_counts, v_counts, suppress_cast=True) _validate_otu_ids_and_tree(counts=u_counts, otu_ids=otu_ids, tree=tree)