Skip to content

Commit

Permalink
IMP: 'subsample' action renamed to 'subsample_ids' (#301)
Browse files Browse the repository at this point in the history
  • Loading branch information
hagenjp authored Jan 4, 2024
1 parent 1987eb0 commit 9f87ffb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions q2_feature_table/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# ----------------------------------------------------------------------------

from ._normalize import rarefy
from ._subsample import subsample
from ._subsample_ids import subsample_ids
from ._transform import (presence_absence, relative_frequency, transpose)
from ._summarize import (summarize, tabulate_seqs, tabulate_sample_frequencies,
tabulate_feature_frequencies, summarize_plus)
Expand All @@ -28,7 +28,7 @@
'summarize', 'merge', 'merge_seqs', 'filter_samples',
'filter_features', 'merge_taxa', 'tabulate_seqs', 'overlap_methods',
'core_features', 'group', 'heatmap', 'heatmap_choices',
'filter_seqs', 'subsample', 'rename_ids',
'filter_seqs', 'subsample_ids', 'rename_ids',
'filter_features_conditionally', 'split',
'tabulate_feature_frequencies', 'tabulate_sample_frequencies',
'summarize_plus']
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import biom


def subsample(table: biom.Table, subsampling_depth: int,
axis: str) -> biom.Table:
def subsample_ids(table: biom.Table, subsampling_depth: int,
axis: str) -> biom.Table:
if axis == 'feature':
# we are transposing the table due to biocore/biom-format#759
table = table.transpose()
Expand Down
2 changes: 1 addition & 1 deletion q2_feature_table/plugin_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
)

plugin.methods.register_function(
function=q2_feature_table.subsample,
function=q2_feature_table.subsample_ids,
inputs={'table': FeatureTable[Frequency]},
parameters={'subsampling_depth': Int % Range(1, None),
'axis': Str % Choices(['sample', 'feature'])},
Expand Down
16 changes: 8 additions & 8 deletions q2_feature_table/tests/test_subsample.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
import numpy.testing as npt
from biom.table import Table

from q2_feature_table import subsample
from q2_feature_table import subsample_ids


class SubsampleTests(TestCase):
class SubsampleIDsTests(TestCase):

def test_subsample_samples(self):
t = Table(np.array([[0, 1, 3], [1, 1, 2]]),
['O1', 'O2'],
['S1', 'S2', 'S3'])
a = subsample(t, 2, 'sample')
a = subsample_ids(t, 2, 'sample')
self.assertEqual(a.shape, (2, 2))

sample_ids = frozenset(a.ids(axis='sample'))
Expand All @@ -38,7 +38,7 @@ def test_subsample_features(self):
t = Table(np.array([[0, 1, 3], [1, 1, 2]]).T,
['O1', 'O2', 'O3'],
['S1', 'S2'])
a = subsample(t, 2, 'feature')
a = subsample_ids(t, 2, 'feature')
self.assertEqual(a.shape, (2, 2))

sample_ids = frozenset(a.ids(axis='observation'))
Expand All @@ -56,28 +56,28 @@ def test_subsample_samples_oversample(self):
['O1', 'O2', 'O3'],
['S1', 'S2'])
with self.assertRaisesRegex(ValueError, "depth exceeds"):
subsample(t, 10, 'sample')
subsample_ids(t, 10, 'sample')

def test_subsample_features_oversample(self):
t = Table(np.array([[0, 1, 3], [1, 1, 2]]).T,
['O1', 'O2', 'O3'],
['S1', 'S2'])
with self.assertRaisesRegex(ValueError, "depth exceeds"):
subsample(t, 10, 'feature')
subsample_ids(t, 10, 'feature')

def test_subsample_samples_empty(self):
t = Table(np.array([[0, 0, 0], [0, 0, 0]]).T,
['O1', 'O2', 'O3'],
['S1', 'S2'])
with self.assertRaisesRegex(ValueError, "contains no"):
subsample(t, 2, 'sample')
subsample_ids(t, 2, 'sample')

def test_subsample_features_empty(self):
t = Table(np.array([[0, 0, 0], [0, 0, 0]]).T,
['O1', 'O2', 'O3'],
['S1', 'S2'])
with self.assertRaisesRegex(ValueError, "contains no"):
subsample(t, 2, 'feature')
subsample_ids(t, 2, 'feature')


if __name__ == "__main__":
Expand Down

0 comments on commit 9f87ffb

Please sign in to comment.