Skip to content

Commit

Permalink
anthony-code-review
Browse files Browse the repository at this point in the history
  • Loading branch information
cherman2 committed Nov 5, 2024
1 parent e8fa9c8 commit 6a784f6
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 11 deletions.
23 changes: 13 additions & 10 deletions q2_fmt/_ancombc.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ def detect_donor_indicators(ctx, table, reference_column, time_column,
da_barplot = ctx.get_action('composition', 'da_barplot')
results = []

```suggestion
_check_for_time_column(metadata.to_dataframe(),
time_column)
_check_reference_column(metadata.to_dataframe(),
reference_column)

ids_to_keep = get_baseline_donor_md(metadata=metadata,
reference_column=reference_column,
Expand All @@ -33,19 +33,17 @@ def detect_donor_indicators(ctx, table, reference_column, time_column,
filtered_table, = filter(table=table,
metadata=Metadata(ids_to_keep))
dataloaf, = ancombc(table=filtered_table, metadata=Metadata(ids_to_keep),
reference_levels=["type::donor"], formula='type')
results += dataloaf
viz = da_barplot(data=dataloaf, significance_threshold=0.05,
level_delimiter=level_delimiter)
results += viz
reference_levels=["type::donor"], formula='type')
results.append(dataloaf)
viz, = da_barplot(data=dataloaf, significance_threshold=0.05,
level_delimiter=level_delimiter)
results.append(viz)
return tuple(results)


def get_baseline_donor_md(metadata, reference_column, time_column,
baseline_timepoint):
"""Checks if column is in the metdata
Checks that column is in the metdata and creates helpful error messages.
Parameters
"""Creates a metadata for differentiating baseline and donor
----------
metadata: pd.Dataframe
Study `Metadata`
Expand Down Expand Up @@ -75,7 +73,12 @@ def get_baseline_donor_md(metadata, reference_column, time_column,
ids_to_keep =\
pd.Series(index=md_df[reference_column].dropna().unique(),
data='donor', name='type')
ids_to_keep = pd.concat([ids_to_keep, pd.Series(index=md_df[md_df[time_column] == float(baseline_timepoint)].index.to_list(), data='baseline', name=type)])
ids_to_keep =\
pd.concat([ids_to_keep,
pd.Series(index=md_df[md_df[time_column] ==
float(baseline_timepoint)
].index.to_list(),
data='baseline', name=type)])

ids_to_keep = ids_to_keep.to_frame()
ids_to_keep.index.name = 'id'
Expand Down
24 changes: 24 additions & 0 deletions q2_fmt/_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,27 @@ def pprs_method(use):

pprs_group_dists.assert_output_type("Dist1D[Ordered, Matched] %"
" Properties('pprs')")


def detect_donor_indicators_method(use):
md = use.init_metadata('md', peds_md_factory)
table = use.init_artifact('table', feature_table_factory)

differentials, da_barplot = use.action(
use.UsageAction('fmt', 'detect_donor_indicators'),
use.UsageInputs(
table=table,
metadata=md,
time_column='time_point',
reference_column='Donor',
baseline_timepoint='1',
),
use.UsageOutputNames(
differentials='differentials',
da_barplot='da_barplot'
)

)

differentials.assert_output_type("FeatureData[DifferentialAbundance]")
da_barplot.assert_output_type(" Visualization")
7 changes: 6 additions & 1 deletion q2_fmt/plugin_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,12 @@
' differentials.'},
name='Detect Donor Indicators Features',
description='Runs a pipeline to indentify differetial features between the'
' donor and the baseline recipient'
' donor and the baseline recipient. This is done by filtering'
' the feature table to donor and baseline timepoints and'
' running ancombc comparing those groups',
examples={
'detect_methods': ex.detect_donor_indicators_method
}
)

importlib.import_module('q2_fmt._transformer')

0 comments on commit 6a784f6

Please sign in to comment.