Replaces original da-barplot with ANCOMBC2-visualizer#166
Conversation
|
Hey @Macabe222, let us know when this one needs a review! |
|
@lizgehret this one should be good now |
lizgehret
left a comment
There was a problem hiding this comment.
Hey @Macabe222, this all generally lgtm; just some test coverage changes mentioned below!
| self.assertEqual(len(variable_with_spaces_columns), 2) | ||
|
|
||
| def test_ancombc2_visualizer(self): | ||
| def test_da_barplot(self): |
There was a problem hiding this comment.
It's probably worth adding some additional tests to show that both formats can be used for this visualizer. I also think the tests that were removed with the deletion of test_diff_abundance_plot should be moved/refactored into here so that we aren't just losing all of that test coverage for the visualizer that's now supporting double the inputs/outputs.
There was a problem hiding this comment.
One other drive-by thought - maybe all of the shared tests for this visualizer should get moved into test_diff_abundance_plot and then the only tests in this file are for the ancombc2 method.
|
EDIT: discussed in eng meeting (21 April 2026); this was in our breaking changes for 2025.10 |
|
Hey @Macabe222 just a heads up, I've implemented a new PR template that's now connected to the lint action in CI for all of our distro plugins. I've retroactively added the template to this PR (since you opened it prior). You'll just need to select the appropriate AI disclosure checkbox & fill in details on that if AI was used. lmk if you have any questions! |
|
The failure here is a bit strange. Haven't fully dug through the framework to figure out why exactly this is working in this way, but Here we call ancombc2 as a raw function cls.abc2_output = ancombc2(
table=cls.biom_table,
metadata=cls.ancombc2_metadata,
fixed_effects_formula='body-site + year',
group='body-site',
structural_zeros=True
)
return transform(data=slices, to_type=ANCOMBC2OutputDirFmt)This is the transformer it is invoking. @plugin.register_transformer
def _2(slices: ANCOMBC2SliceMapping) -> ANCOMBC2OutputDirFmt:
'''
Transforms a dataframe of ANCOMBC2 model statistics into the ANCOMBC2
output directory format.
'''
format = ANCOMBC2OutputDirFmt()
for slice_name, slice_df in slices.items():
format_slice = format.__getattribute__(slice_name)
format_slice.write_data(slice_df, pd.DataFrame)
extra_files = ['diff', 'passed_ss']
if not any(file in slices.keys() for file in extra_files):
header = {
"doctype": {
"name": "table.jsonl",
"format": "application/x-json-lines",
"version": "1.0"
},
"direction": "row",
"style": "key:value",
"fields": [
{"name": "taxon", "type": "string", "missing": False},
{"name": "(Intercept)", "type": "number", "missing": False}
],
"index": [],
"title": "",
"description": "",
"extra": {}
}
for file in extra_files:
output_path = os.path.join(format.path, file + '.jsonl')
with open(output_path, 'w') as f:
f.write(json.dumps(header, separators=(',', ':')) + "\n")
return formatWe run the following two tests in the following order (some other tests also run and aren't relevant to the failure): First, test_da_barplot_action_ancombc2 which loads our def test_da_barplot_action_ancombc2(self):
pm = PluginManager()
da_barplot = pm.plugins['composition'].actions['da_barplot']
ancombc2_artifact = Artifact.import_data(
type='FeatureData[ANCOMBC2Output]', view=self.abc2_output
)
viz = da_barplot(ancombc2_artifact)
viz = viz.visualization
with tempfile.TemporaryDirectory() as tempdir:
viz.export_data(tempdir)
assert os.path.exists(os.path.join(tempdir, 'index.html'))Second, test_da_barplot_non_overlapping_taxonomy, which uses def test_da_barplot_non_overlapping_taxonomy(self):
'''
Tests that an error is raised when attempting to visualize ancombc2
data with a taxonomy that contains none of the features present in the
ancombc2 data.
'''
taxonomy_df = pd.DataFrame({
'Feature ID': ['feat1', 'feat2'],
'Taxon': ['taxon1', 'taxon2'],
'Confidence': [0.9, 0.95]
})
with tempfile.TemporaryDirectory() as tempdir:
with self.assertRaisesRegex(
ValueError, 'No features remained in your taxonomy'
):
da_barplot(tempdir, self.abc2_output, taxonomy_df)
with tempfile.TemporaryDirectory() as tempdir:
with self.assertRaisesRegex(
ValueError, 'No features remained in your taxonomy'
):
da_barplot(tempdir, self.abc_output, taxonomy_df)I'm not sure I fully understand what's happening yet, but due to the invocation of the transformer at the end of @lizgehret @ebolyen thoughts? Do we want to ditch invoking the transformer at the end of |
Description
Adds transformer of type
DataLoafPackageDirFmtto typeANCOMBC2OutputDirFmtallowingancombc2_visualizerto accept outputs fromancombc. Renamesancombc2_visualizertoda_barplotand deletes originalda_barplot.Addresses #156
AI Disclosure
AI Usage Details