def test_l19_chi(self): """beta calc run should return same values as directly calling metric""" beta_calc_chisq = BetaDiversityCalc(dist_chisq, 'chi square', False) matrix, labels = beta_calc_chisq(data_path=self.l19_str, tree_path=None) self.assertEqual(labels, self.l19_sample_names) self.assertFloatEqual(matrix, dist_chisq(self.l19_data))
def test_l19_unifrac(self): """beta calc run should also work for phylo metric""" beta_calc = BetaDiversityCalc(dist_unweighted_unifrac, 'unifrac', True) matrix, labels = beta_calc(data_path=self.l19_fp, tree_path=self.l19_tree, result_path=None, log_path=None) self.assertEqual(labels, self.l19_sample_names)
def test_l19_unifrac_escaped_names(self): """beta calc works for unifrac when tips names are escaped in newick """ beta_calc = BetaDiversityCalc(dist_unweighted_unifrac, 'unifrac', True) non_escaped_result = beta_calc(data_path=self.l19_fp, tree_path=self.l19_tree, result_path=None, log_path=None) l19_tree_str = "(((('tax7':0.1,'tax3':0.2):.98,tax8:.3, 'tax4':.3):.4,\ (('ta_x1':0.3, tax6:.09):0.43,tax2:0.4):0.5):.2, (tax9:0.3, 'endbigtaxon':.08));" tree_fp = get_tmp_filename(prefix='Beta_div_tests', suffix='.tre') open(tree_fp, 'w').write(l19_tree_str) self.files_to_remove.append(tree_fp) escaped_result = beta_calc(data_path=self.l19_str_w_underscore_fp, tree_path=tree_fp, result_path=None, log_path=None) self.assertEqual(escaped_result, non_escaped_result)