Skip to content

Add calculation of gene set metrics module - #24

Merged
allyhawkins merged 10 commits into
devfrom
allyhawkins/geneset-metrics
Sep 2, 2026
Merged

Add calculation of gene set metrics module#24
allyhawkins merged 10 commits into
devfrom
allyhawkins/geneset-metrics

Conversation

@allyhawkins

Copy link
Copy Markdown
Member

This PR adds the second half of the module for calculating metrics, which includes metrics specific to genesets. I took any code related to gene set metrics, including running ORA, out of the original script and added it to the template here.

Similar to the other metrics module, I decided to output TSV files here rather than an RDS since I think it will be easier to work with. I saved the TSV with the full ORA results, the metrics for each metaprogam (gene set specificity), and the background stats.

The other main difference here is that I read in a pre-prepared term2gene file with all genes in the gene set rather than pulling from msigdb every time the script is run.

The original script also included extracting the top 200 genes from the metaprograms. I think it makes more sense to do this once and store it in the original RDS object that's saved as output from generate-metaprograms. So I updated that script to include the top genes.

When reviewing, please compare implementation to the previous script and look for any discrepancies that might not be intentional as described above.

Note that I'm still testing this since I'm getting an error that there's no package GO.db. I'm working on fixing this with the environment file, but figured it was still worth getting review started on the rest of it.

@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown

nf-core pipelines lint overall result: Passed ✅ ⚠️

Posted for pipeline commit 40bd923

+| ✅ 182 tests passed       |+
#| ❔  15 tests were ignored |#
!| ❗  27 tests had warnings |!
Details

❗ Test warnings:

  • files_unchanged - LICENSE does not match the template
  • readme - README contains the placeholder zenodo.XXXXXXX. This should be replaced with the zenodo doi (after the first release).
  • pipeline_todos - TODO string in README.md: TODO nf-core:
  • pipeline_todos - TODO string in README.md: Include a figure that guides the user through the major workflow steps. Many nf-core
  • pipeline_todos - TODO string in README.md: Fill in short bullet-pointed list of the default steps in the pipeline
  • pipeline_todos - TODO string in README.md: Describe the minimum required steps to execute the pipeline, e.g. how to prepare samplesheets.
  • pipeline_todos - TODO string in README.md: update the following command to include all required parameters for a minimal example
  • pipeline_todos - TODO string in README.md: If applicable, make list of people who have also contributed
  • pipeline_todos - TODO string in README.md: Add citation for pipeline after first release. Uncomment lines below and update Zenodo doi and badge at the top of this file.
  • pipeline_todos - TODO string in README.md: Add bibliography of tools and data used in your pipeline
  • pipeline_todos - TODO string in nextflow.config: Specify your pipeline's command line flags
  • pipeline_todos - TODO string in nextflow.config: Optionally, you can add a pipeline-specific nf-core config at https://github.com/nf-core/configs
  • pipeline_todos - TODO string in main.nf: Optionally add in-text citation tools to this list.
  • pipeline_todos - TODO string in main.nf: Optionally add bibliographic entries to this list.
  • pipeline_todos - TODO string in main.nf: Only uncomment below if logic in toolCitationText/toolBibliographyText has been filled!
  • pipeline_todos - TODO string in nextflow.config: Specify any additional parameters here
  • pipeline_todos - TODO string in output.md: Write this documentation describing your workflow's output
  • pipeline_todos - TODO string in usage.md: Add documentation about anything specific to running your pipeline. For general topics, please point to (and add to) the main nf-core website.
  • pipeline_todos - TODO string in CONTRIBUTING.md: Add any pipeline specific contribution guidelines here, such as coding styles, procedures, checklists etc.
  • pipeline_todos - TODO string in base.config: Check the defaults for all processes
  • pipeline_todos - TODO string in base.config: Customise requirements for specific processes.
  • pipeline_todos - TODO string in test.config: Specify the paths to your test data on nf-core/test-datasets
  • pipeline_todos - TODO string in test.config: Give any required params for the test so that command line flags are not needed
  • pipeline_todos - TODO string in test_full.config: Specify the paths to your full test data ( on nf-core/test-datasets or directly in repositories, e.g. SRA)
  • pipeline_todos - TODO string in test_full.config: Give any required params for the test so that command line flags are not needed
  • pipeline_todos - TODO string in awsfulltest.yml: You can customise AWS full pipeline tests as required
  • schema_lint - Schema $id should be https://raw.githubusercontent.com/AlexsLemonade/metafactory/main/nextflow_schema.json or https://raw.githubusercontent.com/AlexsLemonade/metafactory/master/nextflow_schema.json.
    Found https://raw.githubusercontent.com/nf-core/metafactory/master/nextflow_schema.json

❔ Tests ignored:

✅ Tests passed:

Run details

  • nf-core/tools version 4.0.2
  • Run at 2026-09-02 21:26:58

@sjspielman sjspielman 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.

Looks good to me overall, just a few comments with one design suggestion to allow the adjusted p-value to be specified here.

Also a note that I used this script for reviewing: https://github.com/AlexsLemonade/ews-nf/blob/main/modules/metaprograms/resources/usr/bin/04-metaprogram-metrics.R (the links in the PR went to this notebook)


# run ORA using the top genes
ora_results <- mp_top_list |>
purrr::map(function(genes) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Probably we want \(x) {} syntax here

Suggested change
purrr::map(function(genes) {
purrr::map(\(genes) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Just a note that we can't do this with Nextflow templates. They complain about this syntax which is why we use function here.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fun!!

# combine ora results into a single dataframe
# only include genesets with pvalue < 0.05, the default by enricher
ora_results_df <- ora_results |>
purrr::map(function(ora) ora@result) |>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
purrr::map(function(ora) ora@result) |>
purrr::map(\(ora) ora@result) |>

Comment on lines +43 to +44
# returns a df with all gene sets for each metaprogram with p.adjust <= 0.05
run_ora <- function(mp_top_list, gene_universe, term2gene_df) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

A thought I just had...It might be good to make the adjusted p-value an argument to scripts in this module overall (and eventually, not now, a workflow parameter) in case someone wants to vary for the own usage this e.g. to 0.01

# keep the total number of genesets the same
shuffled_ora_results <- mp_geneset_counts[["geneset_count"]] |>
purrr::set_names(mp_geneset_counts[["metaprogram"]]) |>
purrr::map(function(count) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
purrr::map(function(count) {
purrr::map(\(count) {


# get the top X number of genes for each MP
mp_top_list <- mp_list |>
purrr::map(function(weights){

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
purrr::map(function(weights){
purrr::map(\(weights){

@allyhawkins

Copy link
Copy Markdown
Member Author

Okay this is now working correctly. I guess pixi doesn't like to build certain bioconductor packages so we have to just use the wave command directly rather than the script we have. I made a note of that in the environment.yml file for this module. I also replied to the other comments so this should be ready for another look.

@allyhawkins
allyhawkins merged commit c4d4ac8 into dev Sep 2, 2026
7 of 8 checks passed
@allyhawkins
allyhawkins deleted the allyhawkins/geneset-metrics branch September 2, 2026 22:13
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.

2 participants