Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions subworkflows/nf-core/fasta_clean_faidx/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ include { SAMTOOLS_DICT } from "../../../modules/nf-core/samtool
workflow FASTA_CLEAN_FAIDX {
take:
ch_reference // channel.of( [meta], reference )
val_replace_dots // boolean: replace dots in headers with underscores in trimmed reference
val_get_chromsizes // boolean: emit chromsizes
val_get_dict // boolean: emit dict

Expand Down Expand Up @@ -50,19 +51,27 @@ workflow FASTA_CLEAN_FAIDX {
//
// MODULE: REPLACE `.` IN HEADERS WITH `_`
// `.` CAN CAUSE ISSUES FOR SOME DOWNSTREAM TOOLS
//
SEQKIT_DOTS (
SEQKIT_SEQ.out.fastx,
"fasta"
)
// CONTROLLING THIS ON val_replace_dots ALLOWS US TO STAY INSIDE OF
// SOME STANDARDS (e.g. ONLY TAKE FIRST WORK IN HEADER)
//
if (val_replace_dots) {
SEQKIT_DOTS (
SEQKIT_SEQ.out.fastx,
"fasta"
)

renamed_fasta = SEQKIT_DOTS.out.fastx
} else {
renamed_fasta = SEQKIT_SEQ.out.fastx
}


//
// MODULE: GENERATE INDEX OF REFERENCE FASTA
// OPTIONALLY EMIT CHROMOSOME SIZES FILE
//
SAMTOOLS_FAIDX (
SEQKIT_DOTS.out.fastx.map { meta, file -> [meta, file, []] },
renamed_fasta.map { meta, file -> [meta, file, []] },
val_get_chromsizes
)

Expand All @@ -79,12 +88,12 @@ workflow FASTA_CLEAN_FAIDX {
// MODULE: GENERATE A SAMTOOLS DICT FILE BASED ON THE CORRECTED FASTA FILE
//
SAMTOOLS_DICT (
SEQKIT_DOTS.out.fastx.filter { meta, file -> val_get_dict }
renamed_fasta.filter { meta, file -> val_get_dict }
)


emit:
reference = SEQKIT_DOTS.out.fastx
reference = renamed_fasta
fai = SAMTOOLS_FAIDX.out.fai
sizes = SAMTOOLS_FAIDX.out.sizes
dict = SAMTOOLS_DICT.out.dict
Expand Down
10 changes: 10 additions & 0 deletions subworkflows/nf-core/fasta_clean_faidx/meta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,20 @@ input:

Structure: [ val(meta), path(fasta) ]
pattern: "*.{(fasta,fa,fna)(.gz)}"

- val_replace_dots:
type: boolean
description: |
Whether to replace dots in the fasta reference name with underscores.

Some tools can't handle dots in the fasta name, however,
sometimes the ID must remain unchanged.

- val_get_chromsizes:
type: boolean
description: |
Whether to generate a chromosome sizes file from the fasta reference.

- val_get_dict:
type: boolean
description: |
Expand Down
48 changes: 46 additions & 2 deletions subworkflows/nf-core/fasta_clean_faidx/tests/main.nf.test
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ nextflow_workflow {
)
input[1] = true
input[2] = true
input[3] = true
"""
}

Expand All @@ -41,6 +42,7 @@ nextflow_workflow {
{ assert workflow.success },
{ assert snapshot(
path(workflow.out.dict[0][1]).readLines()[0],
path(workflow.out.reference[0][1]).readLines()[0],
workflow.out.reference,
workflow.out.fai,
workflow.out.sizes,
Expand All @@ -50,7 +52,7 @@ nextflow_workflow {
}
}

test("Bacteroides fragilis genome [fasta] w/ index no sizes") {
test("Bacteroides fragilis genome [fasta] w/ index - keep dots") {
when {

params {
Expand All @@ -67,6 +69,7 @@ nextflow_workflow {
)
input[1] = false
input[2] = true
input[3] = true
"""
}

Expand All @@ -77,6 +80,45 @@ nextflow_workflow {
{ assert workflow.success },
{ assert snapshot(
path(workflow.out.dict[0][1]).readLines()[0],
path(workflow.out.reference[0][1]).readLines()[0],
workflow.out.reference,
workflow.out.fai,
workflow.out.sizes,
workflow.out.sequence_description
).match() }
)
}
}

