From e853641be420da3a84cb5eff7f2cd122297d4bbb Mon Sep 17 00:00:00 2001 From: Marcel Ribeiro-Dantas Date: Tue, 27 Jun 2023 22:55:09 -0300 Subject: [PATCH 1/5] Add tabs for source code/console/files in YAML subsection Signed-off-by: Marcel Ribeiro-Dantas --- docs/basic_training/channels.md | 178 +++++++++++++++++++++++++------- 1 file changed, 138 insertions(+), 40 deletions(-) diff --git a/docs/basic_training/channels.md b/docs/basic_training/channels.md index a61072d2..0e3522dd 100644 --- a/docs/basic_training/channels.md +++ b/docs/basic_training/channels.md @@ -693,64 +693,162 @@ Files containing JSON content can also be parsed: This can also be used as a way to parse YAML files: -```groovy linenums="1" -import org.yaml.snakeyaml.Yaml +=== "Source code" + + ```groovy linenums="1" + import org.yaml.snakeyaml.Yaml -def f = file('data/meta/regions.yml') -def records = new Yaml().load(f) + def f = file('data/meta/regions.yml') + def records = new Yaml().load(f) -for (def entry : records) { - log.info "$entry.patient_id -- $entry.feature" -} + for (def entry : records) { + log.info "$entry.patient_id -- $entry.feature" + } ``` +=== "data/meta/regions.yml" + + ```yml + - patient_id: ATX-TBL-001-GB-01-105 + region_id: R1 + feature: pass_vafqc_flag + pass_flag: "TRUE" + - patient_id: ATX-TBL-001-GB-01-105 + region_id: R1 + feature: pass_stripy_flag + pass_flag: "TRUE" + - patient_id: ATX-TBL-001-GB-01-105 + region_id: R1 + feature: pass_manual_flag + pass_flag: "TRUE" + - patient_id: ATX-TBL-001-GB-01-105 + region_id: R1 + feature: other_region_selection_flag + pass_flag: "TRUE" + - patient_id: ATX-TBL-001-GB-01-105 + region_id: R1 + feature: ace_information_gained + pass_flag: "TRUE" + - patient_id: ATX-TBL-001-GB-01-105 + region_id: R1 + feature: concordance_flag + pass_flag: "TRUE" + - patient_id: ATX-TBL-001-GB-01-105 + region_id: R2 + feature: pass_vafqc_flag + pass_flag: "TRUE" + - patient_id: ATX-TBL-001-GB-01-105 + region_id: R2 + feature: pass_stripy_flag + pass_flag: "TRUE" + - patient_id: ATX-TBL-001-GB-01-105 + region_id: R2 + feature: pass_manual_flag + pass_flag: "TRUE" + - patient_id: ATX-TBL-001-GB-01-105 + region_id: R2 + feature: other_region_selection_flag + pass_flag: "TRUE" + - patient_id: ATX-TBL-001-GB-01-105 + region_id: R2 + feature: ace_information_gained + pass_flag: "TRUE" + - patient_id: ATX-TBL-001-GB-01-105 + region_id: R2 + feature: concordance_flag + pass_flag: "TRUE" + - patient_id: ATX-TBL-001-GB-01-105 + region_id: R3 + feature: pass_vafqc_flag + pass_flag: "TRUE" + - patient_id: ATX-TBL-001-GB-01-105 + region_id: R3 + feature: pass_stripy_flag + pass_flag: "FALSE" + ``` + +=== "Output" + + ```console + ATX-TBL-001-GB-01-105 -- pass_vafqc_flag + ATX-TBL-001-GB-01-105 -- pass_stripy_flag + ATX-TBL-001-GB-01-105 -- pass_manual_flag + ATX-TBL-001-GB-01-105 -- other_region_selection_flag + ATX-TBL-001-GB-01-105 -- ace_information_gained + ATX-TBL-001-GB-01-105 -- concordance_flag + ATX-TBL-001-GB-01-105 -- pass_vafqc_flag + ATX-TBL-001-GB-01-105 -- pass_stripy_flag + ATX-TBL-001-GB-01-105 -- pass_manual_flag + ATX-TBL-001-GB-01-105 -- other_region_selection_flag + ATX-TBL-001-GB-01-105 -- ace_information_gained + ATX-TBL-001-GB-01-105 -- concordance_flag + ATX-TBL-001-GB-01-105 -- pass_vafqc_flag + ATX-TBL-001-GB-01-105 -- pass_stripy_flag + ``` + ### Storage of parsers into modules The best way to store parser scripts is to keep them in a Nextflow module file. -See the following Nextflow script: +Let's say we don't have a JSON channel operator, but we create a function instead. The `parsers.nf` file should contain the `parseJsonFile` function. See the contente below: -```groovy linenums="1" -include { parseJsonFile } from './modules/parsers.nf' +=== "Source code" -process FOO { - input: - tuple val(patient_id), val(feature) + ```groovy linenums="1" + include { parseJsonFile } from './modules/parsers.nf' - output: - stdout + process FOO { + input: + tuple val(patient_id), val(feature) - script: - """ - echo $patient_id has $feature as feature - """ -} + output: + stdout -workflow { - Channel - .fromPath('data/meta/regions*.json') - | flatMap { parseJsonFile(it) } - | map { record -> [record.patient_id, record.feature] } - | unique - | FOO - | view -} -``` + script: + """ + echo $patient_id has $feature as feature + """ + } -For this script to work, a module file called `parsers.nf` needs to be created and stored in a modules folder in the current directory. + workflow { + Channel + .fromPath('data/meta/regions*.json') + | flatMap { parseJsonFile(it) } + | map { record -> [record.patient_id, record.feature] } + | unique + | FOO + | view + } + ``` -The `parsers.nf` file should contain the `parseJsonFile` function. For example: +=== "./modules/parsers.nf" -```groovy linenums="1" -import groovy.json.JsonSlurper + ```groovy linenums="1" + import groovy.json.JsonSlurper -def parseJsonFile(json_file) { - def f = file('data/meta/regions.json') - def records = new JsonSlurper().parse(f) - return records -} -``` + def parseJsonFile(json_file) { + def f = file(json_file) + def records = new JsonSlurper().parse(f) + return records + } + ``` + +=== "Output" + + ```console + ATX-TBL-001-GB-01-105 has pass_stripy_flag as feature + + ATX-TBL-001-GB-01-105 has ace_information_gained as feature + + ATX-TBL-001-GB-01-105 has concordance_flag as feature + + ATX-TBL-001-GB-01-105 has pass_vafqc_flag as feature + + ATX-TBL-001-GB-01-105 has pass_manual_flag as feature + + ATX-TBL-001-GB-01-105 has other_region_selection_flag as feature + ``` Nextflow will use this as a custom function within the workflow scope. From 2748f753897757311257235d7cc95077b32a4f98 Mon Sep 17 00:00:00 2001 From: Marcel Ribeiro-Dantas Date: Tue, 27 Jun 2023 23:04:48 -0300 Subject: [PATCH 2/5] Prettify --- docs/basic_training/channels.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/basic_training/channels.md b/docs/basic_training/channels.md index 0e3522dd..8d462aa8 100644 --- a/docs/basic_training/channels.md +++ b/docs/basic_training/channels.md @@ -705,7 +705,7 @@ This can also be used as a way to parse YAML files: for (def entry : records) { log.info "$entry.patient_id -- $entry.feature" } -``` + ``` === "data/meta/regions.yml" From 1d865a0133ca6550d14e9e7f94e14a4add65375c Mon Sep 17 00:00:00 2001 From: Marcel Ribeiro-Dantas Date: Wed, 28 Jun 2023 08:54:04 -0300 Subject: [PATCH 3/5] Update docs/basic_training/channels.md Co-authored-by: Phil Ewels --- docs/basic_training/channels.md | 57 +-------------------------------- 1 file changed, 1 insertion(+), 56 deletions(-) diff --git a/docs/basic_training/channels.md b/docs/basic_training/channels.md index 8d462aa8..eb047126 100644 --- a/docs/basic_training/channels.md +++ b/docs/basic_training/channels.md @@ -710,62 +710,7 @@ This can also be used as a way to parse YAML files: === "data/meta/regions.yml" ```yml - - patient_id: ATX-TBL-001-GB-01-105 - region_id: R1 - feature: pass_vafqc_flag - pass_flag: "TRUE" - - patient_id: ATX-TBL-001-GB-01-105 - region_id: R1 - feature: pass_stripy_flag - pass_flag: "TRUE" - - patient_id: ATX-TBL-001-GB-01-105 - region_id: R1 - feature: pass_manual_flag - pass_flag: "TRUE" - - patient_id: ATX-TBL-001-GB-01-105 - region_id: R1 - feature: other_region_selection_flag - pass_flag: "TRUE" - - patient_id: ATX-TBL-001-GB-01-105 - region_id: R1 - feature: ace_information_gained - pass_flag: "TRUE" - - patient_id: ATX-TBL-001-GB-01-105 - region_id: R1 - feature: concordance_flag - pass_flag: "TRUE" - - patient_id: ATX-TBL-001-GB-01-105 - region_id: R2 - feature: pass_vafqc_flag - pass_flag: "TRUE" - - patient_id: ATX-TBL-001-GB-01-105 - region_id: R2 - feature: pass_stripy_flag - pass_flag: "TRUE" - - patient_id: ATX-TBL-001-GB-01-105 - region_id: R2 - feature: pass_manual_flag - pass_flag: "TRUE" - - patient_id: ATX-TBL-001-GB-01-105 - region_id: R2 - feature: other_region_selection_flag - pass_flag: "TRUE" - - patient_id: ATX-TBL-001-GB-01-105 - region_id: R2 - feature: ace_information_gained - pass_flag: "TRUE" - - patient_id: ATX-TBL-001-GB-01-105 - region_id: R2 - feature: concordance_flag - pass_flag: "TRUE" - - patient_id: ATX-TBL-001-GB-01-105 - region_id: R3 - feature: pass_vafqc_flag - pass_flag: "TRUE" - - patient_id: ATX-TBL-001-GB-01-105 - region_id: R3 - feature: pass_stripy_flag - pass_flag: "FALSE" + --8<-- "../../nf-training/data/meta/regions.yml" ``` === "Output" From 595769091f994aa141e4c904f341377496e29162 Mon Sep 17 00:00:00 2001 From: Marcel Ribeiro-Dantas Date: Wed, 28 Jun 2023 08:54:44 -0300 Subject: [PATCH 4/5] Update docs/basic_training/channels.md Co-authored-by: Phil Ewels --- docs/basic_training/channels.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/basic_training/channels.md b/docs/basic_training/channels.md index eb047126..cecf2fa7 100644 --- a/docs/basic_training/channels.md +++ b/docs/basic_training/channels.md @@ -709,7 +709,7 @@ This can also be used as a way to parse YAML files: === "data/meta/regions.yml" - ```yml + ```yaml --8<-- "../../nf-training/data/meta/regions.yml" ``` From d9a9473cb3daa90a00375536fcb2b86b394a2e0d Mon Sep 17 00:00:00 2001 From: Marcel Ribeiro-Dantas Date: Wed, 28 Jun 2023 12:35:13 -0300 Subject: [PATCH 5/5] Fix path to file in YAML subsection Signed-off-by: Marcel Ribeiro-Dantas --- docs/basic_training/channels.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/basic_training/channels.md b/docs/basic_training/channels.md index cecf2fa7..38bbb3ac 100644 --- a/docs/basic_training/channels.md +++ b/docs/basic_training/channels.md @@ -710,7 +710,7 @@ This can also be used as a way to parse YAML files: === "data/meta/regions.yml" ```yaml - --8<-- "../../nf-training/data/meta/regions.yml" + --8<-- "nf-training/data/meta/regions.yml" ``` === "Output"