Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IMP: 'subsample' action renamed to 'subsample_ids' #301

Merged
merged 9 commits into from
Jan 4, 2024
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
14 changes: 7 additions & 7 deletions q2_feature_table/tests/test_subsample.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
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):
Expand All @@ -21,7 +21,7 @@ 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