Skip to content

Commit

Permalink
Updated fasta_ltrretriever_lai
Browse files Browse the repository at this point in the history
  • Loading branch information
GallVp committed Feb 29, 2024
1 parent d714bf0 commit f13a9e5
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
2 changes: 1 addition & 1 deletion modules.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"pfr": {
"fasta_ltrretriever_lai": {
"branch": "main",
"git_sha": "60ee50c79f8f868fe0b2e48cba543ad1d8fa89b2",
"git_sha": "f148f5384395618fc706b6e2f059bd1ce037d06c",
"installed_by": ["subworkflows"]
},
"fastq_bwa_mem_samblaster": {
Expand Down
16 changes: 11 additions & 5 deletions subworkflows/pfr/fasta_ltrretriever_lai/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 = [:]
Expand All @@ -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
}
30 changes: 28 additions & 2 deletions subworkflows/pfr/fasta_ltrretriever_lai/tests/main.nf.test
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 }
)
}
}
}

0 comments on commit f13a9e5

Please sign in to comment.