Hi Folks , I Am trying to write nextflow subworkflow : for :
1- Trimming
2- Aligninig trimmed Reads
And unfortunately I didn’t know how to emit Trimmed reads which derived from sub-workflow n°1 to be used into the next sub-workflow n°2 ( Alignment )
Any Advice !
main.nf
Trimmming Subworkflow
Here my Triming subworkflowoutputs
Alignment Subworkflow
ERROR
@mribeirodantas what do suggest please
You have to call the TRIMMED
subworkflow so that there’s an output channel to be consumed by the Alignment
process. It’s what the error message is saying. Shouldn’t you have trimmedReads
where you typed TRIMMED.out.trimmedR
?
Yes I already create that channel but . Alignment subworkfkow don’t recognise it
I want to align Trim.outputs ( process under TRIMMD Subworkfkow)
TRIMMED SUBWORKFKOW
Alignment subworkfkow
Pictures aren’t the best way to share code. Please, share code blocks so I can know if these are all in the same file, for example. In the code you showed, I don’t see the subworkflows being called.
@mribeirodantas No they are not in the same file, They are organised like that :
├── data
│ ├── SRR519926_1.fastq
│ ├── SRR519926_2.fastq
│ ├── SRR519930_1.fastq
│ └── SRR519930_2.fastq
├── main.nf
├── modules
│ ├── Alignment.nf
│ ├── bwa_index.nf
│ ├── FASTQC.nf
│ └── TRIM.nf
├── Ref_genome
│ └── Ecoli.fa
├── samplemain.csv
└── subworkflows
├── alignmentsub.nf
├── RawQC_sub.nf
└── Trim&QC_Sub.nf
Main.nf
#!/usr/bin/env nextflow
// Params
params.reads = "$projectDir/samplemain.csv"
params.reference = "$projectDir/Ref_genome/*.{fasta,fa}"
params.outdir ="$projectDir/outdir"
params.cpus = 3
//Channels
reads = Channel.fromPath(params.reads, checkIfExists: true)
.splitCsv(header: true)
.map { row -> tuple(row.sampleId, file(row.read1), file(row.read2)) }
Channel.fromPath(params.reference)
.first()
.set {ref_file}
// Sub-Workflows
// Raw Reads QC :: nextflow
include { RAW_QC } from "./subworkflows/RawQC_sub.nf"
workflow Raw {
RAW_QC (reads)
}
// Trimming + QC check
include { TRIMMED } from "./subworkflows/Trim&QC_Sub.nf"
workflow Trim {
TRIMMED (reads)
}
// Mapping to Reference
include { ALIGNMENT } from "./subworkflows/alignmentsub.nf"
workflow Align {
ALIGNMENT (ref_file,TRIMMED)
}
Trimming Sub-Workflow
/*
========================================================================================
Trimming Sub-Workflow
========================================================================================
*/
include {Trimming} from '../modules/TRIM.nf' // Check raw reads Quality
include {QC_Trim} from '../modules/TRIM.nf' // Multiqc for raw reads
include {Multiqc_Trim} from '../modules/TRIM.nf' // Multiqc for raw reads
reads = Channel.fromPath(params.reads, checkIfExists: true)
.splitCsv(header: true)
.map { row -> tuple(row.sampleId, file(row.read1), file(row.read2)) }
workflow TRIMMED {
take:
reads
main:
Trimming(reads)
QC_Trim(Trimming.out.triMmed)
Multiqc_Trim(QC_Trim.out.collect())
emit:
trimmedR = Trimming.out.triMmed.collect()
trimmedR.view()
}
Alignment Sub-Workflow
/*
========================================================================================
Alignment Sub-Workflow
========================================================================================
*/
include {index } from '../modules/bwa_index.nf' // Index the reference
include {Alignment } from '../modules/Alignment.nf' // Alignment based-reference
include {TRIMMED } from '../subworkflows/Trim&QC_Sub.nf' // Trimming subworkflow
/* channels */
Channel.fromPath(params.reference)
.first()
.set { ref_file }
workflow ALIGNMENT {
take:
ref
trimmedReads
main :
index(ref_file)
Alignment(ref_file,index.out.indexes,TRIMMED.out.trimmedR)
}
ERROR
nextflow run main.nf -entry Align
N E X T F L O W ~ version 23.04.1
Launching `main.nf` [pedantic_jang] DSL2 - revision: 8bc364eb64
Access to 'TRIMMED.out' is undefined since the workflow 'TRIMMED' has not been invoked before accessing the output attribute
-- Check script './subworkflows/alignmentsub.nf' at line: 27 or see '.nextflow.log' file for more details
trimmedReads
isn’t a variable you can access everywhere, you need to use the output of TRIMMED in the input of ALIGNMENT. Here I have combined you examples to demonstrate this. See the anonymous workflow at the bottom:
include {Trimming } from '../modules/TRIM.nf' // Check raw reads Quality
include {QC_Trim } from '../modules/TRIM.nf' // Multiqc for raw reads
include {Multiqc_Trim} from '../modules/TRIM.nf' // Multiqc for raw reads
include {index } from '../modules/bwa_index.nf' // Index the reference
include {Alignment } from '../modules/Alignment.nf' // Alignment based-reference
include {TRIMMED } from '../subworkflows/Trim&QC_Sub.nf' // Trimming subworkflow
workflow TRIMMED {
take:
reads
main:
Trimming(reads)
QC_Trim(Trimming.out.triMmed)
Multiqc_Trim(QC_Trim.out.collect())
emit:
trimmedR = Trimming.out.triMmed.collect()
}
workflow ALIGNMENT {
take:
ref
trimmedReads
main:
index(ref_file)
Alignment(ref_file,index.out.indexes,TRIMMED.out.trimmedR)
}
workflow {
reads = Channel.fromPath(params.reads, checkIfExists: true)
.splitCsv(header: true)
.map { row -> tuple(row.sampleId, file(row.read1), file(row.read2)) }
ref_file = Channel.fromPath(params.reference)
.first()
TRIMMED(reads)
ALIGNMENT(ref_file, TRIMMED.out.trimmedR)
}