Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add plots for DE analysis and unify plotting API #654

Merged
merged 21 commits into from
Sep 16, 2024
Merged

Conversation

Lilly-May
Copy link
Collaborator

PR Checklist

Description of changes

  • Unified plotting API: We now have three parameters (save, show, return_fig) in the plotting functions, and I added a utility method to handle showing and saving plots. Previously, showing and storing figures were handled differently ba the different plotting functions.
  • Added four plotting functions to be used in the DE tutorial: one for pseudobulk analysis, and three for differential expression analysis, as described in Better support for DE in scverse #189.

Discussion points
I'm not entirely sure about the plot_fold_change method yet. In #189, it was suggested as a plot for paired samples, but I think it would be nice (and I implemented it that way as of now) if the plot could work directly with the results_df returned by all DE tools, i.e., plotting the log-FC from that dataframe. However, I’m unsure how to incorporate the pairing in that case and would appreciate ideas.

@github-actions github-actions bot added the enhancement New feature or request label Sep 5, 2024
@codecov-commenter
Copy link

codecov-commenter commented Sep 6, 2024

Codecov Report

Attention: Patch coverage is 26.24434% with 163 lines in your changes missing coverage. Please review.

Project coverage is 65.55%. Comparing base (2ad41a7) to head (7e814fa).

Files with missing lines Patch % Lines
...ertpy/tools/_differential_gene_expression/_base.py 12.30% 114 Missing ⚠️
pertpy/tools/_milo.py 36.84% 12 Missing ⚠️
pertpy/preprocessing/_guide_rna.py 30.00% 7 Missing ⚠️
pertpy/tools/_perturbation_space/_simple.py 46.15% 7 Missing ⚠️
pertpy/metadata/_cell_line.py 25.00% 6 Missing ⚠️
pertpy/tools/_cinemaot.py 25.00% 6 Missing ⚠️
pertpy/tools/_enrichment.py 33.33% 6 Missing ⚠️
pertpy/tools/_scgen/_scgen.py 40.00% 3 Missing ⚠️
pertpy/tools/_dialogue.py 75.00% 1 Missing ⚠️
pertpy/tools/_mixscape.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #654      +/-   ##
==========================================
- Coverage   66.34%   65.55%   -0.79%     
==========================================
  Files          46       47       +1     
  Lines        5960     6105     +145     
==========================================
+ Hits         3954     4002      +48     
- Misses       2006     2103      +97     
Files with missing lines Coverage Δ
pertpy/_doc.py 100.00% <100.00%> (ø)
pertpy/tools/__init__.py 85.71% <100.00%> (ø)
pertpy/tools/_augur.py 72.15% <100.00%> (+3.47%) ⬆️
pertpy/tools/_coda/_base_coda.py 56.30% <100.00%> (+0.07%) ⬆️
...rtpy/tools/_differential_gene_expression/_edger.py 87.09% <100.00%> (ø)
...y/tools/_perturbation_space/_perturbation_space.py 86.59% <ø> (ø)
pertpy/tools/_dialogue.py 35.47% <75.00%> (+1.21%) ⬆️
pertpy/tools/_mixscape.py 79.12% <50.00%> (-0.29%) ⬇️
pertpy/tools/_scgen/_scgen.py 63.69% <40.00%> (+0.42%) ⬆️
pertpy/metadata/_cell_line.py 49.80% <25.00%> (-0.60%) ⬇️
... and 6 more

@Lilly-May Lilly-May marked this pull request as ready for review September 6, 2024 14:22
Copy link
Member

@Zethson Zethson left a comment

Choose a reason for hiding this comment

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

Thank you very much! So many improvements in this PR.

  1. image
    are the stars missing for the significance levels here?
  2. _utils modules/files are a code smell. Could we move the savefig_or_show code into a plotting module? Could we move the doc stuff into a _doc file or something?
  3. I didn't always want to mark it, but show: if True, show to the plot after saving it. is maybe better wording then what you have? Another set of colons can also cause unintended issues.
  4. Could you amend the tutorial, please?

