Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions subworkflows/nf-core/bcl_demultiplex/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ include { BCLCONVERT } from "../../../modules/nf-core/bclconvert/main"
include { BCL2FASTQ } from "../../../modules/nf-core/bcl2fastq/main"

// Define the log file path before the workflow starts
def logFile = new File("${params.outdir}/invalid_fastqs.log")
def logFile = file("${params.outdir}/empty_fastqs.log")

workflow BCL_DEMULTIPLEX {
take:
ch_flowcell // [[id:"", lane:""],samplesheet.csv, path/to/bcl/files]
demultiplexer // bclconvert or bcl2fastq
log_empty_fastqs // parameter to control the logging of empty FASTQs to a file

main:
ch_versions = Channel.empty()
Expand Down Expand Up @@ -85,13 +86,13 @@ workflow BCL_DEMULTIPLEX {

// This function appends a given text to a specified log file.
// If the log file does not exist, it creates a new one.
def appendToLogFile(String text, File logFile) {
if (!logFile.exists()) {
logFile.createNewFile()
}
def appendToLogFile(String text, Path logFile) {
// Convert the text to String if it's a GString
String textToWrite = text.toString()
logFile << textToWrite + "\n" // Appends the text to the file with a new line
// Append text to the log file
logFile.withWriterAppend { writer ->
writer.println(textToWrite) // Appends the text to the file with a new line
}
}

// Add meta values to fastq channel and skip invalid FASTQ files
Expand All @@ -118,12 +119,14 @@ def generate_fastq_meta(ch_reads, logFile) {
meta.readgroup = readgroup_from_fastq(fastq)
meta.readgroup.SM = meta.samplename
} else {
appendToLogFile(
"Empty or invalid FASTQ file: ${fastq}",
logFile
if (params.log_empty_fastqs) {
appendToLogFile(
"Empty or invalid FASTQ file: ${fastq}",
logFile
)
fastq = null
}
}
fastq = null
}

return [meta, fastq]
}.filter { it[0] != null }
Expand All @@ -132,8 +135,8 @@ def generate_fastq_meta(ch_reads, logFile) {
// Add meta.single_end
.map { meta, fastq ->
if (meta != null) {
meta.single_end = fastq.size() == 1
}
meta.single_end = fastq.size() == 1
}
return [meta, fastq.flatten()]
}
}
Expand Down