Skip to content

Commit b6d2cae

Browse files
authored
Merge pull request #147 from icgc-argo-workflows/json-parser@0.1.0
[release]
2 parents 5cef925 + f502301 commit b6d2cae

15 files changed

Lines changed: 235 additions & 1 deletion

json-parser/.dockerignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.gitignore
2+
.nextflow*
3+
tests
4+
work
5+
outdir

json-parser/Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM python:3.7.5-slim-buster
2+
3+
LABEL org.opencontainers.image.source https://github.com/icgc-argo-workflows/data-processing-utility-tools
4+
5+
RUN apt-get update && apt-get install -y procps jq
6+
7+
ENV PATH="/tools:${PATH}"
8+
9+
WORKDIR /tools
10+
11+
COPY . .

json-parser/main.nf

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/usr/bin/env nextflow
2+
3+
/*
4+
Copyright (C) 2021, Ontario Institute for Cancer Research
5+
6+
This program is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU Affero General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
11+
This program is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU Affero General Public License for more details.
15+
16+
You should have received a copy of the GNU Affero General Public License
17+
along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
19+
Authors:
20+
Linda Xiang
21+
*/
22+
23+
/********************************************************************/
24+
/* this block is auto-generated based on info from pkg.json where */
25+
/* changes can be made if needed, do NOT modify this block manually */
26+
nextflow.enable.dsl = 2
27+
version = '0.1.0' // package version
28+
29+
container = [
30+
'ghcr.io': 'ghcr.io/icgc-argo-workflows/data-processing-utility-tools.json-parser'
31+
]
32+
default_container_registry = 'ghcr.io'
33+
/********************************************************************/
34+
35+
36+
// universal params go here
37+
params.container_registry = ""
38+
params.container_version = ""
39+
params.container = ""
40+
41+
params.cpus = 1
42+
params.mem = 1 // GB
43+
params.publish_dir = "" // set to empty string will disable publishDir
44+
45+
46+
// tool specific parmas go here, add / change as needed
47+
params.metadata_analysis = ""
48+
49+
50+
process jsonParser {
51+
container "${params.container ?: container[params.container_registry ?: default_container_registry]}:${params.container_version ?: version}"
52+
publishDir "${params.publish_dir}/${task.process.replaceAll(':', '_')}", mode: "copy", enabled: params.publish_dir
53+
54+
cpus params.cpus
55+
memory "${params.mem} GB"
56+
57+
input:
58+
path metadata_analysis
59+
60+
output:
61+
env STUDY_ID, emit: study_id
62+
env DONOR_ID, emit: donor_id
63+
env EXP, emit: experimental_strategy
64+
env PAIRED, emit: paired
65+
env ANALYSIS_TOOLS, emit: analysis_tools
66+
env STRAND, emit: library_strandedness
67+
68+
script:
69+
"""
70+
set -euxo pipefail
71+
VARIABLE1=`cat ${metadata_analysis} | jq -r 'if ([.read_groups[]?] | length) >0 then [.read_groups[] | .is_paired_end] | all | tostring else "NULL" end' | tr -d '\\n'`
72+
PAIRED=\${VARIABLE1:-'NULL'}
73+
VARIABLE2=`cat ${metadata_analysis} | jq -r '[.files[] | .info? | .analysis_tools[]?] | unique | join(",")' | tr -d '\\n'`
74+
ANALYSIS_TOOLS=\${VARIABLE2:-'NULL'}
75+
VARIABLE3=`cat ${metadata_analysis} | jq -r 'if (.experiment | .library_strandedness?) then .experiment|.library_strandedness else "NULL" end' | tr -d '\\n'`
76+
STRAND=\${VARIABLE3:-'NULL'}
77+
STUDY_ID=`cat ${metadata_analysis} | jq -er '.studyId' | tr -d '\\n'`
78+
DONOR_ID=`cat ${metadata_analysis} | jq -er '.samples[0].donor.donorId' | tr -d '\\n'`
79+
EXP=`cat ${metadata_analysis} | jq -er '.experiment | .experimental_strategy? // .library_strategy' | tr -d '\\n'`
80+
"""
81+
}
82+
83+
84+
// this provides an entry point for this main script, so it can be run directly without clone the repo
85+
// using this command: nextflow run <git_acc>/<repo>/<pkg_name>/<main_script>.nf -r <pkg_name>.v<pkg_version> --params-file xxx
86+
workflow {
87+
jsonParser(
88+
file(params.metadata_analysis)
89+
)
90+
}

