Skip to content

Commit

Permalink
Set chunk prepare channel as function
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisLeNezet committed Mar 3, 2025
1 parent 9368068 commit f8e7eff
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 164 deletions.
112 changes: 0 additions & 112 deletions subworkflows/local/chunk_prepare_channel/tests/main.nf.test.snap

This file was deleted.

2 changes: 0 additions & 2 deletions subworkflows/local/chunk_prepare_channel/tests/tags.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
workflow CHUNK_PREPARE_CHANNEL {

take:
ch_chunks // channel: [ [id, chr], txt ]
tool

main:

def chunkPrepareChannel(ch_chunks, tool) {
if(tool == "glimpse"){
ch_chunks = ch_chunks.map { chr, txt -> [chr, file(txt)]}
.splitCsv(header: ['ID', 'Chr', 'RegionIn', 'RegionOut', 'Size1', 'Size2'], sep: "\t", skip: 0)
Expand All @@ -20,8 +13,5 @@ workflow CHUNK_PREPARE_CHANNEL {
} else {
error "Only 'glimpse' and 'quilt' output format are supported. Got ${tool}"
}

emit:
chunks = ch_chunks // channel: [ [meta], regionstart, regionend ]

return ch_chunks // channel: [ [meta], regionstart, regionend ]
}
11 changes: 4 additions & 7 deletions workflows/phaseimpute/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ include { GAWK as FILTER_CHR_DWN } from '../../modules/nf-co
include { VCF_NORMALIZE_BCFTOOLS } from '../../subworkflows/local/vcf_normalize_bcftools'
include { VCF_SITES_EXTRACT_BCFTOOLS } from '../../subworkflows/local/vcf_sites_extract_bcftools'
include { VCF_PHASE_SHAPEIT5 } from '../../subworkflows/local/vcf_phase_shapeit5'
include { CHUNK_PREPARE_CHANNEL } from '../../subworkflows/local/chunk_prepare_channel'
include { VCF_CONCATENATE_BCFTOOLS as CONCAT_PANEL } from '../../subworkflows/local/vcf_concatenate_bcftools'
include { BCFTOOLS_STATS as BCFTOOLS_STATS_PANEL } from '../../modules/nf-core/bcftools/stats'
include { chunkPrepareChannel } from './function.nf'

// Imputation
include { LISTTOFILE } from '../../modules/local/listtofile'
Expand Down Expand Up @@ -291,8 +291,7 @@ workflow PHASEIMPUTE {

// Use chunks from parameters if provided or use previous chunks from panelprep
if (params.chunks) {
CHUNK_PREPARE_CHANNEL(ch_chunks, "glimpse")
ch_chunks_glimpse1 = CHUNK_PREPARE_CHANNEL.out.chunks
ch_chunks_glimpse1 = chunkPrepareChannel(ch_chunks, "glimpse")
}

// Glimpse1 subworkflow
Expand Down Expand Up @@ -330,8 +329,7 @@ workflow PHASEIMPUTE {
log.info("Impute with GLIMPSE2")

if (params.chunks) {
CHUNK_PREPARE_CHANNEL(ch_chunks, "glimpse")
ch_chunks_glimpse2 = CHUNK_PREPARE_CHANNEL.out.chunks
ch_chunks_glimpse2 = chunkPrepareChannel(ch_chunks, "glimpse")
}

// Run imputation
Expand Down Expand Up @@ -378,8 +376,7 @@ workflow PHASEIMPUTE {

// Use provided chunks if --chunks
if (params.chunks) {
CHUNK_PREPARE_CHANNEL(ch_chunks, "quilt")
ch_chunks_quilt = CHUNK_PREPARE_CHANNEL.out.chunks
ch_chunks_quilt = chunkPrepareChannel(ch_chunks, "quilt")
}

// Impute BAMs with QUILT
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
nextflow_workflow {
nextflow_function {
/*
The following tests are for the functions in the main.nf script
They are tested using the --verbose argument
*/

name "Test Subworkflow CHUNK_PREPARE_CHANNEL"
script "../main.nf"

workflow "CHUNK_PREPARE_CHANNEL"

tag "subworkflows"
tag "subworkflows_local"
tag "subworkflows/chunk_prepare_channel"
tag "chunk_prepare_channel"
name "Test function phaseimpute"
script "../function.nf"
tag "function"

test("Prepare chunks channel Glimpse") {
function "chunkPrepareChannel"
tag "chunkPrepareChannel"
when {
params {
max_cpus = 2
max_memory = '2.GB'
}
workflow {
function {
"""
input[0] = Channel.of([
[id: "1000GP", chr: "chr21"],
Expand All @@ -29,19 +25,16 @@ nextflow_workflow {

then {
assertAll(
{ assert workflow.success },
{ assert snapshot(workflow.out).match() },
{ assert function.success }
)
}
}

test("Prepare chunks channel Quilt") {
function "chunkPrepareChannel"
tag "chunkPrepareChannel"
when {
params {
max_cpus = 2
max_memory = '2.GB'
}
workflow {
function {
"""
input[0] = Channel.of([
[id: "1000GP", chr: "chr21"],
Expand All @@ -54,19 +47,16 @@ nextflow_workflow {

then {
assertAll(
{ assert workflow.success },
{ assert snapshot(workflow.out).match() },
{ assert function.success }
)
}
}

test("Prepare chunks channel error tool") {
function "chunkPrepareChannel"
tag "chunkPrepareChannel"
when {
params {
max_cpus = 2
max_memory = '2.GB'
}
workflow {
function {
"""
input[0] = Channel.of([
[id: "1000GP", chr: "chr21"],
Expand All @@ -79,8 +69,8 @@ nextflow_workflow {

then {
assertAll(
{ assert workflow.failed },
{ assert snapshot(workflow.stdout).match() }
{ assert function.failed },
{ assert function.stdout.contains("Only 'glimpse' and 'quilt' output format are supported. Got glimpse2") }
)
}
}
Expand Down
40 changes: 40 additions & 0 deletions workflows/phaseimpute/tests/function.nf.test.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"Prepare chunks channel Quilt": {
"content": [
{

}
],
"meta": {
"nf-test": "0.9.1",
"nextflow": "24.10.4"
},
"timestamp": "2025-03-03T16:53:24.615848886"
},
"Prepare chunks channel error tool": {
"content": [
[
"N E X T F L O W ~ version 24.10.4",
"Launching `/home/llenezet/repositories/phaseimpute/.nf-test-dd0d5421ca2fe0df9ae90be137523768.nf` [scruffy_fermat] DSL2 - revision: d78e86493b",
"Only 'glimpse' and 'quilt' output format are supported. Got glimpse2"
]
],
"meta": {
"nf-test": "0.9.1",
"nextflow": "24.10.4"
},
"timestamp": "2025-03-03T16:59:53.809041216"
},
"Prepare chunks channel Glimpse": {
"content": [
{

}
],
"meta": {
"nf-test": "0.9.1",
"nextflow": "24.10.4"
},
"timestamp": "2025-03-03T16:53:17.567651555"
}
}

0 comments on commit f8e7eff

Please sign in to comment.