diff --git a/qiime/workflow/pick_open_reference_otus.py b/qiime/workflow/pick_open_reference_otus.py index d119081a1c..ed65342694 100644 --- a/qiime/workflow/pick_open_reference_otus.py +++ b/qiime/workflow/pick_open_reference_otus.py @@ -16,8 +16,7 @@ from copy import deepcopy from skbio.util import create_dir, remove_files from skbio.parse.sequences import parse_fasta -from biom import Table -from biom.util import biom_open +from biom import load_table from qiime.util import (subsample_fasta, count_seqs_from_file) from qiime.filter import (filter_otus_from_otu_table, @@ -538,8 +537,7 @@ def iterative_pick_subsampled_open_reference_otus( status_update_callback=status_update_callback) # Build OTU table without PyNAST failures - with biom_open(align_and_tree_input_otu_table) as biom_file: - table = Table.from_hdf5(biom_file) + table = load_table(align_and_tree_input_otu_table) filtered_otu_table = filter_otus_from_otu_table(table, get_seq_ids_from_fasta_file(open(pynast_failures_fp, 'U')), 0, inf, 0, inf, negate_ids_to_keep=True) @@ -1073,8 +1071,7 @@ def pick_subsampled_open_reference_otus(input_fp, status_update_callback=status_update_callback) # Build OTU table without PyNAST failures - with biom_open(align_and_tree_input_otu_table) as biom_file: - table = Table.from_hdf5(biom_file) + table = load_table(align_and_tree_input_otu_table) filtered_otu_table = filter_otus_from_otu_table(table, get_seq_ids_from_fasta_file(open(pynast_failures_fp, 'U')), 0, inf, 0, inf, negate_ids_to_keep=True) diff --git a/tests/test_rarefaction.py b/tests/test_rarefaction.py index 3f55f50d7f..7d4d2bf8f8 100644 --- a/tests/test_rarefaction.py +++ b/tests/test_rarefaction.py @@ -19,9 +19,8 @@ import numpy.testing as npt import numpy as np +from biom import load_table from biom.table import Table, TableException -from biom.parse import parse_biom_table -from biom.util import biom_open from qiime.rarefaction import RarefactionMaker, get_rare_data from qiime.util import load_qiime_config, write_biom_table @@ -108,8 +107,7 @@ def test_rarefy_to_files(self): include_lineages=False) fname = os.path.join(self.rare_dir, "rarefaction_1_0.biom") - with biom_open(fname, 'U') as biom_file: - otu_table = Table.from_hdf5(biom_file) + otu_table = load_table(fname) self.assertItemsEqual( otu_table.ids(), @@ -127,8 +125,7 @@ def test_rarefy_to_files2(self): include_lineages=False) fname = os.path.join(self.rare_dir, "rarefaction_1_0.biom") - with biom_open(fname, 'U') as biom_file: - otu_table = Table.from_hdf5(biom_file) + otu_table = load_table(fname) self.assertItemsEqual( otu_table.ids(), diff --git a/tests/test_simsam.py b/tests/test_simsam.py index 79b83d89be..961c80f689 100755 --- a/tests/test_simsam.py +++ b/tests/test_simsam.py @@ -17,9 +17,9 @@ from itertools import izip from cogent.parse.tree import DndParser +from biom import load_table from biom.parse import parse_biom_table from biom.table import Table -from biom.util import biom_open from qiime.parse import parse_mapping_file from qiime.util import load_qiime_config, get_qiime_temp_dir import qiime.simsam @@ -114,8 +114,7 @@ def test_script(self): result_fp = os.path.join(out_dir, 'otuf_n%d_d0.003.biom' % num_replicates) - with biom_open(result_fp) as biom_file: - res_table = Table.from_hdf5(biom_file) + res_table = load_table(result_fp) orig_table = parse_biom_table(open(otuf, 'U')) @@ -182,8 +181,7 @@ def test_script_nochange(self): num_replicates = 3 # ensure this matches cmd above result_fp = os.path.join(out_dir, 'otuf_n%d_d0.0.biom' % num_replicates) - with biom_open(result_fp) as biom_file: - res_table = Table.from_hdf5(biom_file) + res_table = load_table(result_fp) orig_table = parse_biom_table(open(otuf, 'U')) @@ -417,8 +415,7 @@ def test_simsam_range_to_files(self): self.assertTrue(exists('%s/world_n2_d0.1.txt' % self.test_out)) # confirm same sample ids in table and mapping file - with biom_open('%s/hello_n2_d0.1.biom' % self.test_out) as biom_file: - t = Table.from_hdf5(biom_file) + t = load_table('%s/hello_n2_d0.1.biom' % self.test_out) d, _, _ = \ parse_mapping_file(open('%s/world_n2_d0.1.txt' % self.test_out)) mapping_sample_ids = [e[0] for e in d] diff --git a/tests/test_workflow/test_pick_open_reference_otus.py b/tests/test_workflow/test_pick_open_reference_otus.py index 51e0daf8ce..e8b7d66327 100755 --- a/tests/test_workflow/test_pick_open_reference_otus.py +++ b/tests/test_workflow/test_pick_open_reference_otus.py @@ -19,8 +19,7 @@ from skbio.tree import TreeNode from skbio.util import remove_files -from biom import Table -from biom.util import biom_open +from biom import load_table from qiime.util import load_qiime_config, count_seqs, get_qiime_temp_dir 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): "PyNAST failures file doesn't exist") # all OTUs in final OTU table occur more than once - with biom_open(otu_table_fp) as biom_file: - otu_table = Table.from_hdf5(biom_file) + otu_table = load_table(otu_table_fp) for row in otu_table.iter_data(axis='observation'): self.assertTrue(sum(row) >= 2, "Singleton OTU detected in OTU table.") @@ -191,8 +189,7 @@ def test_pick_subsampled_open_reference_otus_step_1_and_4(self): # OTU table without singletons or pynast failures has same number of # otus as there are aligned sequences - with biom_open(otu_table_fp) as biom_file: - otu_table = Table.from_hdf5(biom_file) + otu_table = load_table(otu_table_fp) self.assertEqual(len(otu_table.ids(axis='observation')), num_align_seqs) @@ -265,8 +262,7 @@ def test_pick_subsampled_open_reference_otus_step_1_through_4(self): "PyNAST failures file doesn't exist") # all OTUs in final OTU table occur more than once - with biom_open(otu_table_fp) as biom_file: - otu_table = Table.from_hdf5(biom_file) + otu_table = load_table(otu_table_fp) for row in otu_table.iter_data(axis='observation'): self.assertTrue(sum(row) >= 2, "Singleton OTU detected in OTU table.") @@ -317,8 +313,7 @@ def test_pick_subsampled_open_reference_otus_step_1_through_4(self): # OTU table without singletons or pynast failures has same number of # otus as there are aligned sequences - with biom_open(otu_table_fp) as biom_file: - otu_table = Table.from_hdf5(biom_file) + otu_table = load_table(otu_table_fp) self.assertEqual(len(otu_table.ids(axis='observation')), num_align_seqs) @@ -403,8 +398,7 @@ def test_pick_subsampled_open_reference_otus_rdp_tax_assign(self): "rdp taxonomy assignment result doesn't exist") # all OTUs in final OTU table occur more than once - with biom_open(otu_table_fp) as biom_file: - otu_table = Table.from_hdf5(biom_file) + otu_table = load_table(otu_table_fp) for row in otu_table.iter_data(axis='observation'): self.assertTrue(sum(row) >= 2, "Singleton OTU detected in OTU table.") @@ -455,8 +449,7 @@ def test_pick_subsampled_open_reference_otus_rdp_tax_assign(self): # OTU table without singletons or pynast failures has same number of # otus as there are aligned sequences - with biom_open(otu_table_fp) as biom_file: - otu_table = Table.from_hdf5(biom_file) + otu_table = load_table(otu_table_fp) self.assertEqual(len(otu_table.ids(axis='observation')), num_align_seqs) @@ -531,8 +524,7 @@ def test_pick_subsampled_open_reference_otus_usearch(self): "PyNAST failures file doesn't exist") # all OTUs in final OTU table occur more than once - with biom_open(otu_table_fp) as biom_file: - otu_table = Table.from_hdf5(biom_file) + otu_table = load_table(otu_table_fp) for row in otu_table.iter_data(axis='observation'): self.assertTrue(sum(row) >= 2, "Singleton OTU detected in OTU table.") @@ -582,8 +574,7 @@ def test_pick_subsampled_open_reference_otus_usearch(self): # OTU table without singletons or pynast failures has same number of # otus as there are aligned sequences - with biom_open(otu_table_fp) as biom_file: - otu_table = Table.from_hdf5(biom_file) + otu_table = load_table(otu_table_fp) self.assertEqual(len(otu_table.ids(axis='observation')), num_align_seqs) @@ -664,8 +655,7 @@ def test_pick_subsampled_open_reference_otus_sortmerna_sumaclust(self): "PyNAST failures file doesn't exist") # all OTUs in final OTU table occur more than once - with biom_open(otu_table_fp) as biom_file: - otu_table = Table.from_hdf5(biom_file) + otu_table = load_table(otu_table_fp) for row in otu_table.iter_data(axis='observation'): self.assertTrue(sum(row) >= 2, "Singleton OTU detected in OTU table.") @@ -734,8 +724,7 @@ def test_pick_subsampled_open_reference_otus_sortmerna_sumaclust(self): # OTU table without singletons or pynast failures has same number of # otus as there are aligned sequences - with biom_open(otu_table_fp) as biom_file: - otu_table = Table.from_hdf5(biom_file) + otu_table = load_table(otu_table_fp) self.assertEqual(len(otu_table.ids(axis='observation')), num_align_seqs) @@ -816,8 +805,7 @@ def test_pick_subsampled_open_reference_otus_sortmerna_sumaclust_step2_3(self): "PyNAST failures file doesn't exist") # all OTUs in final OTU table occur more than once - with biom_open(otu_table_fp) as biom_file: - otu_table = Table.from_hdf5(biom_file) + otu_table = load_table(otu_table_fp) for row in otu_table.iter_data(axis='observation'): self.assertTrue(sum(row) >= 2, "Singleton OTU detected in OTU table.") @@ -883,8 +871,7 @@ def test_pick_subsampled_open_reference_otus_sortmerna_sumaclust_step2_3(self): # OTU table without singletons or pynast failures has same number of # otus as there are aligned sequences - with biom_open(otu_table_fp) as biom_file: - otu_table = Table.from_hdf5(biom_file) + otu_table = load_table(otu_table_fp) self.assertEqual(len(otu_table.ids(axis='observation')), num_align_seqs) @@ -973,8 +960,7 @@ def test_pick_subsampled_open_reference_otus_sortmerna_sumaclust_db(self): "PyNAST failures file doesn't exist") # all OTUs in final OTU table occur more than once - with biom_open(otu_table_fp) as biom_file: - otu_table = Table.from_hdf5(biom_file) + otu_table = load_table(otu_table_fp) for row in otu_table.iter_data(axis='observation'): self.assertTrue(sum(row) >= 2, "Singleton OTU detected in OTU table.") @@ -1037,8 +1023,7 @@ def test_pick_subsampled_open_reference_otus_sortmerna_sumaclust_db(self): # OTU table without singletons or pynast failures has same number of # otus as there are aligned sequences - with biom_open(otu_table_fp) as biom_file: - otu_table = Table.from_hdf5(biom_file) + otu_table = load_table(otu_table_fp) self.assertEqual(len(otu_table.ids(axis='observation')), num_align_seqs) @@ -1172,8 +1157,7 @@ def test_pick_subsampled_open_reference_otus_no_prefilter(self): "PyNAST failures file doesn't exist") # all OTUs in final OTU table occur more than once - with biom_open(otu_table_fp) as biom_file: - otu_table = Table.from_hdf5(biom_file) + otu_table = load_table(otu_table_fp) for row in otu_table.iter_data(axis='observation'): self.assertTrue(sum(row) >= 2, "Singleton OTU detected in OTU table.") @@ -1225,8 +1209,7 @@ def test_pick_subsampled_open_reference_otus_no_prefilter(self): # OTU table without singletons or pynast failures has same number of # otus as there are aligned sequences - with biom_open(otu_table_fp) as biom_file: - otu_table = Table.from_hdf5(biom_file) + otu_table = load_table(otu_table_fp) self.assertEqual(len(otu_table.ids(axis='observation')), num_align_seqs) @@ -1300,8 +1283,7 @@ def test_pick_subsampled_open_reference_otus_parallel(self): "PyNAST failures file doesn't exist") # all OTUs in final OTU table occur more than once - with biom_open(otu_table_fp) as biom_file: - otu_table = Table.from_hdf5(biom_file) + otu_table = load_table(otu_table_fp) for row in otu_table.iter_data(axis='observation'): self.assertTrue(sum(row) >= 2, "Singleton OTU detected in OTU table.") @@ -1352,8 +1334,7 @@ def test_pick_subsampled_open_reference_otus_parallel(self): # OTU table without singletons or pynast failures has same number of # otus as there are aligned sequences - with biom_open(otu_table_fp) as biom_file: - otu_table = Table.from_hdf5(biom_file) + otu_table = load_table(otu_table_fp) self.assertEqual(len(otu_table.ids(axis='observation')), num_align_seqs) @@ -1432,8 +1413,7 @@ def test_pick_subsampled_open_reference_otus_suppress_step4(self): "PyNAST failures file doesn't exist") # all OTUs in final OTU table occur more than once - with biom_open(otu_table_fp) as biom_file: - otu_table = Table.from_hdf5(biom_file) + otu_table = load_table(otu_table_fp) for row in otu_table.iter_data(axis='observation'): self.assertTrue(sum(row) >= 2, "Singleton OTU detected in OTU table.") @@ -1488,8 +1468,7 @@ def test_pick_subsampled_open_reference_otus_suppress_step4(self): # OTU table without singletons or pynast failures has same number of # otus as there are aligned sequences - with biom_open(otu_table_fp) as biom_file: - otu_table = Table.from_hdf5(biom_file) + otu_table = load_table(otu_table_fp) self.assertEqual(len(otu_table.ids(axis='observation')), num_align_seqs) @@ -1592,8 +1571,7 @@ def test_iterative_pick_subsampled_open_reference_otus_no_prefilter(self): "Iteration 1 OTU map with singletons doesn't exist") # all OTUs in final OTU table occur more than once - with biom_open(otu_table_fp) as biom_file: - otu_table = Table.from_hdf5(biom_file) + otu_table = load_table(otu_table_fp) for row in otu_table.iter_data(axis='observation'): self.assertTrue(sum(row) >= 2, "Singleton OTU detected in OTU table.") @@ -1734,8 +1712,7 @@ def test_iterative_pick_subsampled_open_reference_otus(self): "Iteration 1 OTU map with singletons doesn't exist") # all OTUs in final OTU table occur more than once - with biom_open(otu_table_fp) as biom_file: - otu_table = Table.from_hdf5(biom_file) + otu_table = load_table(otu_table_fp) for row in otu_table.iter_data(axis='observation'): self.assertTrue(sum(row) >= 2, "Singleton OTU detected in OTU table.") @@ -1876,8 +1853,7 @@ def test_iterative_pick_subsampled_open_reference_otus_parallel(self): "Iteration 1 OTU map with singletons doesn't exist") # all OTUs in final OTU table occur more than once - with biom_open(otu_table_fp) as biom_file: - otu_table = Table.from_hdf5(biom_file) + otu_table = load_table(otu_table_fp) for row in otu_table.iter_data(axis='observation'): self.assertTrue(sum(row) >= 2, "Singleton OTU detected in OTU table.")