Skip to content

Commit 97abcce

Browse files
committed
Set get region as a function
1 parent 8dc48d1 commit 97abcce

File tree

6 files changed

+182
-138
lines changed

6 files changed

+182
-138
lines changed

subworkflows/local/get_region/main.nf

Lines changed: 0 additions & 29 deletions
This file was deleted.

subworkflows/local/get_region/tests/main.nf.test

Lines changed: 0 additions & 99 deletions
This file was deleted.

subworkflows/local/get_region/tests/tags.yml

Lines changed: 0 additions & 2 deletions
This file was deleted.

subworkflows/local/utils_nfcore_phaseimpute_pipeline/main.nf

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,9 @@
99
*/
1010

1111
include { UTILS_NFSCHEMA_PLUGIN } from '../../nf-core/utils_nfschema_plugin'
12-
include { paramsSummaryMap } from 'plugin/nf-schema'
1312
include { samplesheetToList } from 'plugin/nf-schema'
14-
include { completionEmail } from '../../nf-core/utils_nfcore_pipeline'
15-
include { completionSummary } from '../../nf-core/utils_nfcore_pipeline'
16-
include { imNotification } from '../../nf-core/utils_nfcore_pipeline'
1713
include { UTILS_NFCORE_PIPELINE } from '../../nf-core/utils_nfcore_pipeline'
1814
include { UTILS_NEXTFLOW_PIPELINE } from '../../nf-core/utils_nextflow_pipeline'
19-
include { GET_REGION } from '../get_region'
2015
include { SAMTOOLS_FAIDX } from '../../../modules/nf-core/samtools/faidx'
2116

2217
/*
@@ -172,9 +167,7 @@ workflow PIPELINE_INITIALISATION {
172167
//
173168
if (params.input_region == null){
174169
// #TODO Add support for string input
175-
GET_REGION ("all", ch_ref_gen)
176-
ch_versions = ch_versions.mix(GET_REGION.out.versions)
177-
ch_regions = GET_REGION.out.regions
170+
ch_regions = getRegionFromFai("all", ch_ref_gen)
178171
} else if (params.input_region.endsWith(".csv")) {
179172
println "Region file provided as input is a csv file"
180173
ch_regions = Channel.fromList(samplesheetToList(
@@ -337,6 +330,11 @@ workflow PIPELINE_INITIALISATION {
337330
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
338331
*/
339332

333+
include { completionEmail } from '../../nf-core/utils_nfcore_pipeline'
334+
include { completionSummary } from '../../nf-core/utils_nfcore_pipeline'
335+
include { imNotification } from '../../nf-core/utils_nfcore_pipeline'
336+
include { paramsSummaryMap } from 'plugin/nf-schema'
337+
340338
workflow PIPELINE_COMPLETION {
341339

342340
take:
@@ -536,6 +534,32 @@ def checkMetaChr(chr_a, chr_b, name){
536534
return intersect
537535
}
538536

537+
//
538+
// Get region from fasta fai file
539+
//
540+
def getRegionFromFai(input_region, ch_fasta) {
541+
def ch_regions = Channel.empty()
542+
// Gather regions to use and create the meta map
543+
if (input_region ==~ '^(chr)?[0-9XYM]+$' || input_region == "all") {
544+
ch_regions = ch_fasta.map{it -> it[2]}
545+
.splitCsv(header: ["chr", "size", "offset", "lidebase", "linewidth", "qualoffset"], sep: "\t")
546+
.map{it -> [chr:it.chr, region:"0-"+it.size]}
547+
if (input_region != "all") {
548+
ch_regions = ch_regions.filter{it.chr == input_region}
549+
}
550+
ch_regions = ch_regions
551+
.map{ [[chr: it.chr, region: it.chr + ":" + it.region], it.chr + ":" + it.region]}
552+
} else {
553+
if (input_region ==~ '^chr[0-9XYM]+:[0-9]+-[0-9]+$') {
554+
ch_regions = Channel.from([input_region])
555+
.map{ [[chr: it.split(":")[0], "region": it], it]}
556+
} else {
557+
error "Invalid input_region: ${input_region}"
558+
}
559+
}
560+
return ch_regions
561+
}
562+
539563
//
540564
// Get file extension
541565
//
@@ -651,6 +675,7 @@ def genomeExistsError() {
651675
error(error_string)
652676
}
653677
}
678+
654679
//
655680
// Generate methods description for MultiQC
656681
//

