Skip to content

Add plot_bcv()#1007

Open
LuisHeinzlmeier wants to merge 4 commits into
mainfrom
feature/plot-bcv
Open

Add plot_bcv()#1007
LuisHeinzlmeier wants to merge 4 commits into
mainfrom
feature/plot-bcv

Conversation

@LuisHeinzlmeier

Copy link
Copy Markdown
Collaborator
  • add plot_bcv()
  • add _prepare_dge() to be able to run plot_bcv() before .fit() without calculating normalization factors and estimating dispersions twice
  • add _ensure_deps() to prevent repetitive imports and code
  • closes Add variance mean plots for DGE #968

@github-actions github-actions Bot added the enhancement New feature or request label Jun 3, 2026

@LuisHeinzlmeier LuisHeinzlmeier left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Ready for a review!

@LuisHeinzlmeier LuisHeinzlmeier requested a review from Zethson June 3, 2026 05:54
@Zethson Zethson marked this pull request as ready for review June 3, 2026 06:28
self.fit = fit

@_doc_params(common_plot_args=doc_common_plot_args)
def plot_bcv( # pragma: no cover # noqa: D417

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.

This is only designed for edger now, right? But it should also work with statsmodels or pydeseq2. Like ideally, I'd like to completely phase out the edger support at some point in the future.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

As I understand it, plotBCV() in edgeR is equivalent to plotDispEsts() in DESeq2 because they use the same approach: plotting mean counts against dispersions/variation. The plots differ because edgeR and DESeq2 model differential gene expression slightly differently. But they want to show the same concept.

So I would say it doesn't make sense to add the plotBCV() function from edgeR to DESeq2. I don't think it would even be possible to integrate the same plot into DESeq2.

If you plan to remove edgeR in the long run, I would also only add plotMA() of #969. Also, these plots essentially show the same thing, but there exists one version for DESeq2 and one for edgeR.

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.

Got it. I'd be happy if we only had one version that worked for both.

>>> adata.layers["counts"] = adata.X.copy()
>>> pdata = dc.pp.pseudobulk(adata, sample_col="Patient", groups_col="Cluster", layer="counts", mode="sum")
>>> dc.pp.filter_samples(pdata, inplace=True)
>>> edgr = pt.tl.EdgeR(pdata, design="~Efficacy+Treatment")

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.

I'd love this to be pydeseq2

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

See above :)


ro.globalenv["fit"] = fit
self.fit = fit
self.dge = dge

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.

Why these changes here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It is possible to run plotBCV() before fitting, but the plot needs the part before 'self.dge = dge' for that (e.g. estimateDisp()). This prevents running the part before 'self.dge = dge' multiple times. In this way, it is also possible to run plotBCV() without fitting the whole model immediately. Basically, to save the intermediate steps to make it run faster and prevent redundant code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add variance mean plots for DGE

2 participants