def test_balance_taxonomy(self): index_fp = os.path.join(self.results, 'index.html') balance_taxonomy(self.results, self.balances, self.tree, self.taxonomy, balance_name='c') self.assertTrue(os.path.exists(index_fp)) # test to make sure that the numerator file is there num_fp = os.path.join(self.results, 'numerator.csv') self.assertTrue(os.path.exists(num_fp)) # test to make sure that the denominator file is there denom_fp = os.path.join(self.results, 'denominator.csv') self.assertTrue(os.path.exists(denom_fp)) with open(index_fp, 'r') as fh: html = fh.read() self.assertIn('<h1>Balance Taxonomy</h1>', html) self.assertIn('Numerator taxa', html) self.assertIn('Denominator taxa', html) # extract csv files and test for contents exp = pd.DataFrame( [['foo', 'barf', 'a', 'b', 'c', 'd', 'e'], ['foo', 'bark', 'f', 'g', 'h', 'i', 'j'], ['foo', 'bark', 'f', 'g', 'h', 'w', 'j']], columns=['0', '1', '2', '3', '4', '5', '6'], index=['x', 'y', 'z']) res = pd.read_csv(num_fp, index_col=0) pdt.assert_frame_equal(exp, res.sort_index()) exp = pd.DataFrame([['nom', 'tu', 'k', 'l', 'm', 't', 'o'], ['nom', 'tu', 'k', 'l', 'm', 'n', 'o']], columns=['0', '1', '2', '3', '4', '5', '6'], index=['q', 'k']).sort_index() res = pd.read_csv(denom_fp, index_col=0) pdt.assert_frame_equal(exp, res.sort_index())
def test_balance_taxonomy_categorical(self): balance_taxonomy(self.results, self.balances, self.tree, self.taxonomy, balance_name='a', metadata=self.categorical)
def test_balance_taxonomy_continuous(self): balance_taxonomy(self.results, self.balances, self.tree, self.taxonomy, balance_name='a', metadata=self.continuous)
def test_balance_taxonomy_tips(self): index_fp = os.path.join(self.results, 'index.html') balance_taxonomy(self.results, self.balances, self.tree, self.taxonomy, balance_name='a') self.assertTrue(os.path.exists(index_fp)) # test to make sure that the numerator file is there num_fp = os.path.join(self.results, 'numerator.csv') self.assertTrue(os.path.exists(num_fp)) # test to make sure that the denominator file is there denom_fp = os.path.join(self.results, 'denominator.csv') self.assertTrue(os.path.exists(denom_fp)) exp = pd.DataFrame(['foo', 'bark', 'f', 'g', 'h', 'i', 'j'], index=['0', '1', '2', '3', '4', '5', '6'], columns=['y']).T res = pd.read_csv(num_fp, index_col=0) pdt.assert_frame_equal(exp, res) res = pd.read_csv(denom_fp, index_col=0) exp = pd.DataFrame(['foo', 'barf', 'a', 'b', 'c', 'd', 'e'], index=['0', '1', '2', '3', '4', '5', '6'], columns=['x']).T pdt.assert_frame_equal(exp, res)
def test_balance_taxonomy_continuous(self): index_fp = os.path.join(self.results, 'index.html') balance_taxonomy(self.results, self.table, self.tree, self.taxonomy, balance_name='a', metadata=self.continuous) self.assertTrue(os.path.exists(index_fp)) # test to make sure that the numerator file is there num_fp = os.path.join(self.results, 'numerator.csv') self.assertTrue(os.path.exists(num_fp)) # test to make sure that the denominator file is there denom_fp = os.path.join(self.results, 'denominator.csv') self.assertTrue(os.path.exists(denom_fp)) box_fp = os.path.join(self.results, 'balance_metadata.pdf') self.assertTrue(os.path.exists(box_fp)) prop_fp = os.path.join(self.results, 'proportion_plot.pdf') self.assertTrue(os.path.exists(prop_fp)) box_fp = os.path.join(self.results, 'balance_metadata.pdf') self.assertTrue(os.path.exists(box_fp)) with open(index_fp, 'r') as fh: html = fh.read() self.assertIn('<h1>Balance Taxonomy</h1>', html) self.assertIn('Numerator taxa', html) self.assertIn('Denominator taxa', html) self.assertIn('Proportion', html)
def test_balance_taxonomy_full_numerical_categorical(self): with self.assertRaisesRegex(ValueError, 'only numerical values'): balance_taxonomy(self.results, self.table, self.tree, self.taxonomy, balance_name='a', metadata=self.full_numerical_categorical)
def test_balance_taxonomy_categorical_error(self): with self.assertRaises(ValueError): balance_taxonomy(self.results, self.table, self.tree, self.taxonomy, balance_name='a', metadata=self.categorical, threshold=100.)
def test_balance_taxonomy_genus(self): index_fp = os.path.join(self.results, 'index.html') balance_taxonomy(self.results, self.balances, self.tree, self.taxonomy, balance_name='c', taxa_level=6) self.assertTrue(os.path.exists(index_fp)) # test to make sure that the numerator file is there num_fp = os.path.join(self.results, 'numerator.csv') self.assertTrue(os.path.exists(num_fp)) # test to make sure that the denominator file is there denom_fp = os.path.join(self.results, 'denominator.csv') self.assertTrue(os.path.exists(denom_fp))
def test_balance_taxonomy_partial_numerical_categorical(self): index_fp = os.path.join(self.results, 'index.html') balance_taxonomy(self.results, self.table, self.tree, self.taxonomy, balance_name='a', metadata=self.partial_numerical_categorical) for file in [ 'numerator.csv', 'denominator.csv', 'balance_metadata.pdf' ]: self.assertTrue(os.path.exists(os.path.join(self.results, file))) self.assertFalse( os.path.exists(os.path.join(self.results, 'proportion_plot.pdf'))) with open(index_fp, 'r') as fh: html = fh.read() for exp in [ '<h1>Balance Taxonomy</h1>', 'Numerator taxa', 'Denominator taxa' ]: self.assertIn(exp, html) self.assertNotIn('Proportion', html)