Skip to content

Commit

Permalink
Merge pull request #24 from caporaso-lab/release-prep
Browse files Browse the repository at this point in the history
MAINT: prep for release
  • Loading branch information
ebolyen authored Aug 9, 2024
2 parents 1c32499 + 91ff38a commit 2655825
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 181 deletions.
55 changes: 0 additions & 55 deletions images/pipeline-chart.md

This file was deleted.

19 changes: 0 additions & 19 deletions images/pipeline-key.md

This file was deleted.

50 changes: 35 additions & 15 deletions q2_boots/_beta.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion q2_boots/_core_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions q2_boots/citations.bib

This file was deleted.

32 changes: 10 additions & 22 deletions q2_boots/plugin_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
# The full license is in the file LICENSE, distributed with this software.
# ----------------------------------------------------------------------------

from qiime2.plugin import (Plugin, Int, Range, Collection,
Citations, 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
Expand All @@ -33,8 +32,6 @@
_core_metrics_rarefaction_example)


Citations = Citations.load('citations.bib', package='q2_boots')

plugin = Plugin(
name='boots',
version=q2_boots.__version__,
Expand All @@ -48,7 +45,12 @@
)


_feature_table_description = 'The feature table to be resampled.'
_feature_table_description = 'The input feature table.'
_phylogeny_description = (
'The phylogenetic tree to use in phylogenetic diversity '
'calculations. All feature ids in `table` must be present in '
'this tree, but this tree can contain feature ids that are '
'not present in `table`.')
_sampling_depth_description = (
'The total number of observations that each sample in `table` should be '
'resampled to. Samples where the total number of observations in `table` '
Expand Down Expand Up @@ -110,11 +112,8 @@
}

_diversity_input_descriptions = {
'table': 'The feature table to use in diversity computations.',
'phylogeny': ('The phylogenetic tree to use in phylogenetic diversity '
'calculations. All feature ids in `table` must be present in '
'this tree, but this tree can contain feature ids that are '
'not present in `table`.')
'table': _feature_table_description,
'phylogeny': _phylogeny_description
}

_alpha_average_parameters = {
Expand Down Expand Up @@ -252,27 +251,18 @@
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,
'variance_adjusted': Bool,
'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 '
Expand Down Expand Up @@ -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'),
Expand All @@ -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.',
Expand Down
30 changes: 10 additions & 20 deletions q2_boots/tests/test_alpha.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ def test_alpha_collection_w_replacement(self):
index=['S1', 'S2'],
name='observed_features')
for alpha_vector in observed.values():
observed_series = qiime2.Artifact.view(alpha_vector,
view_type=pd.Series)
observed_series = alpha_vector.view(pd.Series)
pdt.assert_series_equal(observed_series, expected_series)

# at a sampling depth of 2, with table1 as input and sampling with
Expand All @@ -101,8 +100,7 @@ def test_alpha_collection_w_replacement(self):
count_possible_series2_observed = 0
other_series_observed = False
for alpha_vector in observed.values():
observed_series = qiime2.Artifact.view(alpha_vector,
view_type=pd.Series)
observed_series = alpha_vector.view(pd.Series)
if observed_series.equals(possible_series1):
count_possible_series1_observed += 1
elif observed_series.equals(possible_series2):
Expand Down Expand Up @@ -133,8 +131,7 @@ def test_alpha_collection_wo_replacement(self):
index=['S1', 'S2'],
name='observed_features')
for alpha_vector in observed.values():
observed_series = qiime2.Artifact.view(alpha_vector,
view_type=pd.Series)
observed_series = alpha_vector.view(pd.Series)
pdt.assert_series_equal(observed_series, expected_series)

def test_alpha_collection_phylogenetic(self):
Expand All @@ -160,8 +157,7 @@ def test_alpha_collection_phylogenetic(self):
index=['S1', 'S2'],
name='faith_pd')
for alpha_vector in observed.values():
observed_series = qiime2.Artifact.view(alpha_vector,
view_type=pd.Series)
observed_series = alpha_vector.view(pd.Series)
pdt.assert_series_equal(observed_series, expected_series)

def test_alpha_collection_invalid_input(self):
Expand Down Expand Up @@ -203,8 +199,7 @@ def test_alpha_w_replacement(self):
observed, = self.alpha_pipeline(
table=table1, sampling_depth=1, metric='observed_features', n=42,
replacement=True)
observed_series = qiime2.Artifact.view(observed,
view_type=pd.Series)
observed_series = observed.view(pd.Series)

expected_series = pd.Series([1., 1.],
index=['S1', 'S2'],
Expand All @@ -219,8 +214,7 @@ def test_alpha_w_replacement(self):
observed, = self.alpha_pipeline(
table=table1, sampling_depth=2, metric='observed_features',
n=99, replacement=True)
observed_series = qiime2.Artifact.view(observed,
view_type=pd.Series)
observed_series = observed.view(pd.Series)
# note that because n is an odd number, the median for S1 will always
# be one of the actual values that were observed (as opposed to possibly
# being 1.5, if n was an even number).
Expand All @@ -236,8 +230,7 @@ def test_alpha_w_replacement(self):
observed, = self.alpha_pipeline(
table=table1, sampling_depth=2, metric='observed_features',
n=100, replacement=True, average_method='mean')
observed_series = qiime2.Artifact.view(observed,
view_type=pd.Series)
observed_series = observed.view(pd.Series)
# note that b/c these are <, not <=, we know that identical tables
# were not always obtained from the resampling step
self.assertTrue(1.0 < observed_series['S1'] < 2.0)
Expand All @@ -256,8 +249,7 @@ def test_alpha_wo_replacement(self):
observed, = self.alpha_pipeline(
table=table1, sampling_depth=1, metric='observed_features', n=42,
replacement=False)
observed_series = qiime2.Artifact.view(observed,
view_type=pd.Series)
observed_series = observed.view(pd.Series)

expected_series = pd.Series([1., 1.],
index=['S1', 'S2'],
Expand All @@ -270,8 +262,7 @@ def test_alpha_wo_replacement(self):
observed, = self.alpha_pipeline(
table=table1, sampling_depth=2, metric='observed_features',
n=100, replacement=False)
observed_series = qiime2.Artifact.view(observed,
view_type=pd.Series)
observed_series = observed.view(pd.Series)

expected_series = pd.Series([2., 1.],
index=['S1', 'S2'],
Expand All @@ -284,8 +275,7 @@ def test_alpha_wo_replacement(self):
observed, = self.alpha_pipeline(
table=table1, sampling_depth=2, metric='observed_features',
n=100, replacement=False, average_method='mean')
observed_series = qiime2.Artifact.view(observed,
view_type=pd.Series)
observed_series = observed.view(pd.Series)

expected_series = pd.Series([2., 1.],
index=['S1', 'S2'],
Expand Down
Loading

0 comments on commit 2655825

Please sign in to comment.