You can modify your Nextflow process to choose the appropriate Trimmomatic adapter based on the prefix of the sample name. Here's an updated version of your TRIMMOMATIC process, where I included a logic for setting adapters via a conditional check. You will still need to adjust the adapter file paths according to where they are stored in your file system:
#!/usr/bin/env nextflow
nextflow.enable.dsl=2
params.trimmomatic_path = '/path/to/trimmomatic/jar' // Update this path
params.adapters_path = '/path/to/trimmomatic/adapters' // Update this path
process TRIMMOMATIC {
cpus 6
input:
tuple val(sample), path(fastq)
val metadata
output:
tuple val(sample), path("*.paired.trim*.fastq.gz"), emit: trim_paired
script:
def adapter_file = ''
if (sample.startsWith('DL_LTE_rn1_')) {
adapter_file = "${params.adapters_path}/NexteraPE-PE.fa"
} else if (sample.startsWith('ara')) {
adapter_file = "${params.adapters_path}/NexteraPE-PE.fa"
} else if (sample.startsWith('batch')) {
adapter_file = "${params.adapters_path}/NexteraPE-PE.fa"
} else if (sample.startsWith('CL')) {
adapter_file = "${params.adapters_path}/NexteraPE-PE.fa"
} else if (sample.startsWith('SRR') || sample.startsWith('ERR')) {
adapter_file = "${params.adapters_path}/TruSeq3-PE-2.fa"
} else {
// Set default adapter or raise an error
adapter_file = "${params.adapters_path}/default-adapter.fa" // Update this line
}
"""
trimmomatic PE \\
-threads ${task.cpus} \\
${fastq[0]} ${fastq[1]} \\
${sample}.paired.trim_1.fastq.gz ${sample}.unpaired.trim_1.fastq.gz \\
${sample}.paired.trim_2.fastq.gz ${sample}.unpaired.trim_2.fastq.gz \\
-phred33 \\
ILLUMINACLIP:${adapter_file}:2:30:10:2:'false' \\
SLIDINGWINDOW:4:20 MINLEN:30
rm ${sample}.unpaired.trim_1.fastq.gz ${sample}.unpaired.trim_2.fastq.gz
"""
}
Make sure you adjust the paths to TRIMMOMATIC and adapters directory according to your setup by editing params.trimmomatic_path and params.adapters_path. This updated script uses Groovy's string interpolation and Nextflow's process variables to set the adapter_file based on your samples' naming convention.
This approach assumes you're using a consistent naming scheme for your samples, and it selects the appropriate adapter sequence file based on the naming scheme. If a sample does not match any of the predefined prefixes, you can either set a default adapter or raise an error depending on how you want to handle such cases.