Skip to content

Commit

Permalink
add subworfklow + schema for references (#7412)
Browse files Browse the repository at this point in the history
* add subworfklow + schema for references

* s3 -> https

* no function tests

* better function name

* restore fake workflow for tests

* add DISCLAIMER

* better tests

* use format: path
  • Loading branch information
maxulysse authored Feb 6, 2025
1 parent 5cf15e4 commit c18de39
Show file tree
Hide file tree
Showing 6 changed files with 535 additions and 0 deletions.
13 changes: 13 additions & 0 deletions subworkflows/nf-core/utils_references/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Disclaimer

This `utils_references/` folder contains for now two functions and a schema.
This is really meant for a POC and should not be installed by anyone except @maxulysse.
But that was the easiest way to share functions and a schema between three different pipelines and still showcase the logic.
This might evolve in the future, possibly towards a proper plugin.

If you do so, please be aware that:

- @maxulysse has hacked the `main.nf` to test the functions and the schema
- This is really meant to evolve in the future and can be deleted at any moment without prior notice.

That being said, if you still want to use it or want to know more about it, please check the `#references` channel on the nf-core slack.
60 changes: 60 additions & 0 deletions subworkflows/nf-core/utils_references/main.nf
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// DISCLAIMER:
// This subworkflow is just to test the functions and the schema
// It should not be used in any pipeline

// This include statement can also be deleted
include { samplesheetToList } from 'plugin/nf-schema'

workflow UTILS_REFERENCES {
take:
yaml_reference
param_file
param_value
attribute_file
attribute_value
basepath

main:
references = Channel.fromList(samplesheetToList(yaml_reference, "${projectDir}/subworkflows/nf-core/utils_references/schema_references.json"))

// GIVING up writing a test for the functions, so writing a subworkflow to test it
references_file = get_references_file(references, param_file, attribute_file, basepath)
references_value = get_references_value(references, param_value, attribute_value)

emit:
references_file
references_value
}
// You can delete everything before this line (including this line)

/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
FUNCTIONS TO EXTRACT REFERENCES FILES OR VALUES FROM THE REFERENCES YAML OR PARAMS
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/

def get_references_file(references, param, attribute, basepath) {
return references
.map { meta, _readme ->
if (param || meta[attribute]) {
[meta.subMap(['id']), file(param ?: meta[attribute].replace('${params.igenomes_base}', basepath), checkIfExists: true)]
}
else {
null
}
}
.collect()
}

def get_references_value(references, param, attribute) {
return references
.map { meta, _readme ->
if (param || meta[attribute]) {
[meta.subMap(['id']), param ?: meta[attribute]]
}
else {
null
}
}
.collect()
}
14 changes: 14 additions & 0 deletions subworkflows/nf-core/utils_references/meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/nf-core/modules/master/subworkflows/yaml-schema.json
name: "utils_references"
description: Functionality for dealing with references that may be useful for any Nextflow pipeline
keywords:
- utility
- pipeline
- references
components: []
input: []
output: []
authors:
- "@maxulysse"
maintainers:
- "@maxulysse"
Loading

0 comments on commit c18de39

Please sign in to comment.