nf-core / tools

Python package with helper tools for the nf-core community.
https://nf-co.re
MIT License
244 stars 192 forks source link

Remove `import` statements from pipeline template #3165

Closed ewels closed 2 months ago

ewels commented 2 months ago

We should not use Groovy import statements in Nextflow files:

https://github.com/nf-core/tools/blob/930ece572bf23b68c7a7c5259e918a878ba6499e/nf_core/pipeline-template/subworkflows/nf-core/utils_nextflow_pipeline/main.nf#L5-L7

https://github.com/nf-core/tools/blob/930ece572bf23b68c7a7c5259e918a878ba6499e/nf_core/pipeline-template/subworkflows/nf-core/utils_nfcore_pipeline/main.nf#L5-L6

Instead, use fully qualified names. So instead of:

https://github.com/nf-core/tools/blob/930ece572bf23b68c7a7c5259e918a878ba6499e/nf_core/pipeline-template/subworkflows/nf-core/utils_nextflow_pipeline/main.nf#L93

Do this:

    Yaml parser = new org.yaml.snakeyaml.Yaml()

These are subworkflows, so need changing upstream. But adding the issue here because we need to make sure that the updated modules are pulled back into the template.

ewels commented 2 months ago

Related - these additional fixes are also needed to get ahead of upcoming Nextflow syntax changes:

diff --git a/subworkflows/local/utils_nfcore_test_pipeline/main.nf b/subworkflows/local/utils_nfcore_test_pipeline/main.nf
index 12c3177..ad046d5 100644
--- a/subworkflows/local/utils_nfcore_test_pipeline/main.nf
+++ b/subworkflows/local/utils_nfcore_test_pipeline/main.nf
@@ -84,8 +84,8 @@ workflow PIPELINE_INITIALISATION {
                 }
         }
         .groupTuple()
-        .map {
-            validateInputSamplesheet(it)
+        .map {samplesheet ->
+            validateInputSamplesheet(samplesheet)
         }
         .map {
             meta, fastqs ->
@@ -165,7 +165,7 @@ def validateInputSamplesheet(input) {
     def (metas, fastqs) = input[1..2]

     // Check that multiple runs of the same sample are of the same datatype i.e. single-end / paired-end
-    def endedness_ok = metas.collect{ it.single_end }.unique().size == 1
+    def endedness_ok = metas.collect{meta -> meta.single_end }.unique().size == 1
     if (!endedness_ok) {
         error("Please check input samplesheet -> Multiple runs of a sample must be of the same datatype i.e. single-end or paired-end: ${metas[0].id}")
     }
@@ -238,8 +238,10 @@ def methodsDescriptionText(mqc_methods_yaml) {
         // Removing `https://doi.org/` to handle pipelines using DOIs vs DOI resolvers
         // Removing ` ` since the manifest.doi is a string and not a proper list
         def temp_doi_ref = ""
-        String[] manifest_doi = meta.manifest_map.doi.tokenize(",")
-        for (String doi_ref: manifest_doi) temp_doi_ref += "(doi: <a href=\'https://doi.org/${doi_ref.replace("https://doi.org/", "").replace(" ", "")}\'>${doi_ref.replace("https://doi.org/", "").replace(" ", "")}</a>), "
+        def manifest_doi = meta.manifest_map.doi.tokenize(",")
+        manifest_doi.each { doi_ref ->
+            temp_doi_ref += "(doi: <a href=\'https://doi.org/${doi_ref.replace("https://doi.org/", "").replace(" ", "")}\'>${doi_ref.replace("https://doi.org/", "").replace(" ", "")}</a>), "
+        }
         meta["doi_text"] = temp_doi_ref.substring(0, temp_doi_ref.length() - 2)
     } else meta["doi_text"] = ""
     meta["nodoi_text"] = meta.manifest_map.doi ? "" : "<li>If available, make sure to update the text to include the Zenodo DOI of version of the pipeline used. </li>"