From 854de8fcbf9dbd895e31a6fb6277aa112cf41d01 Mon Sep 17 00:00:00 2001 From: lyh970817 Date: Fri, 20 Mar 2026 23:12:12 +0800 Subject: [PATCH 1/4] feat: add gcta/bivariatereml module --- .../gcta/bivariatereml/environment.yml | 7 + modules/nf-core/gcta/bivariatereml/main.nf | 50 ++++++ modules/nf-core/gcta/bivariatereml/meta.yml | 118 ++++++++++++++ .../gcta/bivariatereml/tests/main.nf.test | 147 ++++++++++++++++++ .../bivariatereml/tests/main.nf.test.snap | 85 ++++++++++ .../gcta/bivariatereml/tests/nextflow.config | 3 + 6 files changed, 410 insertions(+) create mode 100644 modules/nf-core/gcta/bivariatereml/environment.yml create mode 100644 modules/nf-core/gcta/bivariatereml/main.nf create mode 100644 modules/nf-core/gcta/bivariatereml/meta.yml create mode 100644 modules/nf-core/gcta/bivariatereml/tests/main.nf.test create mode 100644 modules/nf-core/gcta/bivariatereml/tests/main.nf.test.snap create mode 100644 modules/nf-core/gcta/bivariatereml/tests/nextflow.config diff --git a/modules/nf-core/gcta/bivariatereml/environment.yml b/modules/nf-core/gcta/bivariatereml/environment.yml new file mode 100644 index 000000000000..3e22ea7b9f20 --- /dev/null +++ b/modules/nf-core/gcta/bivariatereml/environment.yml @@ -0,0 +1,7 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/nf-core/modules/master/modules/environment-schema.json +channels: + - conda-forge + - bioconda +dependencies: + - bioconda::gcta=1.94.1 diff --git a/modules/nf-core/gcta/bivariatereml/main.nf b/modules/nf-core/gcta/bivariatereml/main.nf new file mode 100644 index 000000000000..0065f0ea3585 --- /dev/null +++ b/modules/nf-core/gcta/bivariatereml/main.nf @@ -0,0 +1,50 @@ +process GCTA_BIVARIATEREML { + tag "bivariate_reml_${meta.id}_${meta2.id}" + label 'process_medium' + conda "${moduleDir}/environment.yml" + container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ? + 'docker://community.wave.seqera.io/library/gcta:1.94.1--9bc35dc424fcf6e9' : + 'community.wave.seqera.io/library/gcta:1.94.1--9bc35dc424fcf6e9' }" + + input: + tuple val(meta), path(phenotype_file) + tuple val(meta2), path(grm_id), path(grm_bin), path(grm_n_bin) + tuple val(meta3), path(quant_covariates_file) + tuple val(meta4), path(cat_covariates_file) + + output: + tuple val(meta), path("*.hsq"), emit: bivariate_results + tuple val(meta), path("*.log"), emit: log_file + tuple val("${task.process}"), val("gcta"), eval("gcta --version 2>&1 | grep 'version v' | tr -s ' ' | cut -d' ' -f3 | sed 's/^v//'"), emit: versions_gcta, topic: versions + + when: + task.ext.when == null || task.ext.when + + script: + def prefix = task.ext.prefix ?: "${meta.id}" + def pair_id = prefix + def qcovar_param = quant_covariates_file ? "--qcovar ${quant_covariates_file}" : '' + def covar_param = cat_covariates_file ? "--covar ${cat_covariates_file}" : '' + def extra_args = task.ext.args ?: '' + + """ + set -euo pipefail + + gcta \\ + --reml-bivar 1 2 \\ + --grm ${meta2.id} \\ + --pheno "${phenotype_file}" \\ + ${qcovar_param} \\ + ${covar_param} \\ + --out "${pair_id}" \\ + --thread-num ${task.cpus} ${extra_args} + """ + + stub: + def prefix = task.ext.prefix ?: "${meta.id}" + def pair_id = prefix + """ + touch "${pair_id}.hsq" + touch "${pair_id}.log" + """ +} diff --git a/modules/nf-core/gcta/bivariatereml/meta.yml b/modules/nf-core/gcta/bivariatereml/meta.yml new file mode 100644 index 000000000000..493ed7d6196b --- /dev/null +++ b/modules/nf-core/gcta/bivariatereml/meta.yml @@ -0,0 +1,118 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/nf-core/modules/master/modules/meta-schema.json +name: "gcta_bivariatereml" +description: Run bivariate REML analysis with a single dense GRM +keywords: + - gcta + - reml + - bivariate + - genetics +tools: + - "gcta": + description: "Genome-wide Complex Trait Analysis (GCTA) estimates genetic relationships, variance components, and association statistics from genome-wide data." + homepage: "https://yanglab.westlake.edu.cn/software/gcta/" + documentation: "https://yanglab.westlake.edu.cn/software/gcta/static/gcta_doc_latest.pdf" + tool_dev_url: "https://yanglab.westlake.edu.cn/software/gcta/" +input: + - - meta: + type: map + description: | + Groovy map containing shared bivariate phenotype metadata + `meta.id` must contain both trait names, for example `trait1__trait2` + - phenotype_file: + type: file + description: Shared bivariate phenotype file passed to `--pheno` + pattern: "*.{phe,pheno,txt,tsv}" + ontologies: + - edam: "http://edamontology.org/format_3475" + - - meta2: + type: map + description: | + Groovy map containing dense GRM metadata + e.g. `[ id:'plink_simulated' ]` + - grm_id: + type: file + description: Dense GRM sample identifier file + pattern: "*.grm.id" + ontologies: [] + - grm_bin: + type: file + description: Dense GRM binary matrix file + pattern: "*.grm.bin" + ontologies: [] + - grm_n_bin: + type: file + description: Dense GRM sample-count matrix file + pattern: "*.grm.N.bin" + ontologies: [] + - - meta3: + type: map + description: | + Groovy map containing quantitative covariate metadata + e.g. `[ id:'covariates_quant' ]` + - quant_covariates_file: + type: file + description: Quantitative covariates file, pass `[]` when absent + pattern: "*.{covar,cov,txt,tsv}" + ontologies: + - edam: "http://edamontology.org/format_3475" + - - meta4: + type: map + description: | + Groovy map containing categorical covariate metadata + e.g. `[ id:'covariates_cat' ]` + - cat_covariates_file: + type: file + description: Categorical covariates file, pass `[]` when absent + pattern: "*.{covar,cov,txt,tsv}" + ontologies: + - edam: "http://edamontology.org/format_3475" +output: + bivariate_results: + - - meta: + type: map + description: | + Groovy map containing shared bivariate phenotype metadata + `meta.id` must contain both trait names, for example `trait1__trait2` + - "*.hsq": + type: file + description: Bivariate REML result file + pattern: "*.{hsq}" + ontologies: + - edam: "http://edamontology.org/format_2330" + log_file: + - - meta: + type: map + description: | + Groovy map containing shared bivariate phenotype metadata + `meta.id` must contain both trait names, for example `trait1__trait2` + - "*.log": + type: file + description: Bivariate REML log file + pattern: "*.{log}" + ontologies: + - edam: "http://edamontology.org/format_2330" + versions_gcta: + - - "${task.process}": + type: string + description: The process the version was collected from + - "gcta": + type: string + description: The tool name + - "gcta --version 2>&1 | grep 'version v' | tr -s ' ' | cut -d' ' -f3 | sed 's/^v//'": + type: eval + description: The command used to retrieve the GCTA version +topics: + versions: + - - ${task.process}: + type: string + description: The process the version was collected from + - gcta: + type: string + description: The tool name + - gcta --version 2>&1 | grep 'version v' | tr -s ' ' | cut -d' ' -f3 | sed 's/^v//': + type: eval + description: The command used to retrieve the GCTA version +authors: + - "@andongni" +maintainers: + - "@andongni" diff --git a/modules/nf-core/gcta/bivariatereml/tests/main.nf.test b/modules/nf-core/gcta/bivariatereml/tests/main.nf.test new file mode 100644 index 000000000000..442abd673f1f --- /dev/null +++ b/modules/nf-core/gcta/bivariatereml/tests/main.nf.test @@ -0,0 +1,147 @@ +nextflow_process { + name "Test Process GCTA_BIVARIATEREML" + script "../main.nf" + process "GCTA_BIVARIATEREML" + + tag "modules" + tag "modules_nfcore" + tag "gcta" + tag "gcta/bivariatereml" + tag "gcta/makegrmpart" + tag "gawk" + + setup { + run("GAWK", alias: "GAWK_BIVARIATE_PHENO") { + script "../../../gawk/main.nf" + process { + """ + input[0] = [ + [ id:'Trait1__Trait2' ], + [ + file(params.modules_testdata_base_path + 'genomics/homo_sapiens/popgen/plink_simulated_quantitative_phenoname.phe', checkIfExists: true), + file(params.modules_testdata_base_path + 'genomics/homo_sapiens/popgen/plink_simulated_covariates.txt', checkIfExists: true) + ] + ] + input[1] = Channel.of('FNR == NR { if (FNR == 1) next; trait1[\$2] = \$3; next } FNR == 1 { next } { print \$1, \$2, trait1[\$2], \$4 }').collectFile(name:'bivariate_phenotype.awk') + input[2] = false + """ + } + } + + run("GAWK", alias: "GAWK_QUANTITATIVE_COVARIATES") { + script "../../../gawk/main.nf" + process { + """ + input[0] = [ + [ id:'covariates_quant' ], + file(params.modules_testdata_base_path + 'genomics/homo_sapiens/popgen/plink_simulated_covariates.txt', checkIfExists: true) + ] + input[1] = Channel.of('FNR == 1 { next } { print \$1, \$2, \$5, \$6 }').collectFile(name:'quantitative_covariates.awk') + input[2] = false + """ + } + } + + run("GAWK", alias: "GAWK_CATEGORICAL_COVARIATES") { + script "../../../gawk/main.nf" + process { + """ + input[0] = [ + [ id:'covariates_cat' ], + file(params.modules_testdata_base_path + 'genomics/homo_sapiens/popgen/plink_simulated_covariates.txt', checkIfExists: true) + ] + input[1] = Channel.of('FNR == 1 { next } { print \$1, \$2, \$3 }').collectFile(name:'categorical_covariates.awk') + input[2] = false + """ + } + } + + run("GCTA_MAKEGRMPART", alias: "GCTA_MAKEGRMPART_DENSE") { + script "../../makegrmpart/main.nf" + process { + """ + file('plink_simulated.mbfile').text = 'plink_simulated\\n' + + input[0] = [ + [ id:'plink_simulated_dense', part_gcta_job:1, nparts_gcta:1 ], + file('plink_simulated.mbfile'), + [ + file(params.modules_testdata_base_path + 'genomics/homo_sapiens/popgen/plink_simulated.bed', checkIfExists: true) + ], + [ + file(params.modules_testdata_base_path + 'genomics/homo_sapiens/popgen/plink_simulated.bim', checkIfExists: true) + ], + [ + file(params.modules_testdata_base_path + 'genomics/homo_sapiens/popgen/plink_simulated.fam', checkIfExists: true) + ] + ] + input[1] = [[ id:'all_variants' ], []] + """ + } + } + } + + test("homo_sapiens popgen - bivariate phenotype with dense GRM and covariates") { + config "./nextflow.config" + when { + process { + """ + dense_grm = GCTA_MAKEGRMPART_DENSE.out.grm_files.map { meta, grm_id, grm_bin, grm_n_bin -> + def prefix = meta.id + '.part_' + meta.nparts_gcta + '_' + meta.part_gcta_job + [[ id:prefix ], grm_id, grm_bin, grm_n_bin] + } + + input[0] = GAWK_BIVARIATE_PHENO.out.output + input[1] = dense_grm + input[2] = GAWK_QUANTITATIVE_COVARIATES.out.output + input[3] = GAWK_CATEGORICAL_COVARIATES.out.output + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert process.out.bivariate_results.size() == 1 }, + { assert process.out.log_file.size() == 1 }, + { assert process.out.bivariate_results.get(0).get(0).id == "Trait1__Trait2" }, + { assert file(process.out.log_file.get(0).get(1)).name == "Trait1__Trait2.log" }, + { assert file(process.out.log_file.get(0).get(1)).exists() }, + { + assert snapshot( + process.out.bivariate_results, + process.out.findAll { key, val -> key.startsWith('versions') } + ).match() + } + ) + } + } + + test("homo_sapiens popgen - bivariate phenotype with dense GRM - stub") { + options "-stub" + config "./nextflow.config" + + when { + process { + """ + dense_grm = GCTA_MAKEGRMPART_DENSE.out.grm_files.map { meta, grm_id, grm_bin, grm_n_bin -> + def prefix = meta.id + '.part_' + meta.nparts_gcta + '_' + meta.part_gcta_job + [[ id:prefix ], grm_id, grm_bin, grm_n_bin] + } + + input[0] = GAWK_BIVARIATE_PHENO.out.output + input[1] = dense_grm + input[2] = [[ id:'covariates_quant' ], []] + input[3] = [[ id:'covariates_cat' ], []] + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert snapshot(process.out).match() } + ) + } + } +} diff --git a/modules/nf-core/gcta/bivariatereml/tests/main.nf.test.snap b/modules/nf-core/gcta/bivariatereml/tests/main.nf.test.snap new file mode 100644 index 000000000000..d16589847d48 --- /dev/null +++ b/modules/nf-core/gcta/bivariatereml/tests/main.nf.test.snap @@ -0,0 +1,85 @@ +{ + "homo_sapiens popgen - bivariate phenotype with dense GRM and covariates": { + "content": [ + [ + [ + { + "id": "Trait1__Trait2" + }, + "Trait1__Trait2.hsq:md5,dab8c6af3e42c9e359825f8f7e6e6fce" + ] + ], + { + "versions_gcta": [ + [ + "GCTA_BIVARIATEREML", + "gcta", + "1.94.1" + ] + ] + } + ], + "meta": { + "nf-test": "0.9.3", + "nextflow": "25.10.4" + }, + "timestamp": "2026-03-18T19:00:59.97128964" + }, + "homo_sapiens popgen - bivariate phenotype with dense GRM - stub": { + "content": [ + { + "0": [ + [ + { + "id": "Trait1__Trait2" + }, + "Trait1__Trait2.hsq:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ], + "1": [ + [ + { + "id": "Trait1__Trait2" + }, + "Trait1__Trait2.log:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ], + "2": [ + [ + "GCTA_BIVARIATEREML", + "gcta", + "1.94.1" + ] + ], + "bivariate_results": [ + [ + { + "id": "Trait1__Trait2" + }, + "Trait1__Trait2.hsq:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ], + "log_file": [ + [ + { + "id": "Trait1__Trait2" + }, + "Trait1__Trait2.log:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ], + "versions_gcta": [ + [ + "GCTA_BIVARIATEREML", + "gcta", + "1.94.1" + ] + ] + } + ], + "meta": { + "nf-test": "0.9.3", + "nextflow": "25.10.4" + }, + "timestamp": "2026-03-13T13:53:21.898185124" + } +} \ No newline at end of file diff --git a/modules/nf-core/gcta/bivariatereml/tests/nextflow.config b/modules/nf-core/gcta/bivariatereml/tests/nextflow.config new file mode 100644 index 000000000000..de31e0218829 --- /dev/null +++ b/modules/nf-core/gcta/bivariatereml/tests/nextflow.config @@ -0,0 +1,3 @@ +params { + modules_testdata_base_path = System.getenv("NF_MODULES_TESTDATA_BASE_PATH") ?: "https://raw.githubusercontent.com/nf-core/test-datasets/modules/data/" +} From 5eb48468b137300bf484caa28bd2bbde0dbabd5d Mon Sep 17 00:00:00 2001 From: lyh970817 Date: Sat, 21 Mar 2026 15:53:18 +0800 Subject: [PATCH 2/4] test(gcta/bivariatereml): harden basename and covariate coverage --- modules/nf-core/gcta/bivariatereml/main.nf | 4 + modules/nf-core/gcta/bivariatereml/meta.yml | 9 +- .../tests/helpers/makegrm/main.nf | 36 ++++++ .../gcta/bivariatereml/tests/main.nf.test | 104 +++++++++++++----- .../bivariatereml/tests/main.nf.test.snap | 73 ++++++------ 5 files changed, 158 insertions(+), 68 deletions(-) create mode 100644 modules/nf-core/gcta/bivariatereml/tests/helpers/makegrm/main.nf diff --git a/modules/nf-core/gcta/bivariatereml/main.nf b/modules/nf-core/gcta/bivariatereml/main.nf index 0065f0ea3585..13cdbdf46922 100644 --- a/modules/nf-core/gcta/bivariatereml/main.nf +++ b/modules/nf-core/gcta/bivariatereml/main.nf @@ -26,6 +26,10 @@ process GCTA_BIVARIATEREML { def qcovar_param = quant_covariates_file ? "--qcovar ${quant_covariates_file}" : '' def covar_param = cat_covariates_file ? "--covar ${cat_covariates_file}" : '' def extra_args = task.ext.args ?: '' + def expected_grm_basename = grm_id.name.replaceFirst(/\.grm\.id$/, '') + if (meta2.id != expected_grm_basename) { + throw new IllegalArgumentException("GCTA_BIVARIATEREML contract violation: meta2.id '${meta2.id}' must match GRM basename '${expected_grm_basename}'") + } """ set -euo pipefail diff --git a/modules/nf-core/gcta/bivariatereml/meta.yml b/modules/nf-core/gcta/bivariatereml/meta.yml index 493ed7d6196b..d6d6222d6b62 100644 --- a/modules/nf-core/gcta/bivariatereml/meta.yml +++ b/modules/nf-core/gcta/bivariatereml/meta.yml @@ -28,20 +28,21 @@ input: type: map description: | Groovy map containing dense GRM metadata - e.g. `[ id:'plink_simulated' ]` + Public contract: `meta2.id` must be the GRM basename passed to `--grm` + (for example `plink_simulated_dense.part_1_1` for `plink_simulated_dense.part_1_1.grm.{id,bin,N.bin}`) - grm_id: type: file - description: Dense GRM sample identifier file + description: Dense GRM sample identifier file (`.grm.id`) pattern: "*.grm.id" ontologies: [] - grm_bin: type: file - description: Dense GRM binary matrix file + description: Dense GRM binary matrix file (`.grm.bin`) pattern: "*.grm.bin" ontologies: [] - grm_n_bin: type: file - description: Dense GRM sample-count matrix file + description: Dense GRM sample-count matrix file (`.grm.N.bin`) pattern: "*.grm.N.bin" ontologies: [] - - meta3: diff --git a/modules/nf-core/gcta/bivariatereml/tests/helpers/makegrm/main.nf b/modules/nf-core/gcta/bivariatereml/tests/helpers/makegrm/main.nf new file mode 100644 index 000000000000..040caa416a9f --- /dev/null +++ b/modules/nf-core/gcta/bivariatereml/tests/helpers/makegrm/main.nf @@ -0,0 +1,36 @@ +process GCTA_MAKEGRM_HELPER { + tag "${meta.id}" + label "process_medium" + conda "${projectDir}/modules/nf-core/gcta/bivariatereml/environment.yml" + container "${workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ? + 'docker://community.wave.seqera.io/library/gcta:1.94.1--9bc35dc424fcf6e9' : + 'community.wave.seqera.io/library/gcta:1.94.1--9bc35dc424fcf6e9'}" + + input: + tuple val(meta), path(bed), path(bim), path(fam) + tuple val(meta2), path(extract_file) + + output: + tuple val(meta), path("${meta.id}.grm.id"), path("${meta.id}.grm.bin"), path("${meta.id}.grm.N.bin"), emit: grm_files + + script: + def extract_param = extract_file ? "--extract ${extract_file}" : "" + def bfile_prefix = bed.baseName + """ + set -euo pipefail + + gcta \\ + --bfile "${bfile_prefix}" \\ + ${extract_param} \\ + --make-grm \\ + --out "${meta.id}" \\ + --thread-num ${task.cpus} + """ + + stub: + """ + touch "${meta.id}.grm.id" + touch "${meta.id}.grm.bin" + touch "${meta.id}.grm.N.bin" + """ +} diff --git a/modules/nf-core/gcta/bivariatereml/tests/main.nf.test b/modules/nf-core/gcta/bivariatereml/tests/main.nf.test index 442abd673f1f..1c1e8f9fe077 100644 --- a/modules/nf-core/gcta/bivariatereml/tests/main.nf.test +++ b/modules/nf-core/gcta/bivariatereml/tests/main.nf.test @@ -7,7 +7,7 @@ nextflow_process { tag "modules_nfcore" tag "gcta" tag "gcta/bivariatereml" - tag "gcta/makegrmpart" + tag "tests/helpers/makegrm" tag "gawk" setup { @@ -56,24 +56,15 @@ nextflow_process { } } - run("GCTA_MAKEGRMPART", alias: "GCTA_MAKEGRMPART_DENSE") { - script "../../makegrmpart/main.nf" + run("GCTA_MAKEGRM_HELPER", alias: "GCTA_MAKEGRM_DENSE") { + script "../tests/helpers/makegrm/main.nf" process { """ - file('plink_simulated.mbfile').text = 'plink_simulated\\n' - input[0] = [ - [ id:'plink_simulated_dense', part_gcta_job:1, nparts_gcta:1 ], - file('plink_simulated.mbfile'), - [ - file(params.modules_testdata_base_path + 'genomics/homo_sapiens/popgen/plink_simulated.bed', checkIfExists: true) - ], - [ - file(params.modules_testdata_base_path + 'genomics/homo_sapiens/popgen/plink_simulated.bim', checkIfExists: true) - ], - [ - file(params.modules_testdata_base_path + 'genomics/homo_sapiens/popgen/plink_simulated.fam', checkIfExists: true) - ] + [ id:'plink_simulated_dense.part_1_1' ], + file(params.modules_testdata_base_path + 'genomics/homo_sapiens/popgen/plink_simulated.bed', checkIfExists: true), + file(params.modules_testdata_base_path + 'genomics/homo_sapiens/popgen/plink_simulated.bim', checkIfExists: true), + file(params.modules_testdata_base_path + 'genomics/homo_sapiens/popgen/plink_simulated.fam', checkIfExists: true) ] input[1] = [[ id:'all_variants' ], []] """ @@ -86,13 +77,8 @@ nextflow_process { when { process { """ - dense_grm = GCTA_MAKEGRMPART_DENSE.out.grm_files.map { meta, grm_id, grm_bin, grm_n_bin -> - def prefix = meta.id + '.part_' + meta.nparts_gcta + '_' + meta.part_gcta_job - [[ id:prefix ], grm_id, grm_bin, grm_n_bin] - } - input[0] = GAWK_BIVARIATE_PHENO.out.output - input[1] = dense_grm + input[1] = GCTA_MAKEGRM_DENSE.out.grm_files input[2] = GAWK_QUANTITATIVE_COVARIATES.out.output input[3] = GAWK_CATEGORICAL_COVARIATES.out.output """ @@ -105,6 +91,7 @@ nextflow_process { { assert process.out.bivariate_results.size() == 1 }, { assert process.out.log_file.size() == 1 }, { assert process.out.bivariate_results.get(0).get(0).id == "Trait1__Trait2" }, + { assert file(process.out.bivariate_results.get(0).get(1)).name == "Trait1__Trait2.hsq" }, { assert file(process.out.log_file.get(0).get(1)).name == "Trait1__Trait2.log" }, { assert file(process.out.log_file.get(0).get(1)).exists() }, { @@ -117,20 +104,70 @@ nextflow_process { } } - test("homo_sapiens popgen - bivariate phenotype with dense GRM - stub") { - options "-stub" + test("homo_sapiens popgen - bivariate phenotype with dense GRM and no covariates") { config "./nextflow.config" + when { + process { + """ + input[0] = GAWK_BIVARIATE_PHENO.out.output + input[1] = GCTA_MAKEGRM_DENSE.out.grm_files + input[2] = [[ id:'covariates_quant' ], []] + input[3] = [[ id:'covariates_cat' ], []] + """ + } + } + then { + assertAll( + { assert process.success }, + { assert process.out.bivariate_results.size() == 1 }, + { assert process.out.log_file.size() == 1 }, + { assert file(process.out.bivariate_results.get(0).get(1)).name == "Trait1__Trait2.hsq" }, + { assert file(process.out.log_file.get(0).get(1)).name == "Trait1__Trait2.log" }, + { + assert snapshot( + process.out.bivariate_results, + process.out.findAll { key, val -> key.startsWith('versions') } + ).match() + } + ) + } + } + + test("homo_sapiens popgen - bivariate phenotype fails when meta2.id is not GRM basename") { + config "./nextflow.config" when { process { """ - dense_grm = GCTA_MAKEGRMPART_DENSE.out.grm_files.map { meta, grm_id, grm_bin, grm_n_bin -> - def prefix = meta.id + '.part_' + meta.nparts_gcta + '_' + meta.part_gcta_job - [[ id:prefix ], grm_id, grm_bin, grm_n_bin] + mismatched_dense_grm = GCTA_MAKEGRM_DENSE.out.grm_files.map { meta, grm_id, grm_bin, grm_n_bin -> + [[ id:meta.id + '_mismatched' ], grm_id, grm_bin, grm_n_bin] } input[0] = GAWK_BIVARIATE_PHENO.out.output - input[1] = dense_grm + input[1] = mismatched_dense_grm + input[2] = [[ id:'covariates_quant' ], []] + input[3] = [[ id:'covariates_cat' ], []] + """ + } + } + + then { + assertAll( + { assert !process.success }, + { assert process.exitStatus != 0 } + ) + } + } + + test("homo_sapiens popgen - bivariate phenotype with dense GRM - stub") { + options "-stub" + config "./nextflow.config" + + when { + process { + """ + input[0] = GAWK_BIVARIATE_PHENO.out.output + input[1] = GCTA_MAKEGRM_DENSE.out.grm_files input[2] = [[ id:'covariates_quant' ], []] input[3] = [[ id:'covariates_cat' ], []] """ @@ -140,7 +177,16 @@ nextflow_process { then { assertAll( { assert process.success }, - { assert snapshot(process.out).match() } + { assert process.out.bivariate_results.get(0).get(0).id == "Trait1__Trait2" }, + { assert file(process.out.bivariate_results.get(0).get(1)).name == "Trait1__Trait2.hsq" }, + { assert file(process.out.log_file.get(0).get(1)).name == "Trait1__Trait2.log" }, + { + assert snapshot( + process.out.bivariate_results, + process.out.log_file, + process.out.findAll { key, val -> key.startsWith('versions') } + ).match() + } ) } } diff --git a/modules/nf-core/gcta/bivariatereml/tests/main.nf.test.snap b/modules/nf-core/gcta/bivariatereml/tests/main.nf.test.snap index d16589847d48..f3926a53b7b1 100644 --- a/modules/nf-core/gcta/bivariatereml/tests/main.nf.test.snap +++ b/modules/nf-core/gcta/bivariatereml/tests/main.nf.test.snap @@ -27,46 +27,49 @@ }, "homo_sapiens popgen - bivariate phenotype with dense GRM - stub": { "content": [ + [ + [ + { + "id": "Trait1__Trait2" + }, + "Trait1__Trait2.hsq:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ], + [ + [ + { + "id": "Trait1__Trait2" + }, + "Trait1__Trait2.log:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ], { - "0": [ - [ - { - "id": "Trait1__Trait2" - }, - "Trait1__Trait2.hsq:md5,d41d8cd98f00b204e9800998ecf8427e" - ] - ], - "1": [ - [ - { - "id": "Trait1__Trait2" - }, - "Trait1__Trait2.log:md5,d41d8cd98f00b204e9800998ecf8427e" - ] - ], - "2": [ + "versions_gcta": [ [ "GCTA_BIVARIATEREML", "gcta", "1.94.1" ] - ], - "bivariate_results": [ - [ - { - "id": "Trait1__Trait2" - }, - "Trait1__Trait2.hsq:md5,d41d8cd98f00b204e9800998ecf8427e" - ] - ], - "log_file": [ - [ - { - "id": "Trait1__Trait2" - }, - "Trait1__Trait2.log:md5,d41d8cd98f00b204e9800998ecf8427e" - ] - ], + ] + } + ], + "meta": { + "nf-test": "0.9.3", + "nextflow": "25.10.4" + }, + "timestamp": "2026-03-21T00:39:39.931811972" + }, + "homo_sapiens popgen - bivariate phenotype with dense GRM and no covariates": { + "content": [ + [ + [ + { + "id": "Trait1__Trait2" + }, + "Trait1__Trait2.hsq:md5,15ca96ea55899bff113889c811d4c75b" + ] + ], + { "versions_gcta": [ [ "GCTA_BIVARIATEREML", @@ -80,6 +83,6 @@ "nf-test": "0.9.3", "nextflow": "25.10.4" }, - "timestamp": "2026-03-13T13:53:21.898185124" + "timestamp": "2026-03-21T00:37:07.144133381" } } \ No newline at end of file From cd19e4cab198a463e0e9df36646fd383af4a8712 Mon Sep 17 00:00:00 2001 From: lyh970817 Date: Sat, 21 Mar 2026 20:47:36 +0800 Subject: [PATCH 3/4] tests: switch bivariatereml setup to makegrmpart --- .../tests/helpers/makegrm/main.nf | 36 -------------- .../gcta/bivariatereml/tests/main.nf.test | 49 ++++++++++++++----- 2 files changed, 37 insertions(+), 48 deletions(-) delete mode 100644 modules/nf-core/gcta/bivariatereml/tests/helpers/makegrm/main.nf diff --git a/modules/nf-core/gcta/bivariatereml/tests/helpers/makegrm/main.nf b/modules/nf-core/gcta/bivariatereml/tests/helpers/makegrm/main.nf deleted file mode 100644 index 040caa416a9f..000000000000 --- a/modules/nf-core/gcta/bivariatereml/tests/helpers/makegrm/main.nf +++ /dev/null @@ -1,36 +0,0 @@ -process GCTA_MAKEGRM_HELPER { - tag "${meta.id}" - label "process_medium" - conda "${projectDir}/modules/nf-core/gcta/bivariatereml/environment.yml" - container "${workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ? - 'docker://community.wave.seqera.io/library/gcta:1.94.1--9bc35dc424fcf6e9' : - 'community.wave.seqera.io/library/gcta:1.94.1--9bc35dc424fcf6e9'}" - - input: - tuple val(meta), path(bed), path(bim), path(fam) - tuple val(meta2), path(extract_file) - - output: - tuple val(meta), path("${meta.id}.grm.id"), path("${meta.id}.grm.bin"), path("${meta.id}.grm.N.bin"), emit: grm_files - - script: - def extract_param = extract_file ? "--extract ${extract_file}" : "" - def bfile_prefix = bed.baseName - """ - set -euo pipefail - - gcta \\ - --bfile "${bfile_prefix}" \\ - ${extract_param} \\ - --make-grm \\ - --out "${meta.id}" \\ - --thread-num ${task.cpus} - """ - - stub: - """ - touch "${meta.id}.grm.id" - touch "${meta.id}.grm.bin" - touch "${meta.id}.grm.N.bin" - """ -} diff --git a/modules/nf-core/gcta/bivariatereml/tests/main.nf.test b/modules/nf-core/gcta/bivariatereml/tests/main.nf.test index 1c1e8f9fe077..f875b33aa4f8 100644 --- a/modules/nf-core/gcta/bivariatereml/tests/main.nf.test +++ b/modules/nf-core/gcta/bivariatereml/tests/main.nf.test @@ -7,7 +7,7 @@ nextflow_process { tag "modules_nfcore" tag "gcta" tag "gcta/bivariatereml" - tag "tests/helpers/makegrm" + tag "gcta/makegrmpart" tag "gawk" setup { @@ -56,15 +56,24 @@ nextflow_process { } } - run("GCTA_MAKEGRM_HELPER", alias: "GCTA_MAKEGRM_DENSE") { - script "../tests/helpers/makegrm/main.nf" + run("GCTA_MAKEGRMPART", alias: "GCTA_MAKEGRMPART_DENSE") { + script "../../makegrmpart/main.nf" process { """ + file('plink_simulated.mbfile').text = 'plink_simulated\\n' + input[0] = [ - [ id:'plink_simulated_dense.part_1_1' ], - file(params.modules_testdata_base_path + 'genomics/homo_sapiens/popgen/plink_simulated.bed', checkIfExists: true), - file(params.modules_testdata_base_path + 'genomics/homo_sapiens/popgen/plink_simulated.bim', checkIfExists: true), - file(params.modules_testdata_base_path + 'genomics/homo_sapiens/popgen/plink_simulated.fam', checkIfExists: true) + [ id:'plink_simulated_dense', part_gcta_job:1, nparts_gcta:1 ], + file('plink_simulated.mbfile'), + [ + file(params.modules_testdata_base_path + 'genomics/homo_sapiens/popgen/plink_simulated.bed', checkIfExists: true) + ], + [ + file(params.modules_testdata_base_path + 'genomics/homo_sapiens/popgen/plink_simulated.bim', checkIfExists: true) + ], + [ + file(params.modules_testdata_base_path + 'genomics/homo_sapiens/popgen/plink_simulated.fam', checkIfExists: true) + ] ] input[1] = [[ id:'all_variants' ], []] """ @@ -77,8 +86,13 @@ nextflow_process { when { process { """ + dense_grm = GCTA_MAKEGRMPART_DENSE.out.grm_files.map { meta, grm_id, grm_bin, grm_n_bin -> + def prefix = meta.id + '.part_' + meta.nparts_gcta + '_' + meta.part_gcta_job + [[ id:prefix ], grm_id, grm_bin, grm_n_bin] + } + input[0] = GAWK_BIVARIATE_PHENO.out.output - input[1] = GCTA_MAKEGRM_DENSE.out.grm_files + input[1] = dense_grm input[2] = GAWK_QUANTITATIVE_COVARIATES.out.output input[3] = GAWK_CATEGORICAL_COVARIATES.out.output """ @@ -109,8 +123,13 @@ nextflow_process { when { process { """ + dense_grm = GCTA_MAKEGRMPART_DENSE.out.grm_files.map { meta, grm_id, grm_bin, grm_n_bin -> + def prefix = meta.id + '.part_' + meta.nparts_gcta + '_' + meta.part_gcta_job + [[ id:prefix ], grm_id, grm_bin, grm_n_bin] + } + input[0] = GAWK_BIVARIATE_PHENO.out.output - input[1] = GCTA_MAKEGRM_DENSE.out.grm_files + input[1] = dense_grm input[2] = [[ id:'covariates_quant' ], []] input[3] = [[ id:'covariates_cat' ], []] """ @@ -139,8 +158,9 @@ nextflow_process { when { process { """ - mismatched_dense_grm = GCTA_MAKEGRM_DENSE.out.grm_files.map { meta, grm_id, grm_bin, grm_n_bin -> - [[ id:meta.id + '_mismatched' ], grm_id, grm_bin, grm_n_bin] + mismatched_dense_grm = GCTA_MAKEGRMPART_DENSE.out.grm_files.map { meta, grm_id, grm_bin, grm_n_bin -> + def prefix = meta.id + '.part_' + meta.nparts_gcta + '_' + meta.part_gcta_job + [[ id:prefix + '_mismatched' ], grm_id, grm_bin, grm_n_bin] } input[0] = GAWK_BIVARIATE_PHENO.out.output @@ -166,8 +186,13 @@ nextflow_process { when { process { """ + dense_grm = GCTA_MAKEGRMPART_DENSE.out.grm_files.map { meta, grm_id, grm_bin, grm_n_bin -> + def prefix = meta.id + '.part_' + meta.nparts_gcta + '_' + meta.part_gcta_job + [[ id:prefix ], grm_id, grm_bin, grm_n_bin] + } + input[0] = GAWK_BIVARIATE_PHENO.out.output - input[1] = GCTA_MAKEGRM_DENSE.out.grm_files + input[1] = dense_grm input[2] = [[ id:'covariates_quant' ], []] input[3] = [[ id:'covariates_cat' ], []] """ From 9a0b13b8bc354bdd58081389d9576c11fdb129f1 Mon Sep 17 00:00:00 2001 From: lyh970817 Date: Sat, 16 May 2026 08:36:40 +0800 Subject: [PATCH 4/4] Update bivariatereml dense GRM contract --- modules/nf-core/gcta/bivariatereml/main.nf | 22 ++- modules/nf-core/gcta/bivariatereml/meta.yml | 43 +++--- .../gcta/bivariatereml/tests/main.nf.test | 92 ++++++++---- .../bivariatereml/tests/main.nf.test.snap | 28 +++- modules/nf-core/gcta/makegrm/environment.yml | 7 + modules/nf-core/gcta/makegrm/main.nf | 42 ++++++ modules/nf-core/gcta/makegrm/meta.yml | 91 +++++++++++ .../nf-core/gcta/makegrm/tests/main.nf.test | 142 ++++++++++++++++++ .../gcta/makegrm/tests/main.nf.test.snap | 111 ++++++++++++++ .../gcta/makegrm/tests/nextflow.config | 3 + 10 files changed, 525 insertions(+), 56 deletions(-) create mode 100644 modules/nf-core/gcta/makegrm/environment.yml create mode 100644 modules/nf-core/gcta/makegrm/main.nf create mode 100644 modules/nf-core/gcta/makegrm/meta.yml create mode 100644 modules/nf-core/gcta/makegrm/tests/main.nf.test create mode 100644 modules/nf-core/gcta/makegrm/tests/main.nf.test.snap create mode 100644 modules/nf-core/gcta/makegrm/tests/nextflow.config diff --git a/modules/nf-core/gcta/bivariatereml/main.nf b/modules/nf-core/gcta/bivariatereml/main.nf index 13cdbdf46922..783631ca7c46 100644 --- a/modules/nf-core/gcta/bivariatereml/main.nf +++ b/modules/nf-core/gcta/bivariatereml/main.nf @@ -2,20 +2,20 @@ process GCTA_BIVARIATEREML { tag "bivariate_reml_${meta.id}_${meta2.id}" label 'process_medium' conda "${moduleDir}/environment.yml" - container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ? - 'docker://community.wave.seqera.io/library/gcta:1.94.1--9bc35dc424fcf6e9' : - 'community.wave.seqera.io/library/gcta:1.94.1--9bc35dc424fcf6e9' }" + container "${workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container + ? 'https://community-cr-prod.seqera.io/docker/registry/v2/blobs/sha256/46/46b0d05f0daa47561d87d2a9cac5e51edc2c78e26f1bbab439c688386241a274/data' + : 'community.wave.seqera.io/library/gcta:1.94.1--9bc35dc424fcf6e9'}" input: - tuple val(meta), path(phenotype_file) - tuple val(meta2), path(grm_id), path(grm_bin), path(grm_n_bin) + tuple val(meta), path(phenotype_file), val(mpheno), val(prevalence) + tuple val(meta2), path(grm_files) tuple val(meta3), path(quant_covariates_file) tuple val(meta4), path(cat_covariates_file) output: tuple val(meta), path("*.hsq"), emit: bivariate_results tuple val(meta), path("*.log"), emit: log_file - tuple val("${task.process}"), val("gcta"), eval("gcta --version 2>&1 | grep 'version v' | tr -s ' ' | cut -d' ' -f3 | sed 's/^v//'"), emit: versions_gcta, topic: versions + tuple val("${task.process}"), val("gcta"), eval("gcta --version | sed -En 's/^[*] version v([0-9.]*).*/\\1/p'"), emit: versions_gcta, topic: versions when: task.ext.when == null || task.ext.when @@ -26,6 +26,13 @@ process GCTA_BIVARIATEREML { def qcovar_param = quant_covariates_file ? "--qcovar ${quant_covariates_file}" : '' def covar_param = cat_covariates_file ? "--covar ${cat_covariates_file}" : '' def extra_args = task.ext.args ?: '' + def bivar_traits = mpheno ?: '1 2' + def prevalence_param = prevalence ? "--reml-bivar-prevalence ${prevalence}" : '' + def grm_file_list = grm_files instanceof List ? grm_files : [grm_files] + def grm_id = grm_file_list.find { grm_file -> grm_file.name.endsWith('.grm.id') } + if (!grm_id) { + throw new IllegalArgumentException("GCTA_BIVARIATEREML contract violation: grm_files must include a .grm.id file") + } def expected_grm_basename = grm_id.name.replaceFirst(/\.grm\.id$/, '') if (meta2.id != expected_grm_basename) { throw new IllegalArgumentException("GCTA_BIVARIATEREML contract violation: meta2.id '${meta2.id}' must match GRM basename '${expected_grm_basename}'") @@ -35,9 +42,10 @@ process GCTA_BIVARIATEREML { set -euo pipefail gcta \\ - --reml-bivar 1 2 \\ + --reml-bivar ${bivar_traits} \\ --grm ${meta2.id} \\ --pheno "${phenotype_file}" \\ + ${prevalence_param} \\ ${qcovar_param} \\ ${covar_param} \\ --out "${pair_id}" \\ diff --git a/modules/nf-core/gcta/bivariatereml/meta.yml b/modules/nf-core/gcta/bivariatereml/meta.yml index d6d6222d6b62..733e9507730b 100644 --- a/modules/nf-core/gcta/bivariatereml/meta.yml +++ b/modules/nf-core/gcta/bivariatereml/meta.yml @@ -3,8 +3,12 @@ name: "gcta_bivariatereml" description: Run bivariate REML analysis with a single dense GRM keywords: - gcta + - genome-wide complex trait analysis - reml + - restricted maximum likelihood - bivariate + - grm + - genetic relationship matrix - genetics tools: - "gcta": @@ -12,6 +16,8 @@ tools: homepage: "https://yanglab.westlake.edu.cn/software/gcta/" documentation: "https://yanglab.westlake.edu.cn/software/gcta/static/gcta_doc_latest.pdf" tool_dev_url: "https://yanglab.westlake.edu.cn/software/gcta/" + licence: ["GPL-3.0-only"] + identifier: "biotools:gcta" input: - - meta: type: map @@ -24,26 +30,27 @@ input: pattern: "*.{phe,pheno,txt,tsv}" ontologies: - edam: "http://edamontology.org/format_3475" + - mpheno: + type: string + description: | + Optional pair of phenotype column indices passed to `--reml-bivar`; + pass `[]` to use the module default of `1 2` + - prevalence: + type: string + description: | + Optional pair of disease prevalence values passed to `--reml-bivar-prevalence` + for binary traits; pass `[]` for quantitative traits - - meta2: type: map description: | Groovy map containing dense GRM metadata Public contract: `meta2.id` must be the GRM basename passed to `--grm` - (for example `plink_simulated_dense.part_1_1` for `plink_simulated_dense.part_1_1.grm.{id,bin,N.bin}`) - - grm_id: - type: file - description: Dense GRM sample identifier file (`.grm.id`) - pattern: "*.grm.id" - ontologies: [] - - grm_bin: - type: file - description: Dense GRM binary matrix file (`.grm.bin`) - pattern: "*.grm.bin" - ontologies: [] - - grm_n_bin: + (for example `plink_simulated_dense` for `plink_simulated_dense.grm.{id,bin,N.bin}`) + - grm_files: type: file - description: Dense GRM sample-count matrix file (`.grm.N.bin`) - pattern: "*.grm.N.bin" + description: Dense GRM bundle containing sample identifier, binary matrix, + and sample-count matrix files + pattern: "*.grm.*" ontologies: [] - - meta3: type: map @@ -99,7 +106,7 @@ output: - "gcta": type: string description: The tool name - - "gcta --version 2>&1 | grep 'version v' | tr -s ' ' | cut -d' ' -f3 | sed 's/^v//'": + - "gcta --version | sed -En 's/^[*] version v([0-9.]*).*/\\1/p'": type: eval description: The command used to retrieve the GCTA version topics: @@ -110,10 +117,10 @@ topics: - gcta: type: string description: The tool name - - gcta --version 2>&1 | grep 'version v' | tr -s ' ' | cut -d' ' -f3 | sed 's/^v//': + - "gcta --version | sed -En 's/^[*] version v([0-9.]*).*/\\1/p'": type: eval description: The command used to retrieve the GCTA version authors: - - "@andongni" + - "@lyh970817" maintainers: - - "@andongni" + - "@lyh970817" diff --git a/modules/nf-core/gcta/bivariatereml/tests/main.nf.test b/modules/nf-core/gcta/bivariatereml/tests/main.nf.test index f875b33aa4f8..e3fd58313d9e 100644 --- a/modules/nf-core/gcta/bivariatereml/tests/main.nf.test +++ b/modules/nf-core/gcta/bivariatereml/tests/main.nf.test @@ -7,7 +7,7 @@ nextflow_process { tag "modules_nfcore" tag "gcta" tag "gcta/bivariatereml" - tag "gcta/makegrmpart" + tag "gcta/makegrm" tag "gawk" setup { @@ -28,6 +28,20 @@ nextflow_process { } } + run("GAWK", alias: "GAWK_BIVARIATE_BINARY_PHENO") { + script "../../../gawk/main.nf" + process { + """ + input[0] = [ + [ id:'BinaryTrait1__BinaryTrait2' ], + file(params.modules_testdata_base_path + 'genomics/homo_sapiens/popgen/plink_simulated_quantitative_phenoname.phe', checkIfExists: true) + ] + input[1] = Channel.of('FNR == 1 { next } { print \$1, \$2, (NR % 2) + 1, (NR % 3 == 0 ? 2 : 1) }').collectFile(name:'bivariate_binary_phenotype.awk') + input[2] = false + """ + } + } + run("GAWK", alias: "GAWK_QUANTITATIVE_COVARIATES") { script "../../../gawk/main.nf" process { @@ -56,14 +70,14 @@ nextflow_process { } } - run("GCTA_MAKEGRMPART", alias: "GCTA_MAKEGRMPART_DENSE") { - script "../../makegrmpart/main.nf" + run("GCTA_MAKEGRM", alias: "GCTA_MAKEGRM_DENSE") { + script "../../makegrm/main.nf" process { """ file('plink_simulated.mbfile').text = 'plink_simulated\\n' input[0] = [ - [ id:'plink_simulated_dense', part_gcta_job:1, nparts_gcta:1 ], + [ id:'plink_simulated_dense' ], file('plink_simulated.mbfile'), [ file(params.modules_testdata_base_path + 'genomics/homo_sapiens/popgen/plink_simulated.bed', checkIfExists: true) @@ -75,7 +89,6 @@ nextflow_process { file(params.modules_testdata_base_path + 'genomics/homo_sapiens/popgen/plink_simulated.fam', checkIfExists: true) ] ] - input[1] = [[ id:'all_variants' ], []] """ } } @@ -86,13 +99,8 @@ nextflow_process { when { process { """ - dense_grm = GCTA_MAKEGRMPART_DENSE.out.grm_files.map { meta, grm_id, grm_bin, grm_n_bin -> - def prefix = meta.id + '.part_' + meta.nparts_gcta + '_' + meta.part_gcta_job - [[ id:prefix ], grm_id, grm_bin, grm_n_bin] - } - - input[0] = GAWK_BIVARIATE_PHENO.out.output - input[1] = dense_grm + input[0] = GAWK_BIVARIATE_PHENO.out.output.map { meta, phenotype_file -> [meta, phenotype_file, [], []] } + input[1] = GCTA_MAKEGRM_DENSE.out.grm_files input[2] = GAWK_QUANTITATIVE_COVARIATES.out.output input[3] = GAWK_CATEGORICAL_COVARIATES.out.output """ @@ -123,13 +131,8 @@ nextflow_process { when { process { """ - dense_grm = GCTA_MAKEGRMPART_DENSE.out.grm_files.map { meta, grm_id, grm_bin, grm_n_bin -> - def prefix = meta.id + '.part_' + meta.nparts_gcta + '_' + meta.part_gcta_job - [[ id:prefix ], grm_id, grm_bin, grm_n_bin] - } - - input[0] = GAWK_BIVARIATE_PHENO.out.output - input[1] = dense_grm + input[0] = GAWK_BIVARIATE_PHENO.out.output.map { meta, phenotype_file -> [meta, phenotype_file, [], []] } + input[1] = GCTA_MAKEGRM_DENSE.out.grm_files input[2] = [[ id:'covariates_quant' ], []] input[3] = [[ id:'covariates_cat' ], []] """ @@ -153,17 +156,51 @@ nextflow_process { } } + test("homo_sapiens popgen - binary bivariate phenotype with prevalence") { + config "./nextflow.config" + when { + process { + """ + input[0] = GAWK_BIVARIATE_BINARY_PHENO.out.output.map { meta, phenotype_file -> [meta, phenotype_file, '1 2', '0.30 0.25'] } + input[1] = GCTA_MAKEGRM_DENSE.out.grm_files + input[2] = [[ id:'covariates_quant' ], []] + input[3] = [[ id:'covariates_cat' ], []] + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert process.out.bivariate_results.size() == 1 }, + { assert process.out.log_file.size() == 1 }, + { assert process.out.bivariate_results.get(0).get(0).id == "BinaryTrait1__BinaryTrait2" }, + { assert file(process.out.bivariate_results.get(0).get(1)).name == "BinaryTrait1__BinaryTrait2.hsq" }, + { assert file(process.out.log_file.get(0).get(1)).name == "BinaryTrait1__BinaryTrait2.log" }, + { + def logText = file(process.out.log_file.get(0).get(1)).text + assert logText.contains("--reml-bivar-prevalence 0.3 0.25") + }, + { + assert snapshot( + process.out.bivariate_results, + process.out.findAll { key, val -> key.startsWith('versions') } + ).match() + } + ) + } + } + test("homo_sapiens popgen - bivariate phenotype fails when meta2.id is not GRM basename") { config "./nextflow.config" when { process { """ - mismatched_dense_grm = GCTA_MAKEGRMPART_DENSE.out.grm_files.map { meta, grm_id, grm_bin, grm_n_bin -> - def prefix = meta.id + '.part_' + meta.nparts_gcta + '_' + meta.part_gcta_job - [[ id:prefix + '_mismatched' ], grm_id, grm_bin, grm_n_bin] + mismatched_dense_grm = GCTA_MAKEGRM_DENSE.out.grm_files.map { meta, grm_files -> + [[ id:meta.id + '_mismatched' ], grm_files] } - input[0] = GAWK_BIVARIATE_PHENO.out.output + input[0] = GAWK_BIVARIATE_PHENO.out.output.map { meta, phenotype_file -> [meta, phenotype_file, [], []] } input[1] = mismatched_dense_grm input[2] = [[ id:'covariates_quant' ], []] input[3] = [[ id:'covariates_cat' ], []] @@ -186,13 +223,8 @@ nextflow_process { when { process { """ - dense_grm = GCTA_MAKEGRMPART_DENSE.out.grm_files.map { meta, grm_id, grm_bin, grm_n_bin -> - def prefix = meta.id + '.part_' + meta.nparts_gcta + '_' + meta.part_gcta_job - [[ id:prefix ], grm_id, grm_bin, grm_n_bin] - } - - input[0] = GAWK_BIVARIATE_PHENO.out.output - input[1] = dense_grm + input[0] = GAWK_BIVARIATE_PHENO.out.output.map { meta, phenotype_file -> [meta, phenotype_file, [], []] } + input[1] = GCTA_MAKEGRM_DENSE.out.grm_files input[2] = [[ id:'covariates_quant' ], []] input[3] = [[ id:'covariates_cat' ], []] """ diff --git a/modules/nf-core/gcta/bivariatereml/tests/main.nf.test.snap b/modules/nf-core/gcta/bivariatereml/tests/main.nf.test.snap index f3926a53b7b1..c77f1fc7df54 100644 --- a/modules/nf-core/gcta/bivariatereml/tests/main.nf.test.snap +++ b/modules/nf-core/gcta/bivariatereml/tests/main.nf.test.snap @@ -1,4 +1,30 @@ { + "homo_sapiens popgen - binary bivariate phenotype with prevalence": { + "content": [ + [ + [ + { + "id": "BinaryTrait1__BinaryTrait2" + }, + "BinaryTrait1__BinaryTrait2.hsq:md5,c663ff1c3610e4bd9594b0dd9fd94b53" + ] + ], + { + "versions_gcta": [ + [ + "GCTA_BIVARIATEREML", + "gcta", + "1.94.1" + ] + ] + } + ], + "meta": { + "nf-test": "0.9.3", + "nextflow": "25.10.4" + }, + "timestamp": "2026-05-13T16:07:04.068669845" + }, "homo_sapiens popgen - bivariate phenotype with dense GRM and covariates": { "content": [ [ @@ -57,7 +83,7 @@ "nf-test": "0.9.3", "nextflow": "25.10.4" }, - "timestamp": "2026-03-21T00:39:39.931811972" + "timestamp": "2026-05-13T16:39:12.456478213" }, "homo_sapiens popgen - bivariate phenotype with dense GRM and no covariates": { "content": [ diff --git a/modules/nf-core/gcta/makegrm/environment.yml b/modules/nf-core/gcta/makegrm/environment.yml new file mode 100644 index 000000000000..3e22ea7b9f20 --- /dev/null +++ b/modules/nf-core/gcta/makegrm/environment.yml @@ -0,0 +1,7 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/nf-core/modules/master/modules/environment-schema.json +channels: + - conda-forge + - bioconda +dependencies: + - bioconda::gcta=1.94.1 diff --git a/modules/nf-core/gcta/makegrm/main.nf b/modules/nf-core/gcta/makegrm/main.nf new file mode 100644 index 000000000000..0bb78639e361 --- /dev/null +++ b/modules/nf-core/gcta/makegrm/main.nf @@ -0,0 +1,42 @@ +process GCTA_MAKEGRM { + tag "${meta.id}" + label 'process_medium' + conda "${moduleDir}/environment.yml" + container "${workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container + ? 'https://community-cr-prod.seqera.io/docker/registry/v2/blobs/sha256/46/46b0d05f0daa47561d87d2a9cac5e51edc2c78e26f1bbab439c688386241a274/data' + : 'community.wave.seqera.io/library/gcta:1.94.1--9bc35dc424fcf6e9'}" + + input: + tuple val(meta), path(mfile), path(bed_pgen), path(bim_pvar), path(fam_psam) + + output: + tuple val(meta), path("*.grm.*"), emit: grm_files + tuple val("${task.process}"), val("gcta"), eval("gcta --version | sed -En 's/^[*] version v([0-9.]*).*/\\1/p'"), emit: versions_gcta, topic: versions + + when: + task.ext.when == null || task.ext.when + + script: + def extra_args = task.ext.args ?: '' + def prefix = task.ext.prefix ?: "${meta.id}" + def genotype_files = bed_pgen instanceof List ? bed_pgen : [bed_pgen] + def genotype_extension = genotype_files[0].name.tokenize('.').last() + def multi_file_flag = genotype_extension == 'pgen' ? '--mpfile' : '--mbfile' + + """ + + gcta \\ + ${multi_file_flag} ${mfile} \\ + --make-grm \\ + --thread-num ${task.cpus} \\ + --out ${prefix} ${extra_args} + """ + + stub: + def prefix = task.ext.prefix ?: "${meta.id}" + """ + touch ${prefix}.grm.id + touch ${prefix}.grm.bin + touch ${prefix}.grm.N.bin + """ +} diff --git a/modules/nf-core/gcta/makegrm/meta.yml b/modules/nf-core/gcta/makegrm/meta.yml new file mode 100644 index 000000000000..0c813dadada6 --- /dev/null +++ b/modules/nf-core/gcta/makegrm/meta.yml @@ -0,0 +1,91 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/nf-core/modules/master/modules/meta-schema.json +name: "gcta_makegrm" +description: Compute a whole dense GRM with GCTA +keywords: + - gcta + - genome-wide complex trait analysis + - grm + - genetic relationship matrix + - genetics +tools: + - "gcta": + description: "GCTA is a tool for genome-wide complex trait analysis." + homepage: "https://yanglab.westlake.edu.cn/software/gcta/" + documentation: "https://yanglab.westlake.edu.cn/software/gcta/static/gcta_doc_latest.pdf" + tool_dev_url: "https://github.com/jianyangqt/gcta" + licence: + - "GPL-3.0-only" + identifier: biotools:gcta + +input: + - - meta: + type: map + description: | + Groovy Map containing GRM sample metadata + e.g. `[ id:'gcta_grm' ]` + - mfile: + type: file + description: GCTA multi-input manifest consumed by `--mbfile` or + `--mpfile` + pattern: "*.{mbfile,mpfile,txt}" + ontologies: + - edam: "http://edamontology.org/format_2330" + - bed_pgen: + type: file + description: Collection of PLINK primary genotype files referenced by the + multi-input manifest + pattern: "*.{bed,pgen}" + ontologies: + - edam: "http://edamontology.org/format_3003" + - bim_pvar: + type: file + description: Collection of PLINK variant metadata files referenced by the + multi-input manifest + pattern: "*.{bim,pvar}" + ontologies: [] + - fam_psam: + type: file + description: Collection of PLINK sample metadata files referenced by the + multi-input manifest + pattern: "*.{fam,psam}" + ontologies: [] + +output: + grm_files: + - - meta: + type: map + description: | + Groovy Map containing GRM sample metadata + e.g. `[ id:'gcta_grm' ]` + - "*.grm.*": + type: file + description: Dense GRM sidecar files + pattern: "*.grm.{id,bin,N.bin}" + ontologies: [] + versions_gcta: + - - ${task.process}: + type: string + description: The process the version was collected from + - gcta: + type: string + description: The tool name + - "gcta --version | sed -En 's/^[*] version v([0-9.]*).*/\\1/p'": + type: eval + description: The command used to generate the version of the tool + +topics: + versions: + - - ${task.process}: + type: string + description: The process the versions were collected from + - gcta: + type: string + description: The tool name + - "gcta --version | sed -En 's/^[*] version v([0-9.]*).*/\\1/p'": + type: eval + description: The command used to generate the version of the tool + +authors: + - "@lyh970817" +maintainers: + - "@lyh970817" diff --git a/modules/nf-core/gcta/makegrm/tests/main.nf.test b/modules/nf-core/gcta/makegrm/tests/main.nf.test new file mode 100644 index 000000000000..e5c63233678b --- /dev/null +++ b/modules/nf-core/gcta/makegrm/tests/main.nf.test @@ -0,0 +1,142 @@ +nextflow_process { + + name "Test Process GCTA_MAKEGRM" + script "../main.nf" + process "GCTA_MAKEGRM" + + tag "modules" + tag "modules_nfcore" + tag "gcta" + tag "gcta/makegrm" + + test("homo_sapiens popgen - plink2") { + when { + process { + """ + file('gcta_grm.mpfile').text = 'plink_simulated plink_simulated.pgen plink_simulated.psam plink_simulated.pvar\\n' + + input[0] = [ + [ id:'gcta_grm' ], + file('gcta_grm.mpfile'), + [ + file(params.modules_testdata_base_path + 'genomics/homo_sapiens/popgen/plink_simulated.pgen', checkIfExists: true) + ], + [ + file(params.modules_testdata_base_path + 'genomics/homo_sapiens/popgen/plink_simulated.pvar', checkIfExists: true) + ], + [ + file(params.modules_testdata_base_path + 'genomics/homo_sapiens/popgen/plink_simulated.psam', checkIfExists: true) + ] + ] + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert process.out.grm_files.size() == 1 }, + { assert process.out.grm_files.get(0).get(0).id == 'gcta_grm' }, + { assert process.out.grm_files.get(0).get(0).keySet() == ['id'] as Set }, + { assert process.out.grm_files.get(0).get(1).size() == 3 }, + { + assert process.out.grm_files.get(0).get(1).collect { file(it).name }.toSet() == [ + 'gcta_grm.grm.id', + 'gcta_grm.grm.bin', + 'gcta_grm.grm.N.bin' + ] as Set + }, + { assert file(path(process.out.grm_files.get(0).get(1)[0]).parent.toString() + '/.command.sh').text.contains('--make-grm') }, + { assert file(path(process.out.grm_files.get(0).get(1)[0]).parent.toString() + '/.command.sh').text.contains('--mpfile') }, + { + assert snapshot( + process.out.grm_files, + process.out.findAll { key, val -> key.startsWith('versions') } + ).match() + } + ) + } + } + + test("homo_sapiens popgen - plink1") { + when { + process { + """ + file('gcta_grm.mbfile').text = 'plink_simulated\\n' + + input[0] = [ + [ id:'gcta_grm_bed' ], + file('gcta_grm.mbfile'), + [ + file(params.modules_testdata_base_path + 'genomics/homo_sapiens/popgen/plink_simulated.bed', checkIfExists: true) + ], + [ + file(params.modules_testdata_base_path + 'genomics/homo_sapiens/popgen/plink_simulated.bim', checkIfExists: true) + ], + [ + file(params.modules_testdata_base_path + 'genomics/homo_sapiens/popgen/plink_simulated.fam', checkIfExists: true) + ] + ] + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert process.out.grm_files.size() == 1 }, + { assert process.out.grm_files.get(0).get(0).id == 'gcta_grm_bed' }, + { assert process.out.grm_files.get(0).get(0).keySet() == ['id'] as Set }, + { assert process.out.grm_files.get(0).get(1).size() == 3 }, + { + assert process.out.grm_files.get(0).get(1).collect { file(it).name }.toSet() == [ + 'gcta_grm_bed.grm.id', + 'gcta_grm_bed.grm.bin', + 'gcta_grm_bed.grm.N.bin' + ] as Set + }, + { assert file(path(process.out.grm_files.get(0).get(1)[0]).parent.toString() + '/.command.sh').text.contains('--make-grm') }, + { assert file(path(process.out.grm_files.get(0).get(1)[0]).parent.toString() + '/.command.sh').text.contains('--mbfile') }, + { + assert snapshot( + process.out.grm_files, + process.out.findAll { key, val -> key.startsWith('versions') } + ).match() + } + ) + } + } + + test("homo_sapiens popgen - plink1 - stub") { + options "-stub" + + when { + process { + """ + file('gcta_grm.mbfile').text = 'plink_simulated\\n' + + input[0] = [ + [ id:'gcta_grm_bed' ], + file('gcta_grm.mbfile'), + [ + file(params.modules_testdata_base_path + 'genomics/homo_sapiens/popgen/plink_simulated.bed', checkIfExists: true) + ], + [ + file(params.modules_testdata_base_path + 'genomics/homo_sapiens/popgen/plink_simulated.bim', checkIfExists: true) + ], + [ + file(params.modules_testdata_base_path + 'genomics/homo_sapiens/popgen/plink_simulated.fam', checkIfExists: true) + ] + ] + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert snapshot(process.out).match() } + ) + } + } +} diff --git a/modules/nf-core/gcta/makegrm/tests/main.nf.test.snap b/modules/nf-core/gcta/makegrm/tests/main.nf.test.snap new file mode 100644 index 000000000000..f8fbe133d5a2 --- /dev/null +++ b/modules/nf-core/gcta/makegrm/tests/main.nf.test.snap @@ -0,0 +1,111 @@ +{ + "homo_sapiens popgen - plink2": { + "content": [ + [ + [ + { + "id": "gcta_grm" + }, + [ + "gcta_grm.grm.N.bin:md5,acaa43bbbf2253d392537a178ecf09a4", + "gcta_grm.grm.bin:md5,45f8dff14bda17d50009a21050572228", + "gcta_grm.grm.id:md5,4f9aa36c44a417ff6d7caa9841e66ad9" + ] + ] + ], + { + "versions_gcta": [ + [ + "GCTA_MAKEGRM", + "gcta", + "1.94.1" + ] + ] + } + ], + "meta": { + "nf-test": "0.9.3", + "nextflow": "25.10.4" + }, + "timestamp": "2026-05-15T21:08:43.209734458" + }, + "homo_sapiens popgen - plink1": { + "content": [ + [ + [ + { + "id": "gcta_grm_bed" + }, + [ + "gcta_grm_bed.grm.N.bin:md5,acaa43bbbf2253d392537a178ecf09a4", + "gcta_grm_bed.grm.bin:md5,45f8dff14bda17d50009a21050572228", + "gcta_grm_bed.grm.id:md5,4f9aa36c44a417ff6d7caa9841e66ad9" + ] + ] + ], + { + "versions_gcta": [ + [ + "GCTA_MAKEGRM", + "gcta", + "1.94.1" + ] + ] + } + ], + "meta": { + "nf-test": "0.9.3", + "nextflow": "25.10.4" + }, + "timestamp": "2026-05-15T21:09:34.058651287" + }, + "homo_sapiens popgen - plink1 - stub": { + "content": [ + { + "0": [ + [ + { + "id": "gcta_grm_bed" + }, + [ + "gcta_grm_bed.grm.N.bin:md5,d41d8cd98f00b204e9800998ecf8427e", + "gcta_grm_bed.grm.bin:md5,d41d8cd98f00b204e9800998ecf8427e", + "gcta_grm_bed.grm.id:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ] + ], + "1": [ + [ + "GCTA_MAKEGRM", + "gcta", + "1.94.1" + ] + ], + "grm_files": [ + [ + { + "id": "gcta_grm_bed" + }, + [ + "gcta_grm_bed.grm.N.bin:md5,d41d8cd98f00b204e9800998ecf8427e", + "gcta_grm_bed.grm.bin:md5,d41d8cd98f00b204e9800998ecf8427e", + "gcta_grm_bed.grm.id:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ] + ], + "versions_gcta": [ + [ + "GCTA_MAKEGRM", + "gcta", + "1.94.1" + ] + ] + } + ], + "meta": { + "nf-test": "0.9.3", + "nextflow": "25.10.4" + }, + "timestamp": "2026-05-15T21:10:21.024687128" + } +} \ No newline at end of file diff --git a/modules/nf-core/gcta/makegrm/tests/nextflow.config b/modules/nf-core/gcta/makegrm/tests/nextflow.config new file mode 100644 index 000000000000..de31e0218829 --- /dev/null +++ b/modules/nf-core/gcta/makegrm/tests/nextflow.config @@ -0,0 +1,3 @@ +params { + modules_testdata_base_path = System.getenv("NF_MODULES_TESTDATA_BASE_PATH") ?: "https://raw.githubusercontent.com/nf-core/test-datasets/modules/data/" +}