@@ -228,7 +228,7 @@ if("${params.fasta}".endsWith(".gz")){
228228 file zipfasta from ch_unzip_fasta
229229
230230 output:
231- file " *.fasta" into (ch_fasta_for_bwa_indexing, ch_fasta_for_faidx_indexing, ch_fasta_for_dict_indexing, ch_fasta_for_bwa_mapping, ch_fasta_for_damageprofiler, ch_fasta_for_qualimap, ch_fasta_for_pmdtools, ch_fasta_for_circularmapper, ch_fasta_for_circularmapper_index,ch_fasta_for_bwamem_mapping )
231+ file " *.fasta" into (ch_fasta_for_bwa_indexing, ch_fasta_for_faidx_indexing, ch_fasta_for_dict_indexing, ch_fasta_for_damageprofiler, ch_fasta_for_qualimap, ch_fasta_for_pmdtools, ch_fasta_for_circularmapper_index)
232232
233233 script:
234234 """
@@ -238,7 +238,7 @@ if("${params.fasta}".endsWith(".gz")){
238238 } else {
239239 Channel . fromPath(" ${ params.fasta} " )
240240 .ifEmpty { exit 1 , " No genome specified! Please specify one with --fasta" }
241- .into {ch_fasta_for_bwa_indexing;ch_fasta_for_faidx_indexing;ch_fasta_for_dict_indexing; ch_fasta_for_bwa_mapping; ch_fasta_for_damageprofiler; ch_fasta_for_qualimap; ch_fasta_for_pmdtools; ch_fasta_for_circularmapper; ch_fasta_for_circularmapper_index;ch_fasta_for_bwamem_mapping }
241+ .into {ch_fasta_for_bwa_indexing;ch_fasta_for_faidx_indexing;ch_fasta_for_dict_indexing; ch_fasta_for_damageprofiler; ch_fasta_for_qualimap; ch_fasta_for_pmdtools; ch_fasta_for_circularmapper_index}
242242}
243243
244244
@@ -253,14 +253,10 @@ if (params.aligner != 'bwa' && !params.circularmapper && !params.bwamem){
253253}
254254if ( params. bwa_index && (params. aligner == ' bwa' | params. bwamem)){
255255 bwa_index = Channel
256- .fromPath(" ${ params.bwa_index} /**.*" )
257- .ifEmpty { exit 1 , " BWA index not found: ${ params.bwa_index} " }
258- .into{ch_bwa_index_existing;ch_bwa_index_bwamem_existing}
259- } else {
260- // Create empty channels to make sure later mix() does not fail
261- ch_bwa_index_existing = Channel . empty()
262- ch_bwa_index_bwamem_existing = Channel . empty()
263- }
256+ .fromPath(" ${ params.bwa_index} " ,checkIfExists : true )
257+ .ifEmpty { exit 1 , " BWA index not found: ${ params.bwa_index} " }
258+ .into{ch_bwa_index;ch_bwa_index_bwamem}
259+ }
264260
265261// Validate that either pairedEnd or singleEnd has been specified by the user!
266262if ( params. singleEnd || params. pairedEnd ){
@@ -376,6 +372,9 @@ ${summary.collect { k,v -> " <dt>$k</dt><dd><samp>${v ?: '<span style
376372/*
377373* Create BWA indices if they are not present
378374*/
375+
376+ if (! params. bwa_index && params. fasta && (params. aligner == ' bwa' || params. bwamem)) {
377+
379378process makeBWAIndex {
380379 tag {fasta}
381380 publishDir path: " ${ params.outdir} /reference_genome/bwa_index" , mode: ' copy' , saveAs: { filename ->
@@ -391,15 +390,20 @@ process makeBWAIndex {
391390 file wherearemyfiles from ch_where_for_bwa_index
392391
393392 output:
394- file " *.{amb,ann,bwt,pac,sa,fasta,fa} " into (ch_bwa_index,ch_bwa_index_bwamem)
393+ file " bwa_index " into (ch_bwa_index,ch_bwa_index_bwamem)
395394 file " where_are_my_files.txt"
396395
397396 script:
398397 """
398+ mkdir bwa_index
399+ cp "${ fasta} " bwa_index/
400+ cd bwa_index
399401 bwa index $fasta
400402 """
401403}
402404
405+ }
406+
403407
404408/*
405409 * PREPROCESSING - Index Fasta file if not specified on CLI
@@ -581,8 +585,7 @@ process bwa {
581585
582586 input:
583587 file(reads) from ch_clipped_reads
584- file " *" from ch_bwa_index. mix(ch_bwa_index_existing). collect()
585- file fasta from ch_fasta_for_bwa_mapping
588+ file index from ch_bwa_index. first()
586589
587590 output:
588591 file " *.sorted.bam" into ch_mapped_reads_idxstats,ch_mapped_reads_filter,ch_mapped_reads_preseq, ch_mapped_reads_damageprofiler
@@ -591,6 +594,7 @@ process bwa {
591594
592595 script:
593596 prefix = reads[0 ]. toString() - ~/ (_R1)? (\. combined\. )? (prefixed)? (_trimmed)? (_val_1)? (\. fq)? (\. fastq)? (\. gz)? $/
597+ fasta = " ${ index} /*.fasta"
594598 """
595599 bwa aln -t ${ task.cpus} $fasta $reads -n ${ params.bwaalnn} -l ${ params.bwaalnl} -k ${ params.bwaalnk} -f "${ reads.baseName} .sai"
596600 bwa samse -r "@RG\\ tID:ILLUMINA-${ prefix} \\ tSM:${ prefix} \\ tPL:illumina" $fasta "${ reads.baseName} ".sai $reads | samtools sort -@ ${ task.cpus} -O bam - > "${ prefix} ".sorted.bam
@@ -612,12 +616,16 @@ process circulargenerator{
612616 file fasta from ch_fasta_for_circularmapper_index
613617
614618 output:
615- file " *.fasta* " into ch_circularmapper_indices
619+ file " cm_index " into ch_circularmapper_indices
616620
617621 script:
622+ prefix = " ${ fasta.baseName} _${ params.circularextension} .fasta"
618623 """
624+ mkdir cm_index
619625 circulargenerator -e ${ params.circularextension} -i $fasta -s ${ params.circulartarget}
620- bwa index "${ fasta.baseName} _${ params.circularextension} .fasta"
626+ cp "${ fasta.baseName} _${ params.circularextension} .fasta" cm_index/
627+ cd cm_index
628+ bwa index $prefix
621629 """
622630
623631}
@@ -631,8 +639,7 @@ process circularmapper{
631639
632640 input:
633641 file reads from ch_clipped_reads_circularmapper
634- file fasta from ch_fasta_for_circularmapper
635- file " *" from ch_circularmapper_indices
642+ file index from ch_circularmapper_indices. first()
636643
637644 output:
638645 file " *.sorted.bam" into ch_mapped_reads_idxstats_cm,ch_mapped_reads_filter_cm,ch_mapped_reads_preseq_cm, ch_mapped_reads_damageprofiler_cm
@@ -641,9 +648,11 @@ process circularmapper{
641648 script:
642649 filter = " ${ params.circularfilter} " ? ' ' : ' -f true -x false'
643650 prefix = reads[0 ]. toString() - ~/ (_R1)? (\. combined\. )? (prefixed)? (_trimmed)? (_val_1)? (\. fq)? (\. fastq)? (\. gz)? $/
651+ fasta = " ${ index} /*_*.fasta"
652+
644653 """
645- bwa aln -t ${ task.cpus} " ${ fasta.baseName } _ ${ params.circularextension } .fasta" $reads -n ${ params.bwaalnn} -l ${ params.bwaalnl} -k ${ params.bwaalnk} -f "${ reads.baseName} .sai"
646- bwa samse -r "@RG\\ tID:ILLUMINA-${ prefix} \\ tSM:${ prefix} \\ tPL:illumina" " ${ fasta.baseName } _ ${ params.circularextension } .fasta" "${ reads.baseName} ".sai $reads > tmp.out
654+ bwa aln -t ${ task.cpus} $ fasta $reads -n ${ params.bwaalnn} -l ${ params.bwaalnl} -k ${ params.bwaalnk} -f "${ reads.baseName} .sai"
655+ bwa samse -r "@RG\\ tID:ILLUMINA-${ prefix} \\ tSM:${ prefix} \\ tPL:illumina" $ fasta "${ reads.baseName} ".sai $reads > tmp.out
647656 realignsamfile -e ${ params.circularextension} -i tmp.out -r $fasta $filter
648657 samtools sort -@ ${ task.cpus} -O bam tmp_realigned.bam > "${ prefix} ".sorted.bam
649658 samtools index "${ prefix} ".sorted.bam
@@ -658,8 +667,7 @@ process bwamem {
658667
659668 input:
660669 file(reads) from ch_clipped_reads_bwamem
661- file " *" from ch_bwa_index_bwamem. mix(ch_bwa_index_bwamem_existing). collect()
662- file fasta from ch_fasta_for_bwamem_mapping
670+ file index from ch_bwa_index_bwamem. first()
663671
664672 output:
665673 file " *.sorted.bam" into ch_bwamem_mapped_reads_idxstats,ch_bwamem_mapped_reads_filter,ch_bwamem_mapped_reads_preseq, ch_bwamem_mapped_reads_damageprofiler
@@ -668,6 +676,7 @@ process bwamem {
668676
669677 script:
670678 prefix = reads[0 ]. toString() - ~/ (_R1)? (\. combined\. )? (prefixed)? (_trimmed)? (_val_1)? (\. fq)? (\. fastq)? (\. gz)? $/
679+ fasta = " ${ index} /*.fasta"
671680 """
672681 bwa mem -t ${ task.cpus} $fasta $reads -R "@RG\\ tID:ILLUMINA-${ prefix} \\ tSM:${ prefix} \\ tPL:illumina" | samtools sort -@ ${ task.cpus} -O bam - > "${ prefix} ".sorted.bam
673682 samtools index -@ ${ task.cpus} "${ prefix} ".sorted.bam
@@ -1077,7 +1086,7 @@ process multiqc {
10771086 file (' damageprofiler/*' ) from ch_damageprofiler_results. collect(). ifEmpty([])
10781087 file (' qualimap/*' ) from ch_qualimap_results. collect(). ifEmpty([])
10791088 file (' markdup/*' ) from ch_markdup_results_for_multiqc. collect(). ifEmpty([])
1080- file (' dedup/*' ) from ch_dedup_results_for_multiqc. collect(). ifEmpty([])
1089+ file (' dedup* /*' ) from ch_dedup_results_for_multiqc. collect(). ifEmpty([])
10811090 file (' fastp/*' ) from ch_fastp_for_multiqc. collect(). ifEmpty([])
10821091
10831092 file workflow_summary from create_workflow_summary(summary)
0 commit comments