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

Commit

Permalink
Merge pull request #1853 from jairideout/issue-1849
Browse files Browse the repository at this point in the history
BUG: replace Table.from_hdf5 with biom.load_table
  • Loading branch information
gregcaporaso committed Jan 12, 2015
2 parents f1802b7 + ad86dc3 commit 43270ab
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 67 deletions.
9 changes: 3 additions & 6 deletions qiime/workflow/pick_open_reference_otus.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 3 additions & 6 deletions tests/test_rarefaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand All @@ -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(),
Expand Down
11 changes: 4 additions & 7 deletions tests/test_simsam.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'))

Expand Down Expand Up @@ -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'))

Expand Down Expand Up @@ -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]
Expand Down
72 changes: 24 additions & 48 deletions tests/test_workflow/test_pick_open_reference_otus.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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.")
Expand Down

0 comments on commit 43270ab

Please sign in to comment.