def setUp(self): self.qiime_config = load_qiime_config() self.tmp_dir = self.qiime_config['temp_dir'] or '/tmp/' self.l19_data = numpy.array([[7, 1, 0, 0, 0, 0, 0, 0, 0], [4, 2, 0, 0, 0, 1, 0, 0, 0], [2, 4, 0, 0, 0, 1, 0, 0, 0], [1, 7, 0, 0, 0, 0, 0, 0, 0], [0, 8, 0, 0, 0, 0, 0, 0, 0], [0, 7, 1, 0, 0, 0, 0, 0, 0], [0, 4, 2, 0, 0, 0, 2, 0, 0], [0, 2, 4, 0, 0, 0, 1, 0, 0], [0, 1, 7, 0, 0, 0, 0, 0, 0], [0, 0, 8, 0, 0, 0, 0, 0, 0], [0, 0, 7, 1, 0, 0, 0, 0, 0], [0, 0, 4, 2, 0, 0, 0, 3, 0], [0, 0, 2, 4, 0, 0, 0, 1, 0], [0, 0, 1, 7, 0, 0, 0, 0, 0], [0, 0, 0, 8, 0, 0, 0, 0, 0], [0, 0, 0, 7, 1, 0, 0, 0, 0], [0, 0, 0, 4, 2, 0, 0, 0, 4], [0, 0, 0, 2, 4, 0, 0, 0, 1], [0, 0, 0, 1, 7, 0, 0, 0, 0]]) self.l19_sample_names = ['sam1', 'sam2', 'sam3', 'sam4', 'sam5','sam6',\ 'sam7', 'sam8', 'sam9', 'sam_middle', 'sam11', 'sam12', 'sam13', \ 'sam14', 'sam15', 'sam16', 'sam17', 'sam18', 'sam19'] self.l19_taxon_names = ['tax1', 'tax2', 'tax3', 'tax4', 'endbigtaxon',\ 'tax6', 'tax7', 'tax8', 'tax9'] self.l19_taxon_names_w_underscore = [ 'ta_x1', 'tax2', 'tax3', 'tax4', 'endbigtaxon', 'tax6', 'tax7', 'tax8', 'tax9' ] l19_str = format_biom_table( DenseOTUTable(self.l19_data.T, self.l19_sample_names, self.l19_taxon_names)) self.l19_fp = get_tmp_filename(tmp_dir=self.tmp_dir, prefix='test_bdiv_otu_table', suffix='.blom') open(self.l19_fp, 'w').write(l19_str) l19_str_w_underscore = format_biom_table( DenseOTUTable(self.l19_data.T, self.l19_sample_names, self.l19_taxon_names_w_underscore)) self.l19_str_w_underscore_fp = get_tmp_filename( tmp_dir=self.tmp_dir, prefix='test_bdiv_otu_table', suffix='.blom') open(self.l19_str_w_underscore_fp, 'w').write(l19_str_w_underscore) self.l19_tree_str = '((((tax7:0.1,tax3:0.2):.98,tax8:.3, tax4:.3):.4,\ ((tax1:0.3, tax6:.09):0.43,tax2:0.4):0.5):.2, (tax9:0.3, endbigtaxon:.08));' self.l19_tree = parse_newick(self.l19_tree_str, PhyloNode) self.files_to_remove = [self.l19_fp, self.l19_str_w_underscore_fp] self.folders_to_remove = []
def format_otu_table(sample_names, otu_names, data, taxonomy=None, comment=None, skip_empty=False,legacy=True): """Returns string representing OTU table as biom file """ print "Deprecation Warning: you should not be using format_otu_table. Instead use qiime.format.format_biom_table" if taxonomy != None: def strip_f(s): return s.strip() taxonomy = [{'taxonomy':map(strip_f,t.split(';'))} for t in taxonomy] otu_table = DenseOTUTable(Data=data, SampleIds=sample_names, ObservationIds=otu_names, ObservationMetadata=taxonomy) return format_biom_table(otu_table)