json-parser/nextflow.config

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
docker {
2+
enabled = true
3+
runOptions = '-u \$(id -u):\$(id -g)'
4+
}

json-parser/pkg.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "json-parser",
3+
"version": "0.1.0",
4+
"description": "tool to parse JSON metadata",
5+
"main": "main.nf",
6+
"deprecated": false,
7+
"keywords": [
8+
"metadata",
9+
"JSON"
10+
],
11+
"repository": {
12+
"type": "git",
13+
"url": "https://github.com/icgc-argo-workflows/data-processing-utility-tools.git"
14+
},
15+
"container": {
16+
"registries": [
17+
{
18+
"registry": "ghcr.io",
19+
"type": "docker",
20+
"org": "icgc-argo-workflows",
21+
"default": true
22+
}
23+
]
24+
},
25+
"dependencies": [],
26+
"devDependencies": [],
27+
"contributors": [
28+
{
29+
"name": "Linda Xiang",
30+
"email": "linda.xiang@oicr.on.ca"
31+
}
32+
],
33+
"license": "GNU Affero General Public License v3",
34+
"bugReport": "https://github.com/icgc-argo-workflows/data-processing-utility-tools/issues",
35+
"homepage": "https://github.com/icgc-argo-workflows/data-processing-utility-tools#readme"
36+
}

json-parser/tests/checker.nf

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/env nextflow
2+
3+
/*
4+
Copyright (C) 2021, Ontario Institute for Cancer Research
5+
6+
This program is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU Affero General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
11+
This program is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU Affero General Public License for more details.
15+
16+
You should have received a copy of the GNU Affero General Public License
17+
along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
19+
Authors:
20+
Linda Xiang
21+
*/
22+
23+
/*
24+
This is an auto-generated checker workflow to test the generated main template workflow, it's
25+
meant to illustrate how testing works. Please update to suit your own needs.
26+
*/
27+
28+
/********************************************************************/
29+
/* this block is auto-generated based on info from pkg.json where */
30+
/* changes can be made if needed, do NOT modify this block manually */
31+
nextflow.enable.dsl = 2
32+
version = '0.1.0' // package version
33+
34+
container = [
35+
'ghcr.io': 'ghcr.io/icgc-argo-workflows/data-processing-utility-tools.json-parser'
36+
]
37+
default_container_registry = 'ghcr.io'
38+
/********************************************************************/
39+
40+
// universal params
41+
params.container_registry = ""
42+
params.container_version = ""
43+
params.container = ""
44+
45+
// tool specific parmas go here, add / change as needed
46+
params.metadata_analysis = ""
47+
params.expected_output = ""
48+
49+
include { jsonParser } from '../main'
50+
51+
workflow checker {
52+
take:
53+
metadata_analysis
54+
55+
main:
56+
jsonParser(
57+
metadata_analysis
58+
)
59+
jsonParser.out.study_id.set{study_id}
60+
study_id.view()
61+
jsonParser.out.donor_id.view()
62+
jsonParser.out.experimental_strategy.view()
63+
jsonParser.out.analysis_tools.view()
64+
jsonParser.out.paired.view()
65+
jsonParser.out.library_strandedness.view()
66+
}
67+
68+
69+
workflow {
70+
checker(
71+
file(params.metadata_analysis)
72+
)
73+
}

json-parser/tests/data

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../tests/data
14.6 KB
Binary file not shown.
148 KB
Binary file not shown.

json-parser/tests/nextflow.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
includeConfig '../nextflow.config'

0 commit comments

Comments
 (0)