Skip to content
This repository was archived by the owner on Nov 9, 2023. It is now read-only.

Commit 43270ab

Browse files
author
Greg Caporaso
committed
Merge pull request #1853 from jairideout/issue-1849
BUG: replace Table.from_hdf5 with biom.load_table
2 parents f1802b7 + ad86dc3 commit 43270ab

File tree

4 files changed

+34
-67
lines changed

4 files changed

+34
-67
lines changed

qiime/workflow/pick_open_reference_otus.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
from copy import deepcopy
1717
from skbio.util import create_dir, remove_files
1818
from skbio.parse.sequences import parse_fasta
19-
from biom import Table
20-
from biom.util import biom_open
19+
from biom import load_table
2120

2221
from qiime.util import (subsample_fasta, count_seqs_from_file)
2322
from qiime.filter import (filter_otus_from_otu_table,
@@ -538,8 +537,7 @@ def iterative_pick_subsampled_open_reference_otus(
538537
status_update_callback=status_update_callback)
539538

540539
# Build OTU table without PyNAST failures
541-
with biom_open(align_and_tree_input_otu_table) as biom_file:
542-
table = Table.from_hdf5(biom_file)
540+
table = load_table(align_and_tree_input_otu_table)
543541
filtered_otu_table = filter_otus_from_otu_table(table,
544542
get_seq_ids_from_fasta_file(open(pynast_failures_fp, 'U')),
545543
0, inf, 0, inf, negate_ids_to_keep=True)
@@ -1073,8 +1071,7 @@ def pick_subsampled_open_reference_otus(input_fp,
10731071
status_update_callback=status_update_callback)
10741072

10751073
# Build OTU table without PyNAST failures
1076-
with biom_open(align_and_tree_input_otu_table) as biom_file:
1077-
table = Table.from_hdf5(biom_file)
1074+
table = load_table(align_and_tree_input_otu_table)
10781075
filtered_otu_table = filter_otus_from_otu_table(table,
10791076
get_seq_ids_from_fasta_file(open(pynast_failures_fp, 'U')),
10801077
0, inf, 0, inf, negate_ids_to_keep=True)

tests/test_rarefaction.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@
1919

2020
import numpy.testing as npt
2121
import numpy as np
22+
from biom import load_table
2223
from biom.table import Table, TableException
23-
from biom.parse import parse_biom_table
24-
from biom.util import biom_open
2524

2625
from qiime.rarefaction import RarefactionMaker, get_rare_data
2726
from qiime.util import load_qiime_config, write_biom_table
@@ -108,8 +107,7 @@ def test_rarefy_to_files(self):
108107
include_lineages=False)
109108

110109
fname = os.path.join(self.rare_dir, "rarefaction_1_0.biom")
111-
with biom_open(fname, 'U') as biom_file:
112-
otu_table = Table.from_hdf5(biom_file)
110+
otu_table = load_table(fname)
113111

114112
self.assertItemsEqual(
115113
otu_table.ids(),
@@ -127,8 +125,7 @@ def test_rarefy_to_files2(self):
127125
include_lineages=False)
128126

129127
fname = os.path.join(self.rare_dir, "rarefaction_1_0.biom")
130-
with biom_open(fname, 'U') as biom_file:
131-
otu_table = Table.from_hdf5(biom_file)
128+
otu_table = load_table(fname)
132129

