Skip to content

Refactors _run_dada from R to python - #197

Open
Macabe222 wants to merge 22 commits into
qiime2:devfrom
Macabe222:run-dada-ref
Open

Macabe222 wants to merge 22 commits into
qiime2:devfrom
Macabe222:run-dada-ref

Conversation

@Macabe222

@Macabe222 Macabe222 commented Jul 8, 2026 •

Copy link
Copy Markdown

Description

Deletes run_dada.R and replaces it with _run_dada.py, using rpy2. Slightly faster on moving pictures demux.qza, 1:28 vs 1:33.
Addresses #172

AI Disclosure

  • NO AI USED.
  • AI USED.

@github-project-automation github-project-automation Bot moved this to Needs Triage in QIIME 2 - Triage 🚑 Jul 8, 2026
@colinvwood colinvwood self-assigned this Jul 8, 2026
@colinvwood colinvwood added the stat:DO-NOT-MERGE Please do not merge this until this label has been removed. label Jul 14, 2026
@colinvwood

colinvwood commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

waiting on #190

@colinvwood

Copy link
Copy Markdown
Contributor

Note: Pseudo-pooling now uses DADA2’s native pool="pseudo" implementation, instead of two calls to dada on our end. That updates the error model between rounds, whereas run_dada.R reused the first learned model. This results in different, though desirable, output compared to the pre-refactor version.

@benjjneb benjjneb left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dada2 derepFastq function should not be called explicitly in this workflow. This is to avoid loading all samples into memory at the same time unnecessarily, which can be performance-breaking behavior on larger datasets.

benjjneb/dada2#919 (comment)
benjjneb/dada2#1095 (comment)

The R dada function should be passed a vector of file paths rather than the outpur of derepFastq.

Specific places where this performance hit will be felt are in the pseudo-pooling calls:

https://github.com/qiime2/q2-dada2/pull/197/changes/d638c023f9ab03f9a17061633b559ed7a37f63a1..0fc08b57a3e40a53b741dc459ee163cb6101c222#diff-dd7407f67ac9fa623337b0138c3539d679aa730b1ab132271bbf21a218822fbeR439
https://github.com/qiime2/q2-dada2/pull/197/changes/d638c023f9ab03f9a17061633b559ed7a37f63a1..0fc08b57a3e40a53b741dc459ee163cb6101c222#diff-dd7407f67ac9fa623337b0138c3539d679aa730b1ab132271bbf21a218822fbeR545
https://github.com/qiime2/q2-dada2/pull/197/changes/d638c023f9ab03f9a17061633b559ed7a37f63a1..0fc08b57a3e40a53b741dc459ee163cb6101c222#diff-dd7407f67ac9fa623337b0138c3539d679aa730b1ab132271bbf21a218822fbeR552

But the code for the regular operation of dada can also be simplified by removing the looping in the Q2 code:

https://github.com/qiime2/q2-dada2/pull/197/changes/d638c023f9ab03f9a17061633b559ed7a37f63a1..0fc08b57a3e40a53b741dc459ee163cb6101c222#diff-dd7407f67ac9fa623337b0138c3539d679aa730b1ab132271bbf21a218822fbeR568

Similarly, the calls to mergePairs can also take the filepaths instead of the output of derepFastq.

A test (probably non-automatable due to computational cost) to see if this is working correctly is to evaluate the memory usage of this workflow on increasing sample number. At larger numbers of samples, memory costs if derepFastq is being called on the whole dataset will go up linearly with sample number, while if samples are being processed one-at-a-time the memory cost will stay roughly constant with sample number.

@colinvwood

Copy link
Copy Markdown
Contributor

Hello @benjjneb, thank you for the feedback. The memory concerns make sense; I will refactor to pass filepaths and let the R package be more intelligent wrt the derep objects.

@Oddant1
Oddant1 self-requested a review August 17, 2026 22:12

@Oddant1 Oddant1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preliminary review. More to come.

One additional thing, what's with the changes to the test data?

Comment thread q2_dada2/tests/test_denoise.py
Comment thread q2_dada2/_r_utils.py
Comment thread conda-recipe/meta.yaml
Comment thread q2_dada2/_dada_stats/__init__.py Outdated
@Oddant1
Oddant1 self-requested a review August 18, 2026 00:01
@colinvwood

Copy link
Copy Markdown
Contributor

Preliminary review. More to come.

One additional thing, what's with the changes to the test data?

Good question, they're for the pseudo pooling method only, and the reason is explained in my comment from a few weeks ago:

Note: Pseudo-pooling now uses DADA2’s native pool="pseudo" implementation, instead of two calls to dada on our end. That updates the error model between rounds, whereas run_dada.R reused the first learned model. This results in different, though desirable, output compared to the pre-refactor version.

Comment thread q2_dada2/_dada_stats/_error_model.py Outdated
@lizgehret

Copy link
Copy Markdown
Member

Just chatted with @ebolyen about this, we'll get this reviewed shortly!

@colinvwood colinvwood removed the stat:DO-NOT-MERGE Please do not merge this until this label has been removed. label Aug 26, 2026

@VinzentRisch VinzentRisch left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello
This looks like it was a lot of work! The refactored code looks very good and is a big improvement to the R file.
I ran some example data with denoise-paired and denoise-single and that works without problems.
See some comments below.

Comment thread q2_dada2/_dada_stats/_error_model.py Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there should be unittests added for the helpers in this file.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these are covered by the tests added in #169

Comment thread q2_dada2/_denoise.py
Comment thread q2_dada2/_denoise.py Outdated
Comment thread q2_dada2/_denoise.py Outdated
Comment thread q2_dada2/tests/test_denoise.py Outdated
Comment thread q2_dada2/_run_dada.py Outdated
Comment thread q2_dada2/_run_dada.py Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants