From 25e128ea7489692eb6d33d1a28f456626b155ca7 Mon Sep 17 00:00:00 2001 From: Marcel Ribeiro Dantas Date: Sun, 25 Jun 2023 22:31:59 -0300 Subject: [PATCH 1/8] Update JSON section in basic training Update Groovy code by the new JSON channel operator https://github.com/nextflow-io/nextflow/commit/4f58f695b7c4087cac8854bcd702ea71c67c2d9c Signed-off-by: Marcel Ribeiro-Dantas --- docs/basic_training/channels.md | 39 +++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/docs/basic_training/channels.md b/docs/basic_training/channels.md index d03a3104..3efe24a4 100644 --- a/docs/basic_training/channels.md +++ b/docs/basic_training/channels.md @@ -601,23 +601,40 @@ Channel ### JSON -We can also easily parse the JSON file format using the following groovy schema: +We can also easily parse the JSON file format using the `splitJson` channel operator. +The `splitJson` operator supports JSON arrays: ```groovy linenums="1" -import groovy.json.JsonSlurper - -def f = file('data/meta/regions.json') -def records = new JsonSlurper().parse(f) - +Channel + .of('["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]') + .splitJson() + .view { "Item: ${it}" } +``` -for (def entry : records) { - log.info "$entry.patient_id -- $entry.feature" -} +JSON objects: +```groovy linenums="1" +Channel + .of('{"player": {"name": "Bob", "height": 180, "champion": false}}') + .splitJson() + .view { "Item: ${it}" } ``` -!!! warning +And even a JSON array of JSON objects! +```groovy linenums="1" +Channel + .of('[{"name": "Bob", "height": 180, "champion": false}, \ + {"name": "Alice", "height": 170, "champion": false}]') + .splitJson() + .view { "Item: ${it}" } +``` - When using an older JSON version, you may need to replace `parse(f)` with `parseText(f.text)` +Files containing JSON content can also be parsed: +```groovy linenums="1" +Channel + .fromPath('file.json') + .splitJson() + .view { "Item: ${it}" } +``` ### YAML From 5f57613dd68dfd3e6fbf920c89e120cb7de8a30f Mon Sep 17 00:00:00 2001 From: Marcel Ribeiro Dantas Date: Sun, 25 Jun 2023 22:35:47 -0300 Subject: [PATCH 2/8] Update translation of Channel section in basic training Update translation of JSON subsection Signed-off-by: Marcel Ribeiro-Dantas --- docs/basic_training/channels.pt.md | 39 +++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/docs/basic_training/channels.pt.md b/docs/basic_training/channels.pt.md index f7508f37..9aecf1ce 100644 --- a/docs/basic_training/channels.pt.md +++ b/docs/basic_training/channels.pt.md @@ -602,23 +602,40 @@ Channel ### JSON -Também podemos analisar facilmente o formato de arquivo JSON usando o seguinte esquema do Groovy: +Também podemos analisar facilmente o formato de arquivo JSON usando o oeprador de canal `splitJson`. +O operador `splitJson` suporta arranjos JSON: ```groovy linenums="1" -import groovy.json.JsonSlurper - -def f = file('data/meta/regions.json') -def registros = new JsonSlurper().parse(f) - +Channel + .of('["Domingo", "Segunda", "Terça", "Quarta", "Quinta", "Sexta", "Sábado"]') + .splitJson() + .view { "Item: ${it}" } +``` -for (def entrada : registros) { - log.info "$entrada.patient_id -- $entrada.feature" -} +Objetos JSON: +```groovy linenums="1" +Channel + .of('{"jogador": {"nome": "Bob", "altura": 180, "venceu_campeonato": false}}') + .splitJson() + .view { "Item: ${it}" } ``` -!!! warning +E inclusive arranjos JSON com objetos JSON! +```groovy linenums="1" +Channel + .of('[{"nome": "Bob", "altura": 180, "venceu_campeonato": false}, \ + {"nome": "Alice", "height": 170, "venceu_campeonato": false}]') + .splitJson() + .view { "Item: ${it}" } +``` - Ao usar uma versão JSON mais antiga, pode ser necessário substituir `parse(f)` por `parseText(f.text)` +Arquivos contendo dados em formato JSON também podem ser analisados: +```groovy linenums="1" +Channel + .fromPath('arquivo.json') + .splitJson() + .view { "Item: ${it}" } +``` ### YAML From f5d3e0c2202b035ff87720bbf5588df9a1b2f0db Mon Sep 17 00:00:00 2001 From: Marcel Ribeiro-Dantas Date: Tue, 27 Jun 2023 00:30:37 -0300 Subject: [PATCH 3/8] Add outputs as tabs Signed-off-by: Marcel Ribeiro-Dantas --- docs/basic_training/channels.md | 100 ++++++++++++++++++++++++-------- 1 file changed, 75 insertions(+), 25 deletions(-) diff --git a/docs/basic_training/channels.md b/docs/basic_training/channels.md index 3efe24a4..35971e27 100644 --- a/docs/basic_training/channels.md +++ b/docs/basic_training/channels.md @@ -604,37 +604,87 @@ Channel We can also easily parse the JSON file format using the `splitJson` channel operator. The `splitJson` operator supports JSON arrays: -```groovy linenums="1" -Channel - .of('["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]') - .splitJson() - .view { "Item: ${it}" } -``` + +=== "Source code" + + ```groovy linenums="1" + Channel + .of('["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]') + .splitJson() + .view { "Item: ${it}" } + ``` + +=== "Output" + + ```console + Item: Sunday + Item: Monday + Item: Tuesday + Item: Wednesday + Item: Thursday + Item: Friday + Item: Saturday + ``` JSON objects: -```groovy linenums="1" -Channel - .of('{"player": {"name": "Bob", "height": 180, "champion": false}}') - .splitJson() - .view { "Item: ${it}" } -``` + +=== "Source code" + + ```groovy linenums="1" + Channel + .of('{"player": {"name": "Bob", "height": 180, "champion": false}}') + .splitJson() + .view { "Item: ${it}" } + ``` + +=== "Output" + + ```console + Item: [key:player, value:[name:Bob, height:180, champion:false]] + ``` And even a JSON array of JSON objects! -```groovy linenums="1" -Channel - .of('[{"name": "Bob", "height": 180, "champion": false}, \ - {"name": "Alice", "height": 170, "champion": false}]') - .splitJson() - .view { "Item: ${it}" } -``` + +=== "Source code" + + ```groovy linenums="1" + Channel + .of('[{"name": "Bob", "height": 180, "champion": false}, \ + {"name": "Alice", "height": 170, "champion": false}]') + .splitJson() + .view { "Item: ${it}" } + ``` + +=== "Output" + + ```console + Item: [name:Bob, height:180, champion:false] + Item: [name:Alice, height:170, champion:false] + ``` Files containing JSON content can also be parsed: -```groovy linenums="1" -Channel - .fromPath('file.json') - .splitJson() - .view { "Item: ${it}" } -``` + +=== "Source code" + + ```groovy linenums="1" + Channel + .fromPath('file.json') + .splitJson() + .view { "Item: ${it}" } + ``` + +=== "file.json" + + ```json + [{"name": "Bob", "height": 180, "champion": false}, {"name": "Alice", "height": 170, "champion": false}] + ``` + +=== "Output" + + ```console + Item: [name:Bob, height:180, champion:false] + Item: [name:Alice, height:170, champion:false] + ``` ### YAML From 51244a6bbc832a775da83f62b31183711aa920a9 Mon Sep 17 00:00:00 2001 From: Marcel Ribeiro-Dantas Date: Tue, 27 Jun 2023 00:34:24 -0300 Subject: [PATCH 4/8] Enable content tabs Signed-off-by: Marcel Ribeiro-Dantas --- mkdocs.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mkdocs.yml b/mkdocs.yml index 9880649f..1afb833d 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -102,6 +102,8 @@ markdown_extensions: base_path: ["."] - pymdownx.snippets - pymdownx.superfences + - pymdownx.tabbed: + alternate_style: true - tables - toc: title: On this page From 13d426de87a7900325cf2d5da57a36f4336e4d1b Mon Sep 17 00:00:00 2001 From: Marcel Ribeiro-Dantas Date: Tue, 27 Jun 2023 00:46:28 -0300 Subject: [PATCH 5/8] Sync Portuguese translation of JSON subsection Signed-off-by: Marcel Ribeiro-Dantas --- docs/basic_training/channels.pt.md | 100 +++++++++++++++++++++-------- 1 file changed, 75 insertions(+), 25 deletions(-) diff --git a/docs/basic_training/channels.pt.md b/docs/basic_training/channels.pt.md index 9aecf1ce..2530cdfa 100644 --- a/docs/basic_training/channels.pt.md +++ b/docs/basic_training/channels.pt.md @@ -605,37 +605,87 @@ Channel Também podemos analisar facilmente o formato de arquivo JSON usando o oeprador de canal `splitJson`. O operador `splitJson` suporta arranjos JSON: -```groovy linenums="1" -Channel - .of('["Domingo", "Segunda", "Terça", "Quarta", "Quinta", "Sexta", "Sábado"]') - .splitJson() - .view { "Item: ${it}" } -``` + +=== "Source code" + + ```groovy linenums="1" + Channel + .of('["Domingo", "Segunda", "Terça", "Quarta", "Quinta", "Sexta", "Sábado"]') + .splitJson() + .view { "Item: ${it}" } + ``` + +=== "Output" + + ```console + Item: Domingo + Item: Segunda + Item: Terça + Item: Quarta + Item: Quinta + Item: Sexta + Item: Sábado + ``` Objetos JSON: -```groovy linenums="1" -Channel - .of('{"jogador": {"nome": "Bob", "altura": 180, "venceu_campeonato": false}}') - .splitJson() - .view { "Item: ${it}" } -``` + +=== "Source code" + + ```groovy linenums="1" + Channel + .of('{"jogador": {"nome": "Bob", "altura": 180, "venceu_campeonato": false}}') + .splitJson() + .view { "Item: ${it}" } + ``` + +=== "Output" + + ```console + Item: [key:jogador, value:[nome:Bob, altura:180, venceu_campeonato:false]] + ``` E inclusive arranjos JSON com objetos JSON! -```groovy linenums="1" -Channel - .of('[{"nome": "Bob", "altura": 180, "venceu_campeonato": false}, \ - {"nome": "Alice", "height": 170, "venceu_campeonato": false}]') - .splitJson() - .view { "Item: ${it}" } -``` + +=== "Source code" + + ```groovy linenums="1" + Channel + .of('[{"nome": "Bob", "altura": 180, "venceu_campeonato": false}, \ + {"nome": "Alice", "height": 170, "venceu_campeonato": false}]') + .splitJson() + .view { "Item: ${it}" } + ``` + +=== "Output" + + ```console + Item: [nome:Bob, altura:180, venceu_campeonato:false] + Item: [nome:Alice, altura:170, venceu_campeonato:false] + ``` Arquivos contendo dados em formato JSON também podem ser analisados: -```groovy linenums="1" -Channel - .fromPath('arquivo.json') - .splitJson() - .view { "Item: ${it}" } -``` + +=== "Source code" + + ```groovy linenums="1" + Channel + .fromPath('arquivo.json') + .splitJson() + .view { "Item: ${it}" } + ``` + +=== "arquivo.json" + + ```json + [{"nome": "Bob", "altura": 180, "venceu_campeonato": false}, {"nome": "Alice", "altura": 170, "venceu_campeonato": false}] + ``` + +=== "Output" + + ```console + Item: [nome:Bob, altura:180, venceu_campeonato:false] + Item: [nome:Alice, altura:170, venceu_campeonato:false] + ``` ### YAML From 14eacba721428bee409443703e57c20c87e2cdec Mon Sep 17 00:00:00 2001 From: Marcel Ribeiro-Dantas Date: Tue, 27 Jun 2023 00:47:03 -0300 Subject: [PATCH 6/8] Prettify channels.md 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 35971e27..f9e6dd2c 100644 --- a/docs/basic_training/channels.md +++ b/docs/basic_training/channels.md @@ -683,7 +683,7 @@ Files containing JSON content can also be parsed: ```console Item: [name:Bob, height:180, champion:false] - Item: [name:Alice, height:170, champion:false] + Item: [name:Alice, height:170, champion:false] ``` ### YAML From 1e616ec51c9f313ce6ba926cab4bf40de3d43542 Mon Sep 17 00:00:00 2001 From: Marcel Ribeiro-Dantas Date: Tue, 27 Jun 2023 00:52:02 -0300 Subject: [PATCH 7/8] Translate tab titles to Portuguese in JSON subsection Signed-off-by: Marcel Ribeiro-Dantas --- docs/basic_training/channels.pt.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/basic_training/channels.pt.md b/docs/basic_training/channels.pt.md index 2530cdfa..d5ca017d 100644 --- a/docs/basic_training/channels.pt.md +++ b/docs/basic_training/channels.pt.md @@ -606,7 +606,7 @@ Também podemos analisar facilmente o formato de arquivo JSON usando o oeprador O operador `splitJson` suporta arranjos JSON: -=== "Source code" +=== "Código-fonte" ```groovy linenums="1" Channel @@ -615,7 +615,7 @@ O operador `splitJson` suporta arranjos JSON: .view { "Item: ${it}" } ``` -=== "Output" +=== "Saída" ```console Item: Domingo @@ -629,7 +629,7 @@ O operador `splitJson` suporta arranjos JSON: Objetos JSON: -=== "Source code" +=== "Código-fonte" ```groovy linenums="1" Channel @@ -638,7 +638,7 @@ Objetos JSON: .view { "Item: ${it}" } ``` -=== "Output" +=== "Saída" ```console Item: [key:jogador, value:[nome:Bob, altura:180, venceu_campeonato:false]] @@ -646,7 +646,7 @@ Objetos JSON: E inclusive arranjos JSON com objetos JSON! -=== "Source code" +=== "Código-fonte" ```groovy linenums="1" Channel @@ -656,7 +656,7 @@ E inclusive arranjos JSON com objetos JSON! .view { "Item: ${it}" } ``` -=== "Output" +=== "Saída" ```console Item: [nome:Bob, altura:180, venceu_campeonato:false] @@ -665,7 +665,7 @@ E inclusive arranjos JSON com objetos JSON! Arquivos contendo dados em formato JSON também podem ser analisados: -=== "Source code" +=== "Código-fonte" ```groovy linenums="1" Channel @@ -680,7 +680,7 @@ Arquivos contendo dados em formato JSON também podem ser analisados: [{"nome": "Bob", "altura": 180, "venceu_campeonato": false}, {"nome": "Alice", "altura": 170, "venceu_campeonato": false}] ``` -=== "Output" +=== "Saída" ```console Item: [nome:Bob, altura:180, venceu_campeonato:false] From 94e99644b1a5d201b723c107ce082ddbdca43468 Mon Sep 17 00:00:00 2001 From: Marcel Ribeiro-Dantas Date: Tue, 27 Jun 2023 09:59:26 -0300 Subject: [PATCH 8/8] Update docs/basic_training/channels.md Co-authored-by: Phil Ewels --- docs/basic_training/channels.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/basic_training/channels.md b/docs/basic_training/channels.md index f9e6dd2c..a61072d2 100644 --- a/docs/basic_training/channels.md +++ b/docs/basic_training/channels.md @@ -676,7 +676,10 @@ Files containing JSON content can also be parsed: === "file.json" ```json - [{"name": "Bob", "height": 180, "champion": false}, {"name": "Alice", "height": 170, "champion": false}] + [ + { "name": "Bob", "height": 180, "champion": false }, + { "name": "Alice", "height": 170, "champion": false } + ] ``` === "Output"