subworkflows/local/utils_nfcore_phaseimpute_pipeline/tests/function.nf.test

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,102 @@ nextflow_function {
420420
)
421421
}
422422
}
423+
424+
test ("Test getRegionFromFai with all") {
425+
function "getRegionFromFai"
426+
tag "getRegionFromFai"
427+
when {
428+
function {
429+
"""
430+
input[0] = "all"
431+
input[1] = Channel.of([
432+
[genome:"GRCh37"],
433+
file("https://raw.githubusercontent.com/nf-core/test-datasets/phaseimpute/hum_data/reference_genome/GRCh38.s.fa.gz", checkIfExists: true),
434+
file("https://raw.githubusercontent.com/nf-core/test-datasets/phaseimpute/hum_data/reference_genome/GRCh38.s.fa.gz.fai", checkIfExists: true)
435+
])
436+
"""
437+
}
438+
}
439+
440+
then {
441+
assertAll(
442+
{ assert function.success },
443+
{ assert snapshot(
444+
check_stdout(function.stdout)
445+
).match() }
446+
)
447+
}
448+
}
449+
450+
test ("Test getRegionFromFai with specified chr") {
451+
function "getRegionFromFai"
452+
tag "getRegionFromFai"
453+
when {
454+
function {
455+
"""
456+
input[0] = "chr22"
457+
input[1] = Channel.of([
458+
[genome:"GRCh37"],
459+
file("https://raw.githubusercontent.com/nf-core/test-datasets/phaseimpute/hum_data/reference_genome/GRCh38.s.fa.gz", checkIfExists: true),
460+
file("https://raw.githubusercontent.com/nf-core/test-datasets/phaseimpute/hum_data/reference_genome/GRCh38.s.fa.gz.fai", checkIfExists: true)
461+
])
462+
"""
463+
}
464+
}
465+
466+
then {
467+
assertAll(
468+
{ assert function.success },
469+
{ assert snapshot(
470+
check_stdout(function.stdout)
471+
).match() }
472+
)
473+
}
474+
}
475+
476+
test ("Test getRegionFromFai with specified region without fasta") {
477+
function "getRegionFromFai"
478+
tag "getRegionFromFai"
479+
when {
480+
function {
481+
"""
482+
input[0] = "chr22:0-4000"
483+
input[1] = Channel.of([[], [], []])
484+
"""
485+
}
486+
}
487+
488+
then {
489+
assertAll(
490+
{ assert function.success },
491+
{ assert snapshot(
492+
check_stdout(function.stdout)
493+
).match() }
494+
)
495+
}
496+
}
497+
498+
test ("Test getRegionFromFai with an error") {
499+
function "getRegionFromFai"
500+
tag "getRegionFromFai"
501+
when {
502+
function {
503+
"""
504+
input[0] = "chr22:0-4000:4648"
505+
input[1] = Channel.of([[],[],[]])
506+
"""
507+
}
508+
}
509+
510+
then {
511+
assertAll(
512+
{ assert function.failed },
513+
{ assert snapshot(
514+
check_stdout(function.stdout)
515+
).match() }
516+
)
517+
}
518+
}
423519
}
424520

425521
def check_stdout(function_stdout) {

subworkflows/local/utils_nfcore_phaseimpute_pipeline/tests/function.nf.test.snap

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,44 @@
11
{
2+
"Test getRegionFromFai with specified region without fasta": {
3+
"content": [
4+
[
5+
"N E X T F L O W ~ version 24.10.4",
6+
"Launching `/home/llenezet/repositories/phaseimpute/.nf-test-116782867ed97a5c13ace9bd868bbcf4.nf` [confident_poincare] DSL2 - revision: 2e27797805"
7+
]
8+
],
9+
"meta": {
10+
"nf-test": "0.9.1",
11+
"nextflow": "24.10.4"
12+
},
13+
"timestamp": "2025-03-03T16:33:27.900550819"
14+
},
15+
"Test getRegionFromFai with an error": {
16+
"content": [
17+
[
18+
"N E X T F L O W ~ version 24.10.4",
19+
"Launching `/home/llenezet/repositories/phaseimpute/.nf-test-1a3752b79d4099a7e0e3ebc89ddcefe4.nf` [romantic_linnaeus] DSL2 - revision: 497ddbdc0c",
20+
"Invalid input_region: chr22:0-4000:4648"
21+
]
22+
],
23+
"meta": {
24+
"nf-test": "0.9.1",
25+
"nextflow": "24.10.4"
26+
},
27+
"timestamp": "2025-03-03T16:33:34.099630703"
28+
},
29+
"Test getRegionFromFai with specified chr": {
30+
"content": [
31+
[
32+
"N E X T F L O W ~ version 24.10.4",
33+
"Launching `/home/llenezet/repositories/phaseimpute/.nf-test-809919788e3408bfdbf2abf526ce3429.nf` [mad_wing] DSL2 - revision: d7b132a693"
34+
]
35+
],
36+
"meta": {
37+
"nf-test": "0.9.1",
38+
"nextflow": "24.10.4"
39+
},
40+
"timestamp": "2025-03-03T16:33:20.266790135"
41+
},
242
"Test checkFileIndex no error with empty channel": {
343
"content": null,
444
"meta": {
@@ -39,6 +79,19 @@
3979
},
4080
"timestamp": "2024-11-06T15:32:58.039856651"
4181
},
82+
"Test getRegionFromFai with all": {
83+
"content": [
84+
[
85+
"N E X T F L O W ~ version 24.10.4",
86+
"Launching `/home/llenezet/repositories/phaseimpute/.nf-test-4eec42e60e03cc0422d6cdd736e0ca5c.nf` [pedantic_kilby] DSL2 - revision: 1c4729a817"
87+
]
88+
],
89+
"meta": {
90+
"nf-test": "0.9.1",
91+
"nextflow": "24.10.4"
92+
},
93+
"timestamp": "2025-03-03T16:33:12.465326351"
94+
},
4295
"Test validateInputBatchTools vcf only for glimpse": {
4396
"content": [
4497
[

0 commit comments

Comments
 (0)