133130
self.assertItemsEqual(
134131
otu_table.ids(),

tests/test_simsam.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
from itertools import izip
1818
from cogent.parse.tree import DndParser
1919

20+
from biom import load_table
2021
from biom.parse import parse_biom_table
2122
from biom.table import Table
22-
from biom.util import biom_open
2323
from qiime.parse import parse_mapping_file
2424
from qiime.util import load_qiime_config, get_qiime_temp_dir
2525
import qiime.simsam
@@ -114,8 +114,7 @@ def test_script(self):
114114

115115
result_fp = os.path.join(out_dir, 'otuf_n%d_d0.003.biom' %
116116
num_replicates)
117-
with biom_open(result_fp) as biom_file:
118-
res_table = Table.from_hdf5(biom_file)
117+
res_table = load_table(result_fp)
119118

120119
orig_table = parse_biom_table(open(otuf, 'U'))
121120

@@ -182,8 +181,7 @@ def test_script_nochange(self):
182181
num_replicates = 3 # ensure this matches cmd above
183182
result_fp = os.path.join(out_dir, 'otuf_n%d_d0.0.biom' %
184183
num_replicates)
185-
with biom_open(result_fp) as biom_file:
186-
res_table = Table.from_hdf5(biom_file)
184+
res_table = load_table(result_fp)
187185

188186
orig_table = parse_biom_table(open(otuf, 'U'))
189187

@@ -417,8 +415,7 @@ def test_simsam_range_to_files(self):
417415
self.assertTrue(exists('%s/world_n2_d0.1.txt' % self.test_out))
418416

419417
# confirm same sample ids in table and mapping file
420-
with biom_open('%s/hello_n2_d0.1.biom' % self.test_out) as biom_file:
421-
t = Table.from_hdf5(biom_file)
418+
t = load_table('%s/hello_n2_d0.1.biom' % self.test_out)
422419
d, _, _ = \
423420
parse_mapping_file(open('%s/world_n2_d0.1.txt' % self.test_out))
424421
mapping_sample_ids = [e[0] for e in d]

tests/test_workflow/test_pick_open_reference_otus.py

Lines changed: 24 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919

2020
from skbio.tree import TreeNode
2121
from skbio.util import remove_files
22-
from biom import Table
23-
from biom.util import biom_open
22+
from biom import load_table
2423

2524
from qiime.util import load_qiime_config, count_seqs, get_qiime_temp_dir
2625
from qiime.workflow.util import (call_commands_serially, no_status_updates,
@@ -139,8 +138,7 @@ def test_pick_subsampled_open_reference_otus_step_1_and_4(self):
139138
"PyNAST failures file doesn't exist")
140139

141140
# all OTUs in final OTU table occur more than once
142-
with biom_open(otu_table_fp) as biom_file:
143-
otu_table = Table.from_hdf5(biom_file)
141+
otu_table = load_table(otu_table_fp)
144142
for row in otu_table.iter_data(axis='observation'):
145143
self.assertTrue(sum(row) >= 2,
146144
"Singleton OTU detected in OTU table.")
@@ -191,8 +189,7 @@ def test_pick_subsampled_open_reference_otus_step_1_and_4(self):
191189

192190
# OTU table without singletons or pynast failures has same number of
193191
# otus as there are aligned sequences
194-
with biom_open(otu_table_fp) as biom_file:
195-
otu_table = Table.from_hdf5(biom_file)
192+
otu_table = load_table(otu_table_fp)
196193
self.assertEqual(len(otu_table.ids(axis='observation')),
197194
num_align_seqs)
198195

@@ -265,8 +262,7 @@ def test_pick_subsampled_open_reference_otus_step_1_through_4(self):
265262
"PyNAST failures file doesn't exist")
266263

267264
# all OTUs in final OTU table occur more than once
268-
with biom_open(otu_table_fp) as biom_file:
269-
otu_table = Table.from_hdf5(biom_file)
265+
otu_table = load_table(otu_table_fp)
270266
for row in otu_table.iter_data(axis='observation'):
271267
self.assertTrue(sum(row) >= 2,
272268
"Singleton OTU detected in OTU table.")
@@ -317,8 +313,7 @@ def test_pick_subsampled_open_reference_otus_step_1_through_4(self):
317313

318314
# OTU table without singletons or pynast failures has same number of
319315
# otus as there are aligned sequences
320-
with biom_open(otu_table_fp) as biom_file:
321-
otu_table = Table.from_hdf5(biom_file)
316+
otu_table = load_table(otu_table_fp)
322317
self.assertEqual(len(otu_table.ids(axis='observation')),
323318
num_align_seqs)
324319

@@ -403,8 +398,7 @@ def test_pick_subsampled_open_reference_otus_rdp_tax_assign(self):
403398
"rdp taxonomy assignment result doesn't exist")
404399

405400
# all OTUs in final OTU table occur more than once
406-
with biom_open(otu_table_fp) as biom_file:
407-
otu_table = Table.from_hdf5(biom_file)
401+
otu_table = load_table(otu_table_fp)
408402
for row in otu_table.iter_data(axis='observation'):
409403
self.assertTrue(sum(row) >= 2,
410404
"Singleton OTU detected in OTU table.")
@@ -455,8 +449,7 @@ def test_pick_subsampled_open_reference_otus_rdp_tax_assign(self):
455449

456450
# OTU table without singletons or pynast failures has same number of
457451
# otus as there are aligned sequences
458-
with biom_open(otu_table_fp) as biom_file:
459-
otu_table = Table.from_hdf5(biom_file)
452+
otu_table = load_table(otu_table_fp)
460453
self.assertEqual(len(otu_table.ids(axis='observation')),
461454
num_align_seqs)
462455

@@ -531,8 +524,7 @@ def test_pick_subsampled_open_reference_otus_usearch(self):
531524
"PyNAST failures file doesn't exist")
532525