pertpy/_utils.py Outdated Show resolved Hide resolved
pertpy/_utils.py Outdated Show resolved Hide resolved
pertpy/tools/_perturbation_space/_simple.py Outdated Show resolved Hide resolved
pertpy/tools/_perturbation_space/_simple.py Outdated Show resolved Hide resolved
tests/tools/_differential_gene_expression/test_edger.py Outdated Show resolved Hide resolved
pertpy/tools/_differential_gene_expression/_base.py Outdated Show resolved Hide resolved
pertpy/tools/_differential_gene_expression/_base.py Outdated Show resolved Hide resolved
pertpy/tools/_differential_gene_expression/_base.py Outdated Show resolved Hide resolved
@Lilly-May
Copy link
Collaborator Author

Thanks for the review!

  1. The stars were there, but in white... Not my smartest move... It's fixed now.
  2. Sure, I'll move both. But for the plotting utilities, are you planning to keep the pertpy.plot module in the long run, even though all the plots have been moved to the tools module? In that case, maybe I shouldn't move it into that module.
  3. Not really sure what you're referring to here. Do you mean the default parameter description in _utils?
  4. Yes, I already started adapting the tutorial and hope to get it done over the weekend.

@Zethson
Copy link
Member

Zethson commented Sep 6, 2024

  1. We may redo the architecture again in the future if I ever find the time. But for now, we don't plan on providing a lot if anything in the pl plotting module.
  2. Added a comment

@Lilly-May
Copy link
Collaborator Author

Hi @grst!
We've added some DE plots in this PR following your suggestions in #189. However, I'm unsure how to implement the paired fold-change bar plot without completely ignoring the results from the DE tools, i.e. I would like to use the results_df as input to the plot, as it is currently implemented in this PR. Do you maybe have any suggestions? Thanks in advance!

@Lilly-May Lilly-May requested a review from grst September 7, 2024 07:48
pertpy/_utils.py Outdated Show resolved Hide resolved
pertpy/tools/_differential_gene_expression/_base.py Outdated Show resolved Hide resolved
@grst
Copy link
Collaborator

grst commented Sep 8, 2024

I would like to use the results_df as input to the plot, as it is currently implemented in this PR. Do you maybe have any suggestions?

The "best" solution IMO would be the Results class object as indicated in the code comments. But since this might entail quite some additional refactoring this is probably beyond the scope of this PR. Why can't you just provide the data frame as you suggest and then filter it for the relevant genes?

@Lilly-May
Copy link
Collaborator Author

Why can't you just provide the data frame as you suggest and then filter it for the relevant genes?

If I understand you correctly, that's what I'm currently doing. I'm just not sure how to incorporate the pairing into this based on the results_df alone, without calculating a lot of new metrics. But maybe the current plot version is sufficient for this PR, and we can consider adding the one including paired samples as a separate plot in a future PR.

pertpy/tools/_perturbation_space/_simple.py Show resolved Hide resolved
@@ -243,7 +299,7 @@ def _map_genes_categories_highlight(
if varm_key is None:
raise ValueError("Please pass a .varm key to use for plotting")

raise NotImplementedError("Anndata not implemented yet")
raise NotImplementedError("Anndata not implemented yet") # TODO: Implement this
Copy link
Collaborator

Choose a reason for hiding this comment

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

What would be the anndata usecase here actually? DE results stored in .varm?
This is not supported by the DE tools either, so not sure this is required.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm actually not sure myself - that part was already implemented (or rather not implemented in this case). @Zethson, what exactly did you have in mind here? Should I remove it?

pertpy/tools/_differential_gene_expression/_base.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@grst grst left a comment

Choose a reason for hiding this comment

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

Really nice work btw, thank you for working on this!

pertpy/tools/_differential_gene_expression/_base.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@grst grst left a comment

Choose a reason for hiding this comment

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

A few more minor points... LGTM in general now

pertpy/preprocessing/_guide_rna.py Outdated Show resolved Hide resolved
pertpy/tools/_augur.py Show resolved Hide resolved
pertpy/tools/_cinemaot.py Outdated Show resolved Hide resolved
pertpy/tools/_coda/_base_coda.py Outdated Show resolved Hide resolved
pertpy/tools/_differential_gene_expression/_base.py Outdated Show resolved Hide resolved
pertpy/tools/_differential_gene_expression/_base.py Outdated Show resolved Hide resolved
@Zethson Zethson merged commit 99dcd18 into main Sep 16, 2024
5 checks passed
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.

4 participants