def test_subset_samples(self): """Correctly subsets samples in a table.""" obs = _subset_table(json_table_str=self.biom_str1, axis='sample', ids=['f4', 'f2'], hdf5_biom=None) obs = parse_biom_table(list(obs[0])) self.assertEqual(len(obs.ids()), 2) self.assertEqual(len(obs.ids(axis='observation')), 14) self.assertTrue('f4' in obs.ids()) self.assertTrue('f2' in obs.ids())
def test_subset_observations(self): """Correctly subsets observations in a table.""" obs = _subset_table(json_table_str=self.biom_str1, axis='observation', ids=['None2', '879972'], hdf5_biom=None) obs = parse_biom_table(list(obs[0])) self.assertEqual(len(obs.ids()), 9) self.assertEqual(len(obs.ids(axis='observation')), 2) self.assertTrue('None2' in obs.ids(axis='observation')) self.assertTrue('879972' in obs.ids(axis='observation'))
def test_subset_samples_hdf5(self): """Correctly subsets samples in a hdf5 table""" cwd = os.getcwd() if '/' in __file__: os.chdir(__file__.rsplit('/', 1)[0]) obs = _subset_table(hdf5_biom='test_data/test.biom', axis='sample', ids=[u'Sample1', u'Sample2', u'Sample3'], json_table_str=None) os.chdir(cwd) obs = obs[0] self.assertEqual(len(obs.ids()), 3) self.assertEqual(len(obs.ids(axis='observation')), 5) self.assertTrue(u'Sample1' in obs.ids()) self.assertTrue(u'Sample2' in obs.ids()) self.assertTrue(u'Sample3' in obs.ids())
def test_invalid_input(self): """Correctly raises politically correct error upon invalid input.""" with self.assertRaises(ValueError): _subset_table(hdf5_biom=None, json_table_str=self.biom_str1, axis='foo', ids=['f2', 'f4']) with self.assertRaises(ValueError): _subset_table(hdf5_biom=None, json_table_str=None, axis='sample', ids=['f2', 'f4']) with self.assertRaises(ValueError): _subset_table(json_table_str=self.biom_str1, hdf5_biom='foo', axis='sample', ids=['f2', 'f4'])