def single_object_alpha(biom_object, metrics, tree_object): """given a metric calculates alpha diversity of a biom object Inputs: biom_object: biom formatted OTU table metrics: list of alpha diversity metrics tree_object: tree object for the phylogenetic metrics Output: calculations: tab delimitted string with the calculations for the object """ calcs = [] for metric in metrics: try: metric_f = get_nonphylogenetic_metric(metric) is_phylogenetic = False except AttributeError: try: metric_f = get_phylogenetic_metric(metric) is_phylogenetic = True except AttributeError: print 'something is wrong with conf file' c = AlphaDiversityCalc(metric_f, is_phylogenetic) calcs.append(c) all_calcs = AlphaDiversityCalcs(calcs) result = all_calcs(data_path=biom_object, tree_path=tree_object, log_path=None) return all_calcs.formatResult(result)
def single_file_cup(otu_filepath, metrics, outfilepath, r, alpha, f, ci_type): """Compute variations of the conditional uncovered probability. otufilepath: path to otu_table file metrics: comma separated list of required metrics outfilepath: path to output file r: Number of new colors that are required for the next prediction alpha: desired confidence level f: ratio between upper and lower bound ci_type: type of confidence interval. One of: ULCL: upper and lower bounds with conservative lower bound ULCU: upper and lower woth conservative upper bound U: Upper bound only, lower bound fixed to 0 L: Lower bound only, upper bound fixed to 1 The opposite of uncovered probability is sometimes called coverage. """ metrics_list = metrics.split(',') calcs = [] params = {'r': r, 'alpha': alpha, 'f':f, 'ci_type':ci_type} for metric in metrics_list: try: metric_f = get_cup_metric(metric) except AttributeError: stderr.write( "Could not find metric %s.\n Known metrics are: %s\n" \ % (metric, ', '.join(list_known_metrics()))) exit(1) c = AlphaDiversityCalc(metric_f, params=params) calcs.append(c) all_calcs = AlphaDiversityCalcs(calcs) try: result = all_calcs(data_path=otu_filepath, result_path=outfilepath, log_path=None) if result: #can send to stdout instead of file print all_calcs.formatResult(result) except IOError, e: stderr.write("Failed because of missing files.\n") stderr.write(str(e)+'\n') exit(1)
def test1(self): """ checks that output from AlphaDiversityCalcs is the right shape when run on phylo, multiple return value nonphylo, and another nonphylo """ calc1 = AlphaDiversityCalc(metric=observed_otus) calc2 = AlphaDiversityCalc(metric=PD_whole_tree, is_phylogenetic=True) calc3 = AlphaDiversityCalc(metric=osd) calcs = AlphaDiversityCalcs([calc1, calc2, calc3]) results = calcs(data_path=self.otu_table1_fp, tree_path=self.tree1, result_path=None, log_path=None) self.assertEqual(results[0].shape, (3, 5)) self.assertEqual(len(results[1]), 3) self.assertEqual(len(results[2]), 5)