test("Bacteroides fragilis genome [fasta] w/ index no sizes") {
when {

params {
outdir = "test"
}

workflow {
"""
input[0] = channel.of(
[
[ id: 'test' ],
file(params.modules_testdata_base_path + 'genomics/prokaryotes/bacteroides_fragilis/genome/genome.fna.gz', checkIfExists: true)
]
)
input[1] = true
input[2] = false
input[3] = true
"""
}

}

then {
assertAll(
{ assert workflow.success },
{ assert snapshot(
path(workflow.out.dict[0][1]).readLines()[0],
path(workflow.out.reference[0][1]).readLines()[0],
workflow.out.reference,
workflow.out.fai,
workflow.out.sequence_description
Expand All @@ -99,8 +141,9 @@ nextflow_workflow {
file(params.modules_testdata_base_path + 'genomics/prokaryotes/bacteroides_fragilis/genome/genome.fna.gz', checkIfExists: true)
]
)
input[1] = false
input[1] = true
input[2] = false
input[3] = false
"""
}

Expand Down Expand Up @@ -132,6 +175,7 @@ nextflow_workflow {
)
input[1] = true
input[2] = true
input[3] = true
"""
}
}
Expand Down
57 changes: 51 additions & 6 deletions subworkflows/nf-core/fasta_clean_faidx/tests/main.nf.test.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,51 @@
{
"Bacteroides fragilis genome [fasta] w/ index - keep dots": {
"content": [
"@HD\tVN:1.0\tSO:unsorted",
">NZ_CP069563.1",
[
[
{
"id": "test"
},
"test.fasta:md5,96aa7707b864499745e8946f169ae8e0"
]
],
[
[
{
"id": "test"
},
"test.fasta.fai:md5,f1373ef38f3777bcf9567be2e1f5c468"
]
],
[
[
{
"id": "test"
},
"test.fasta.sizes:md5,acc65893c145aa8385e4afb4f4662623"
]
],
[
[
{
"id": "test"
},
"test.json:md5,1e536d080509f7fc34114f0bc58a514d"
]
]
],
"timestamp": "2026-08-28T17:29:22.581741203",
"meta": {
"nf-test": "0.9.5",
"nextflow": "25.04.6"
}
},
"Bacteroides fragilis genome [fasta] w/ index": {
"content": [
"@HD\tVN:1.0\tSO:unsorted",
">NZ_CP069563_1",
[
[
{
Expand Down Expand Up @@ -35,10 +79,10 @@
]
]
],
"timestamp": "2026-08-26T10:00:11.358890143",
"timestamp": "2026-08-28T12:57:01.005284326",
"meta": {
"nf-test": "0.9.5",
"nextflow": "26.04.0"
"nextflow": "25.04.6"
}
},
"Bacteroides fragilis genome - stub": {
Expand Down Expand Up @@ -148,15 +192,16 @@
]
}
],
"timestamp": "2026-08-26T10:00:31.191958515",
"timestamp": "2026-08-28T17:29:42.76692073",
"meta": {
"nf-test": "0.9.5",
"nextflow": "26.04.0"
"nextflow": "25.04.6"
}
},
"Bacteroides fragilis genome [fasta] w/ index no sizes": {
"content": [
"@HD\tVN:1.0\tSO:unsorted",
">NZ_CP069563_1",
[
[
{
Expand All @@ -182,10 +227,10 @@
]
]
],
"timestamp": "2026-08-26T10:00:21.054412137",
"timestamp": "2026-08-28T17:29:32.864768835",
"meta": {
"nf-test": "0.9.5",
"nextflow": "26.04.0"
"nextflow": "25.04.6"
}
}
}