533526
# all OTUs in final OTU table occur more than once
534-
with biom_open(otu_table_fp) as biom_file:
535-
otu_table = Table.from_hdf5(biom_file)
527+
otu_table = load_table(otu_table_fp)
536528
for row in otu_table.iter_data(axis='observation'):
537529
self.assertTrue(sum(row) >= 2,
538530
"Singleton OTU detected in OTU table.")
@@ -582,8 +574,7 @@ def test_pick_subsampled_open_reference_otus_usearch(self):
582574

583575
# OTU table without singletons or pynast failures has same number of
584576
# otus as there are aligned sequences
585-
with biom_open(otu_table_fp) as biom_file:
586-
otu_table = Table.from_hdf5(biom_file)
577+
otu_table = load_table(otu_table_fp)
587578
self.assertEqual(len(otu_table.ids(axis='observation')),
588579
num_align_seqs)
589580

@@ -664,8 +655,7 @@ def test_pick_subsampled_open_reference_otus_sortmerna_sumaclust(self):
664655
"PyNAST failures file doesn't exist")
665656

666657
# all OTUs in final OTU table occur more than once
667-
with biom_open(otu_table_fp) as biom_file:
668-
otu_table = Table.from_hdf5(biom_file)
658+
otu_table = load_table(otu_table_fp)
669659
for row in otu_table.iter_data(axis='observation'):
670660
self.assertTrue(sum(row) >= 2,
671661
"Singleton OTU detected in OTU table.")
@@ -734,8 +724,7 @@ def test_pick_subsampled_open_reference_otus_sortmerna_sumaclust(self):
734724

735725
# OTU table without singletons or pynast failures has same number of
736726
# otus as there are aligned sequences
737-
with biom_open(otu_table_fp) as biom_file:
738-
otu_table = Table.from_hdf5(biom_file)
727+
otu_table = load_table(otu_table_fp)
739728
self.assertEqual(len(otu_table.ids(axis='observation')),
740729
num_align_seqs)
741730

@@ -816,8 +805,7 @@ def test_pick_subsampled_open_reference_otus_sortmerna_sumaclust_step2_3(self):
816805
"PyNAST failures file doesn't exist")
817806

818807
# all OTUs in final OTU table occur more than once
819-
with biom_open(otu_table_fp) as biom_file:
820-
otu_table = Table.from_hdf5(biom_file)
808+
otu_table = load_table(otu_table_fp)
821809
for row in otu_table.iter_data(axis='observation'):
822810
self.assertTrue(sum(row) >= 2,
823811
"Singleton OTU detected in OTU table.")
@@ -883,8 +871,7 @@ def test_pick_subsampled_open_reference_otus_sortmerna_sumaclust_step2_3(self):
883871

884872
# OTU table without singletons or pynast failures has same number of
885873
# otus as there are aligned sequences
886-
with biom_open(otu_table_fp) as biom_file:
887-
otu_table = Table.from_hdf5(biom_file)
874+
otu_table = load_table(otu_table_fp)
888875
self.assertEqual(len(otu_table.ids(axis='observation')),
889876
num_align_seqs)
890877

@@ -973,8 +960,7 @@ def test_pick_subsampled_open_reference_otus_sortmerna_sumaclust_db(self):
973960
"PyNAST failures file doesn't exist")
974961

975962
# all OTUs in final OTU table occur more than once
976-
with biom_open(otu_table_fp) as biom_file:
977-
otu_table = Table.from_hdf5(biom_file)
963+
otu_table = load_table(otu_table_fp)
978964
for row in otu_table.iter_data(axis='observation'):
979965
self.assertTrue(sum(row) >= 2,
980966
"Singleton OTU detected in OTU table.")
@@ -1037,8 +1023,7 @@ def test_pick_subsampled_open_reference_otus_sortmerna_sumaclust_db(self):
10371023

10381024
# OTU table without singletons or pynast failures has same number of
10391025
# otus as there are aligned sequences
1040-
with biom_open(otu_table_fp) as biom_file:
1041-
otu_table = Table.from_hdf5(biom_file)
1026+
otu_table = load_table(otu_table_fp)
10421027
self.assertEqual(len(otu_table.ids(axis='observation')),
10431028
num_align_seqs)
10441029

@@ -1172,8 +1157,7 @@ def test_pick_subsampled_open_reference_otus_no_prefilter(self):
11721157
"PyNAST failures file doesn't exist")
11731158

11741159
# all OTUs in final OTU table occur more than once
1175-
with biom_open(otu_table_fp) as biom_file:
1176-
otu_table = Table.from_hdf5(biom_file)
1160+
otu_table = load_table(otu_table_fp)
11771161
for row in otu_table.iter_data(axis='observation'):
11781162
self.assertTrue(sum(row) >= 2,
11791163
"Singleton OTU detected in OTU table.")
@@ -1225,8 +1209,7 @@ def test_pick_subsampled_open_reference_otus_no_prefilter(self):
12251209

