163
163
self.assertEqual(res[0,0], 0)
164
164
self.assertEqual(res[0,3], 0.0)
165
165
self.assertEqual(res[0,1], 1.0)
167
def test_make_unifrac_row_metric3(self):
168
treestr = '((((tax7:0.1):.98,tax8:.3, tax4:.3):.4, '+\
169
'((tax6:.09):0.43):0.5):.2,'+\
170
'(tax9:0.3, endbigtaxon:.08));' # taxa 1,2,3 removed
171
tree = parse_newick(treestr, PhyloNode)
173
otu_data = numpy.array([
174
[7,1,0,0,0,0,0,0,0], # 1 now zeros
177
[1,7,0,0,0,0,0,0,0], # 4 now zeros
195
unif = make_unifrac_metric(False, unifrac, True)
196
warnings.filterwarnings('ignore')
197
res = unif(otu_data, self.l19_taxon_names, tree,
198
self.l19_sample_names)
199
warnings.resetwarnings()
200
envs = make_envs_dict(self.l19_data, self.l19_sample_names,
201
self.l19_taxon_names)
202
self.assertEqual(res[0,0], 0)
203
self.assertEqual(res[0,3], 0.0)
204
self.assertEqual(res[0,1], 1.0)
206
warnings.filterwarnings('ignore')
207
unif_row = make_unifrac_row_metric(False, unifrac, True)
208
for i, sam_name in enumerate(self.l19_sample_names):
209
if i in [0,3,4,5,8,9]: continue
210
# these have no data and are warned "meaningless".
211
# I Would prefer if they matched res anyway though
212
res_row = unif_row(otu_data, self.l19_taxon_names, tree,
213
self.l19_sample_names, sam_name)
214
for j in range(len(self.l19_sample_names)):
215
if j in [0,3,4,5,8,9]: continue # ok if meaningless number in zero sample
216
self.assertEqual(res_row[j], res[i,j])
217
warnings.resetwarnings()
220
def test_make_unifrac_row_metric2(self):
221
""" samples with no seqs, and identical samples, should behave correctly
223
tree = parse_newick(self.l19_treestr, PhyloNode)
224
unif = make_unifrac_metric(False, unifrac, True)
225
otu_data = numpy.array([
226
[0,0,0,0,0,0,0,0,0],#sam1 zeros
239
[0,0,0,0,0,0,0,0,0],#sam14 zeros
241
[0,0,2,4,0,0,0,1,0], #sam 16 now like sam 13
246
warnings.filterwarnings('ignore')
247
res = unif(otu_data, self.l19_taxon_names, tree,
248
self.l19_sample_names)
249
envs = make_envs_dict(self.l19_data, self.l19_sample_names,
250
self.l19_taxon_names)
251
self.assertEqual(res[0,0], 0)
252
self.assertEqual(res[0,13], 0.0)
253
self.assertEqual(res[12,15], 0.0)
254
self.assertEqual(res[0,1], 1.0)
255
warnings.resetwarnings()
257
warnings.filterwarnings('ignore')
258
unif_row = make_unifrac_row_metric(False, unifrac, True)
259
for i, sam_name in enumerate(self.l19_sample_names):
260
if i in [0]: continue
261
# these have no data and are warned "meaningless".
262
# I Would prefer if they matched res anyway though
263
res_row = unif_row(otu_data, self.l19_taxon_names, tree,
264
self.l19_sample_names, sam_name)
265
for j in range(len((self.l19_sample_names))):
266
if j in [0]: continue # ok if meaningless number in zero sample
267
self.assertEqual(res_row[j], res[i,j])
268
warnings.resetwarnings()
168
270
#run tests if called from command line
169
271
if __name__ == '__main__':