diff --git a/modules.json b/modules.json index 47c20082..a25581b4 100644 --- a/modules.json +++ b/modules.json @@ -81,7 +81,7 @@ "pfr": { "fasta_ltrretriever_lai": { "branch": "main", - "git_sha": "60ee50c79f8f868fe0b2e48cba543ad1d8fa89b2", + "git_sha": "f148f5384395618fc706b6e2f059bd1ce037d06c", "installed_by": ["subworkflows"] }, "fastq_bwa_mem_samblaster": { diff --git a/subworkflows/pfr/fasta_ltrretriever_lai/main.nf b/subworkflows/pfr/fasta_ltrretriever_lai/main.nf index ea5183b1..7bdc2c28 100644 --- a/subworkflows/pfr/fasta_ltrretriever_lai/main.nf +++ b/subworkflows/pfr/fasta_ltrretriever_lai/main.nf @@ -24,7 +24,7 @@ workflow FASTA_LTRRETRIEVER_LAI { ch_short_ids_fasta = ch_fasta | join(CUSTOM_SHORTENFASTAIDS.out.short_ids_fasta, by:0, remainder:true) | map { meta, fasta, short_ids_fasta -> - [ meta, short_ids_fasta ?: fasta ] + if ( fasta ) { [ meta, short_ids_fasta ?: fasta ] } } ch_short_ids_tsv = CUSTOM_SHORTENFASTAIDS.out.short_ids_tsv @@ -35,6 +35,12 @@ workflow FASTA_LTRRETRIEVER_LAI { | map { meta, short_ids_tsv, monoploid_seqs -> map_monoploid_seqs_to_new_ids(meta, short_ids_tsv, monoploid_seqs) } + | collectFile(newLine:true) + | map { seqs -> + def id = seqs.name.split('.mapped.monoploid.seqs.txt')[0] + + [ [ id: id ], seqs ] + } ch_versions = ch_versions.mix(CUSTOM_SHORTENFASTAIDS.out.versions.first()) // MODULE: LTRHARVEST @@ -133,7 +139,7 @@ def map_monoploid_seqs_to_new_ids(meta, short_ids_tsv, monoploid_seqs) { def short_ids_head = short_ids_tsv.text.split('\n')[0] if (short_ids_head == "IDs have acceptable length and character. No change required.") { - return [ meta, monoploid_seqs ] + return [ "${meta.id}.mapped.monoploid.seqs.txt" ] + monoploid_seqs.text.split('\n') } def orig_to_new_ids = [:] @@ -142,15 +148,15 @@ def map_monoploid_seqs_to_new_ids(meta, short_ids_tsv, monoploid_seqs) { orig_to_new_ids[original_id] = renamed_id } - def output_file = new File("${meta.id}.mapped.monoploid.seqs.txt") + def mapped_ids = [] monoploid_seqs.text.eachLine { original_id -> if (!orig_to_new_ids[original_id]) { error "Faild to find $original_id in ${monoploid_seqs}" + "The monoploid_seqs file is malformed!" } - output_file.append(orig_to_new_ids[original_id]) + mapped_ids.add(orig_to_new_ids[original_id]) } - return [ meta, output_file.toPath() ] + return [ "${meta.id}.mapped.monoploid.seqs.txt" ] + mapped_ids } diff --git a/subworkflows/pfr/fasta_ltrretriever_lai/tests/main.nf.test b/subworkflows/pfr/fasta_ltrretriever_lai/tests/main.nf.test index f2c401d8..7ba88ab6 100644 --- a/subworkflows/pfr/fasta_ltrretriever_lai/tests/main.nf.test +++ b/subworkflows/pfr/fasta_ltrretriever_lai/tests/main.nf.test @@ -109,6 +109,8 @@ nextflow_workflow { test("actinidia_chinensis-genome_21_fasta_gz-without_lai") { + options '-stub' + setup { run("GUNZIP") { script "../../../../modules/nf-core/gunzip" @@ -148,11 +150,35 @@ nextflow_workflow { then { assertAll( { assert workflow.success }, - { assert file(workflow.out.annotation_gff[0][1]).text.contains('Copia_LTR_retrotransposon') }, - { assert file(workflow.out.ltrlib[0][1]).text.contains('#LTR/Copia') }, + { assert workflow.out.annotation_gff != null }, + { assert workflow.out.ltrlib != null }, { assert workflow.out.lai_log == [] }, { assert workflow.out.lai_out == [] } ) } } + + test("empty_fasta_stub") { + + options '-stub' + + when { + workflow { + """ + def monoploid_seqs = new File('test.mono.seq.txt') + monoploid_seqs.write("chr_xxxxxxxxxxxxxxx_1") + + input[0] = Channel.empty() + input[1] = Channel.of( [ [ id:'test' ], monoploid_seqs.toPath() ] ) + input[2] = false + """ + } + } + + then { + assertAll( + { assert workflow.success } + ) + } + } }