Skip to content

Commit

Permalink
Compute index only once
Browse files Browse the repository at this point in the history
  • Loading branch information
grst committed Jan 18, 2024
1 parent 533a0f3 commit 60052b6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 49 deletions.
27 changes: 7 additions & 20 deletions subworkflows/local/genome_quant.nf
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,19 @@ include { BOWTIE_MAP_SEQ as BOWTIE_MAP_GENOME } from '../../modules/local/bowtie

workflow GENOME_QUANT {
take:
fasta
index
bowtie_index
fasta_formatted // fasta as generated by bowtie index step
reads // channel: [ val(meta), [ reads ] ]

main:
ch_versions = Channel.empty()

if (!index){
INDEX_GENOME ( [ [:], fasta ] )
bowtie_index = INDEX_GENOME.out.index
fasta_formatted = INDEX_GENOME.out.fasta
ch_versions = ch_versions.mix(INDEX_GENOME.out.versions)
} else {
bowtie_index = Channel.fromPath("${index}**ebwt", checkIfExists: true).ifEmpty { exit 1, "Bowtie1 index directory not found: ${index}" }
fasta_formatted = fasta
}
BOWTIE_MAP_GENOME ( reads, bowtie_index.collect() )
ch_versions = ch_versions.mix(BOWTIE_MAP_GENOME.out.versions)

if (bowtie_index){
BOWTIE_MAP_GENOME ( reads, bowtie_index.collect() )
ch_versions = ch_versions.mix(BOWTIE_MAP_GENOME.out.versions)
fasta_formatted
.map { file -> tuple(file.baseName, file) }
.set { sort_input }
BAM_SORT_STATS_SAMTOOLS ( BOWTIE_MAP_GENOME.out.bam, sort_input )
ch_versions = ch_versions.mix(BAM_SORT_STATS_SAMTOOLS.out.versions)
}
ch_fasta_formatted_for_sort = fasta_formatted .map { file -> tuple(file.baseName, file) }
BAM_SORT_STATS_SAMTOOLS ( BOWTIE_MAP_GENOME.out.bam, ch_fasta_formatted_for_sort )
ch_versions = ch_versions.mix(BAM_SORT_STATS_SAMTOOLS.out.versions)

emit:
fasta = fasta_formatted
Expand Down
11 changes: 0 additions & 11 deletions subworkflows/local/umi_dedup.nf
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ include { CAT_CAT } from '../../modules/nf-core/cat/

workflow DEDUPLICATE_UMIS {
take:
fasta
bt_index
reads // channel: [ val(meta), [ reads ] ]
val_get_dedup_stats //boolean true/false
Expand All @@ -22,16 +21,6 @@ workflow DEDUPLICATE_UMIS {
ch_versions = Channel.empty()
ch_dedup_stats = Channel.empty()

if (!bt_index){
INDEX_GENOME ( [ [:], fasta ] )
bt_index = INDEX_GENOME.out.index
fasta_formatted = INDEX_GENOME.out.fasta
ch_versions = ch_versions.mix(INDEX_GENOME.out.versions)
} else {
fasta_formatted = fasta
}


UMI_MAP_GENOME ( reads, bt_index.collect() )
ch_versions = ch_versions.mix(UMI_MAP_GENOME.out.versions)

Expand Down
39 changes: 21 additions & 18 deletions workflows/smrnaseq.nf
Original file line number Diff line number Diff line change
Expand Up @@ -150,29 +150,32 @@ workflow SMRNASEQ {
)
ch_versions = ch_versions.mix(FASTQ_FASTQC_UMITOOLS_FASTP.out.versions)

ch_fasta = file(params.fasta)
reads_for_mirna = FASTQ_FASTQC_UMITOOLS_FASTP.out.reads

//Prepare bowtie index, unless specified
//This needs to be done here as the index is used by both UMI deduplication and GENOME_QUANT
if(params.bowtie_index) {
ch_bowtie_index = Channel.fromPath("${index}**ebwt", checkIfExists: true).ifEmpty { error "Bowtie1 index directory not found: ${index}" }
ch_fasta_formatted = ch_fasta
} else {
INDEX_GENOME ( [ [:], ch_fasta ] )
ch_versions = ch_versions.mix(INDEX_GENOME.out.versions)
ch_bowtie_index = INDEX_GENOME.out.index
ch_fasta_formatted = INDEX_GENOME.out.fasta
}

//
// SUBWORKFLOW: Deduplicate UMIs by mapping them to the genome
//
if (params.with_umi){
if (params.fasta){
fasta_ch = file(params.fasta)

//This needs to be done here as GENOME_QUANT should not run prior to the deduplication of UMIs.
INDEX_GENOME ( [ [:], fasta_ch ] )

ch_versions = ch_versions.mix(INDEX_GENOME.out.versions)

DEDUPLICATE_UMIS (
fasta_ch,
INDEX_GENOME.out.index,
FASTQ_FASTQC_UMITOOLS_FASTP.out.reads,
params.umi_stats
)
reads_for_mirna = DEDUPLICATE_UMIS.out.reads
ch_versions = ch_versions.mix(DEDUPLICATE_UMIS.out.versions)
}
DEDUPLICATE_UMIS (
ch_bowtie_index,
FASTQ_FASTQC_UMITOOLS_FASTP.out.reads,
params.umi_stats
)
reads_for_mirna = DEDUPLICATE_UMIS.out.reads
ch_versions = ch_versions.mix(DEDUPLICATE_UMIS.out.versions)
}


Expand Down Expand Up @@ -225,7 +228,7 @@ workflow SMRNASEQ {
//
genome_stats = Channel.empty()
if (params.fasta){
GENOME_QUANT ( file(params.fasta), params.bowtie_index, MIRNA_QUANT.out.unmapped )
GENOME_QUANT ( ch_bowtie_index, ch_fasta_formatted, MIRNA_QUANT.out.unmapped )
genome_stats = GENOME_QUANT.out.stats
ch_versions = ch_versions.mix(GENOME_QUANT.out.versions)

Expand Down

0 comments on commit 60052b6

Please sign in to comment.