Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename FASTQ files and check sample ids #145

Merged
merged 4 commits into from
Dec 17, 2020
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### `Changed`

- [#143](https://github.com/nf-core/mag/pull/143) - Changed format of manifest file, has to be handed over via `--input` parameter as well now
- [#145](https://github.com/nf-core/mag/pull/145) - When using TSV input files, uses sample IDs now for `FastQC` instead of basenames of original read files. Allows non-unique file basenames.

### `Deprecated`

Expand Down
42 changes: 38 additions & 4 deletions main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,11 @@ if(hasExtension(params.input, "tsv")){
exit 1, "Input TSV file contains row with ${row.size()} column(s). Expects 4 or 5."
}
}
.into { ch_all_files_sr; ch_all_files_lr }
.into { ch_sample_validate; ch_all_files_sr; ch_all_files_lr }
// prepare input for preprocessing
ch_all_files_sr
.map { row -> [ row[0], [ row[2], row[3] ] ] }
.into { ch_raw_short_reads_fastqc; ch_raw_short_reads_fastp }
.set { ch_raw_short_reads }
ch_all_files_lr
.map { row -> if (row.size() == 5) [ row[0], row[4] ] }
.set { ch_raw_long_reads }
Expand All @@ -178,14 +178,14 @@ if(hasExtension(params.input, "tsv")){
.from(params.input_paths)
.map { row -> [ row[0], [ file(row[1][0], checkIfExists: true) ] ] }
.ifEmpty { exit 1, "params.input_paths was empty - no input files supplied" }
.into { ch_raw_short_reads_fastqc; ch_raw_short_reads_fastp }
.into { ch_sample_validate; ch_raw_short_reads }
ch_raw_long_reads = Channel.from()
} else {
Channel
.from(params.input_paths)
.map { row -> [ row[0], [ file(row[1][0], checkIfExists: true), file(row[1][1], checkIfExists: true) ] ] }
.ifEmpty { exit 1, "params.input_paths was empty - no input files supplied" }
.into { ch_raw_short_reads_fastqc; ch_raw_short_reads_fastp }
.into { ch_sample_validate; ch_raw_short_reads }
ch_raw_long_reads = Channel.from()
}
} else {
Expand All @@ -196,6 +196,12 @@ if(hasExtension(params.input, "tsv")){
ch_raw_long_reads = Channel.from()
}

// Ensure sample IDs are unique
ch_sample_validate
.map { row -> row[0] }
.toList()
.map{ ids -> if( ids.size() != ids.unique().size() ) {exit 1, "ERROR: input contains duplicated sample IDs!" } }

// Check if specified cpus for SPAdes are available
if ( params.spades_fix_cpus && params.spades_fix_cpus > params.max_cpus )
exit 1, "Invalid parameter '--spades_fix_cpus ${params.spades_fix_cpus}', max cpus are '${params.max_cpus}'."
Expand Down Expand Up @@ -444,6 +450,34 @@ process get_software_versions {
"""
}

// required for FastQC and MultiQC: to ensure consistent naming for reports using sample IDs and allow non-unique file basenames with TSV input
process rename_short_read_fastqs {
tag "$name"

input:
set val(name), file(reads) from ch_raw_short_reads

output:
set val(name), path("${name}{_R1,_R2,}.fastq.gz", includeInputs: true) into (ch_raw_short_reads_fastqc, ch_raw_short_reads_fastp)

script:
if ( !params.single_end )
"""
if ! [ -f "${name}_R1.fastq.gz" ]; then
ln -s "${reads[0]}" "${name}_R1.fastq.gz"
fi
if ! [ -f "${name}_R2.fastq.gz" ]; then
ln -s "${reads[1]}" "${name}_R2.fastq.gz"
fi
"""
else
"""
if ! [ -f "${name}.fastq.gz" ]; then
ln -s "${reads}" "${name}.fastq.gz"
fi
"""
}

/*
================================================================================
Preprocessing and QC for short reads
Expand Down