diff --git a/q2_boots/_beta.py b/q2_boots/_beta.py index 1410d0e..6cedf57 100644 --- a/q2_boots/_beta.py +++ b/q2_boots/_beta.py @@ -19,6 +19,13 @@ from q2_boots._resample import resample +_METRIC_MOD_DEFAULTS = { + 'bypass_tips': False, + 'pseudocount': 1, + 'alpha': None, + 'variance_adjusted': False +} + def beta_average(data: skbio.DistanceMatrix, average_method: str) -> skbio.DistanceMatrix: @@ -42,13 +49,19 @@ def beta_average(data: skbio.DistanceMatrix, "mean, and medoid.") -def beta_collection(ctx, table, metric, sampling_depth, n, replacement, - phylogeny=None, bypass_tips=False, n_jobs=1, - pseudocount=1, alpha=None, variance_adjusted=False): +def beta_collection( + ctx, table, metric, sampling_depth, n, replacement, + phylogeny=None, + bypass_tips=_METRIC_MOD_DEFAULTS['bypass_tips'], + pseudocount=_METRIC_MOD_DEFAULTS['pseudocount'], + alpha=_METRIC_MOD_DEFAULTS['alpha'], + variance_adjusted=_METRIC_MOD_DEFAULTS['variance_adjusted']): _validate_beta_metric(metric, phylogeny) resample_function = resample - beta_metric_function = _get_beta_metric_function(ctx, metric, phylogeny) + beta_metric_function = _get_beta_metric_function( + ctx, metric, phylogeny, bypass_tips, pseudocount, alpha, + variance_adjusted) tables = resample_function(ctx=ctx, table=table, @@ -61,8 +74,11 @@ def beta_collection(ctx, table, metric, sampling_depth, n, replacement, def beta(ctx, table, metric, sampling_depth, n, replacement, - average_method='non-metric-median', phylogeny=None, bypass_tips=False, - n_jobs=1, pseudocount=1, alpha=None, variance_adjusted=False): + average_method='non-metric-median', phylogeny=None, + bypass_tips=_METRIC_MOD_DEFAULTS['bypass_tips'], + pseudocount=_METRIC_MOD_DEFAULTS['pseudocount'], + alpha=_METRIC_MOD_DEFAULTS['alpha'], + variance_adjusted=_METRIC_MOD_DEFAULTS['variance_adjusted']): beta_collection_function = beta_collection beta_average_action = ctx.get_action('boots', 'beta_average') dms = beta_collection_function(ctx=ctx, @@ -73,7 +89,6 @@ def beta(ctx, table, metric, sampling_depth, n, replacement, n=n, pseudocount=pseudocount, replacement=replacement, - n_jobs=n_jobs, variance_adjusted=variance_adjusted, alpha=alpha, bypass_tips=bypass_tips) @@ -114,18 +129,23 @@ def _validate_beta_metric(metric, phylogeny): raise ValueError(f'Metric {metric} requires a phylogenetic tree.') -def _get_beta_metric_function(ctx, metric, phylogeny): +def _get_beta_metric_function( + ctx, metric, phylogeny, + bypass_tips=_METRIC_MOD_DEFAULTS['bypass_tips'], + pseudocount=_METRIC_MOD_DEFAULTS['pseudocount'], + alpha=_METRIC_MOD_DEFAULTS['alpha'], + variance_adjusted=_METRIC_MOD_DEFAULTS['variance_adjusted']): if _is_phylogenetic_beta_metric(metric): beta_metric_function = q2div_beta_phylogenetic - beta_metric_function = functools.partial(beta_metric_function, - ctx=ctx, - phylogeny=phylogeny, - metric=metric) + beta_metric_function = functools.partial( + beta_metric_function, ctx=ctx, phylogeny=phylogeny, metric=metric, + bypass_tips=bypass_tips, alpha=alpha, + variance_adjusted=variance_adjusted) else: beta_metric_function = q2div_beta - beta_metric_function = functools.partial(beta_metric_function, - ctx=ctx, - metric=metric) + beta_metric_function = functools.partial( + beta_metric_function, ctx=ctx, metric=metric, + pseudocount=pseudocount) return beta_metric_function diff --git a/q2_boots/_core_metrics.py b/q2_boots/_core_metrics.py index 0ba8678..db7c6eb 100644 --- a/q2_boots/_core_metrics.py +++ b/q2_boots/_core_metrics.py @@ -16,7 +16,7 @@ def core_metrics(ctx, table, sampling_depth, metadata, n, replacement, - n_jobs=1, phylogeny=None, alpha_average_method='median', + phylogeny=None, alpha_average_method='median', beta_average_method='non-metric-median'): resample_function = resample diff --git a/q2_boots/plugin_setup.py b/q2_boots/plugin_setup.py index 6ec4197..b1cecab 100644 --- a/q2_boots/plugin_setup.py +++ b/q2_boots/plugin_setup.py @@ -6,9 +6,8 @@ # The full license is in the file LICENSE, distributed with this software. # ---------------------------------------------------------------------------- -from qiime2.plugin import (Plugin, Int, Range, Collection, - Str, Choices, Bool, Float, Threads, - Metadata, Visualization) +from qiime2.plugin import (Plugin, Int, Range, Collection, Str, Choices, Bool, + Float, Metadata, Visualization) from q2_types.feature_table import ( FeatureTable, Frequency, RelativeFrequency, PresenceAbsence @@ -252,7 +251,6 @@ beta_metrics['PHYLO']['UNIMPL']), 'pseudocount': Int % Range(1, None), 'replacement': Bool, - 'n_jobs': Threads, 'n': Int % Range(1, None), 'sampling_depth': Int % Range(1, None), 'bypass_tips': Bool, @@ -260,19 +258,11 @@ 'alpha': Float % Range(0, 1, inclusive_end=True) } -_n_jobs_description = ( - 'The number of CPU threads to use in performing this calculation. ' - 'May not exceed the number of available physical cores. If threads = ' - '\'auto\', one thread will be created for each identified CPU core on the ' - 'host.' -) - _beta_collection_parameter_descriptions = { 'metric': 'The beta diversity metric to be computed.', 'pseudocount': ('A pseudocount to handle zeros for compositional ' 'metrics. This is ignored for other metrics.'), 'replacement': _replacement_description, - 'n_jobs': _n_jobs_description, 'n': _n_description, 'sampling_depth': _sampling_depth_description, 'bypass_tips': ('Ignore tips of tree in phylogenetic diversity ' @@ -341,7 +331,6 @@ inputs=_diversity_inputs, parameters={ 'metadata': Metadata, - 'n_jobs': Threads, 'n': Int % Range(1, None), 'sampling_depth': Int % Range(1, None), 'alpha_average_method': Str % Choices('mean', 'median'), @@ -360,7 +349,6 @@ input_descriptions=_diversity_input_descriptions, parameter_descriptions={ 'metadata': 'The sample metadata used in generating Emperor plots.', - 'n_jobs': _n_jobs_description, 'n': _n_description, 'sampling_depth': _sampling_depth_description, 'alpha_average_method': 'Method to use for averaging alpha diversity.', diff --git a/q2_boots/tests/test_core_metrics.py b/q2_boots/tests/test_core_metrics.py index 0779612..f35180c 100644 --- a/q2_boots/tests/test_core_metrics.py +++ b/q2_boots/tests/test_core_metrics.py @@ -40,7 +40,6 @@ def test_core_metrics_wo_replacement(self): output = self.core_metrics(table=self.table1, sampling_depth=2, metadata=self.metadata, - n_jobs=1, replacement=False, n=10) # n tables returned @@ -78,7 +77,6 @@ def test_core_metrics_w_replacement(self): output = self.core_metrics(table=self.table1, sampling_depth=2, metadata=self.metadata, - n_jobs=1, replacement=True, n=99) # n tables returned @@ -146,7 +144,6 @@ def test_core_metrics_phylogenetic(self): phylogeny=self.phylogeny, sampling_depth=2, metadata=self.metadata, - n_jobs=1, replacement=False, n=10) # n tables returned