12261210
# OTU table without singletons or pynast failures has same number of
12271211
# otus as there are aligned sequences
1228-
with biom_open(otu_table_fp) as biom_file:
1229-
otu_table = Table.from_hdf5(biom_file)
1212+
otu_table = load_table(otu_table_fp)
12301213
self.assertEqual(len(otu_table.ids(axis='observation')),
12311214
num_align_seqs)
12321215

@@ -1300,8 +1283,7 @@ def test_pick_subsampled_open_reference_otus_parallel(self):
13001283
"PyNAST failures file doesn't exist")
13011284

13021285
# all OTUs in final OTU table occur more than once
1303-
with biom_open(otu_table_fp) as biom_file:
1304-
otu_table = Table.from_hdf5(biom_file)
1286+
otu_table = load_table(otu_table_fp)
13051287
for row in otu_table.iter_data(axis='observation'):
13061288
self.assertTrue(sum(row) >= 2,
13071289
"Singleton OTU detected in OTU table.")
@@ -1352,8 +1334,7 @@ def test_pick_subsampled_open_reference_otus_parallel(self):
13521334

13531335
# OTU table without singletons or pynast failures has same number of
13541336
# otus as there are aligned sequences
1355-
with biom_open(otu_table_fp) as biom_file:
1356-
otu_table = Table.from_hdf5(biom_file)
1337+
otu_table = load_table(otu_table_fp)
13571338
self.assertEqual(len(otu_table.ids(axis='observation')),
13581339
num_align_seqs)
13591340

@@ -1432,8 +1413,7 @@ def test_pick_subsampled_open_reference_otus_suppress_step4(self):
14321413
"PyNAST failures file doesn't exist")
14331414

14341415
# all OTUs in final OTU table occur more than once
1435-
with biom_open(otu_table_fp) as biom_file:
1436-
otu_table = Table.from_hdf5(biom_file)
1416+
otu_table = load_table(otu_table_fp)
14371417
for row in otu_table.iter_data(axis='observation'):
14381418
self.assertTrue(sum(row) >= 2,
14391419
"Singleton OTU detected in OTU table.")
@@ -1488,8 +1468,7 @@ def test_pick_subsampled_open_reference_otus_suppress_step4(self):
14881468

14891469
# OTU table without singletons or pynast failures has same number of
14901470
# otus as there are aligned sequences
1491-
with biom_open(otu_table_fp) as biom_file:
1492-
otu_table = Table.from_hdf5(biom_file)
1471+
otu_table = load_table(otu_table_fp)
14931472
self.assertEqual(len(otu_table.ids(axis='observation')),
14941473
num_align_seqs)
14951474

@@ -1592,8 +1571,7 @@ def test_iterative_pick_subsampled_open_reference_otus_no_prefilter(self):
15921571
"Iteration 1 OTU map with singletons doesn't exist")
15931572

15941573
# all OTUs in final OTU table occur more than once
1595-
with biom_open(otu_table_fp) as biom_file:
1596-
otu_table = Table.from_hdf5(biom_file)
1574+
otu_table = load_table(otu_table_fp)
15971575
for row in otu_table.iter_data(axis='observation'):
15981576
self.assertTrue(sum(row) >= 2,
15991577
"Singleton OTU detected in OTU table.")
@@ -1734,8 +1712,7 @@ def test_iterative_pick_subsampled_open_reference_otus(self):
17341712
"Iteration 1 OTU map with singletons doesn't exist")
17351713

17361714
# all OTUs in final OTU table occur more than once
1737-
with biom_open(otu_table_fp) as biom_file:
1738-
otu_table = Table.from_hdf5(biom_file)
1715+
otu_table = load_table(otu_table_fp)
17391716
for row in otu_table.iter_data(axis='observation'):
17401717
self.assertTrue(sum(row) >= 2,
17411718
"Singleton OTU detected in OTU table.")
@@ -1876,8 +1853,7 @@ def test_iterative_pick_subsampled_open_reference_otus_parallel(self):
18761853
"Iteration 1 OTU map with singletons doesn't exist")
18771854

18781855
# all OTUs in final OTU table occur more than once
1879-
with biom_open(otu_table_fp) as biom_file:
1880-
otu_table = Table.from_hdf5(biom_file)
1856+
otu_table = load_table(otu_table_fp)
18811857
for row in otu_table.iter_data(axis='observation'):
18821858
self.assertTrue(sum(row) >= 2,
18831859
"Singleton OTU detected in OTU table.")

0 commit comments

Comments
 (0)