From 1419462906487a5d6e895586d8897898b67c31dc Mon Sep 17 00:00:00 2001 From: Steven Sutcliffe Date: Mon, 23 Sep 2024 17:34:24 -0400 Subject: [PATCH] Revert "Remove necessity of meta.id_alt key" This reverts commit 66a2b48afb3e3c82916be037e9d17c2d51321c9d. --- assets/schema_input.json | 2 +- tests/workflows/snvphylnfc.nf.test | 4 ++-- workflows/snvphylnfc.nf | 30 +++++++++++++----------------- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/assets/schema_input.json b/assets/schema_input.json index 9e3f9e8..714cda3 100644 --- a/assets/schema_input.json +++ b/assets/schema_input.json @@ -16,7 +16,7 @@ }, "sample_name": { "type": "string", - "meta": ["id"], + "meta": ["id", "id_alt"], "errorMessage": "Sample name is optional, if provided will replace sample for filenames and outputs" }, "fastq_1": { diff --git a/tests/workflows/snvphylnfc.nf.test b/tests/workflows/snvphylnfc.nf.test index fbb60f1..37e6006 100644 --- a/tests/workflows/snvphylnfc.nf.test +++ b/tests/workflows/snvphylnfc.nf.test @@ -75,11 +75,11 @@ nextflow_workflow { } test("selecting reference by sample id") { - tag "ref_sample_id" + when { params { input = "$baseDir/assets/samplesheet.csv" - reference_sample_id = "A 1#" + reference_sample_id = "A_1_" outdir = "results" } workflow {} diff --git a/workflows/snvphylnfc.nf b/workflows/snvphylnfc.nf index 13e78bf..e704b64 100644 --- a/workflows/snvphylnfc.nf +++ b/workflows/snvphylnfc.nf @@ -95,20 +95,7 @@ workflow SNVPHYL { // or [meta, [fastq_1, fastq_2], reference_assembly] if fastq_2 exists // and remove non-alphanumeric characters in sample_names (meta.id), whilst also correcting for duplicate sample_names (meta.id) .map { meta, fastq_1, fastq_2, reference_assembly -> - fastq_2 ? tuple(meta, [ file(fastq_1), file(fastq_2) ], reference_assembly) : - tuple(meta, [ file(fastq_1) ], file(reference_assembly))} - - // Channel of read tuples (meta, [fastq_1, fastq_2*]): - reads = input.map { meta, reads, reference_assembly -> tuple(meta, reads) } - - // Channel of sample tuples (meta, assembly): - sample_assemblies = input.map { meta, reads, reference_assembly -> tuple(meta, reference_assembly ? reference_assembly : null) } - - reference_genome = select_reference(params.refgenome, params.reference_sample_id, sample_assemblies) - - // Ensure that, if 'meta.id' is supplied that follows it is appropriate for the pipeline - input = input.map { meta, reads, reference_assembly -> - if (!meta.id) { + if (!meta.id) { meta.id = meta.irida_id } else { // Non-alphanumeric characters (excluding _,-,.) will be replaced with "_" @@ -121,8 +108,17 @@ workflow SNVPHYL { // Add the ID to the set of processed IDs processedIDs << meta.id - return [meta, reads, reference_assembly] - } + fastq_2 ? tuple(meta, [ file(fastq_1), file(fastq_2) ], reference_assembly) : + tuple(meta, [ file(fastq_1) ], file(reference_assembly))} + + + // Channel of read tuples (meta, [fastq_1, fastq_2*]): + reads = input.map { meta, reads, reference_assembly -> tuple(meta, reads) } + + // Channel of sample tuples (meta, assembly): + sample_assemblies = input.map { meta, reads, reference_assembly -> tuple(meta, reference_assembly ? reference_assembly : null) } + + reference_genome = select_reference(params.refgenome, params.reference_sample_id, sample_assemblies) INDEXING( reference_genome @@ -266,7 +262,7 @@ def select_reference(refgenome, reference_sample_id, sample_assemblies) { } else if (reference_sample_id) { // Check each meta category (meta.id, meta.id_alt, meta.irida_id) for a match to params.reference_sample_id - reference_genome = sample_assemblies.filter { (it[0].id == reference_sample_id || it[0].irida_id == reference_sample_id) && it[1] != null} + reference_genome = sample_assemblies.filter { (it[0].id == reference_sample_id || it[0].irida_id == reference_sample_id || it[0].id_alt == reference_sample_id) && it[1] != null} .ifEmpty { error("The provided reference sample ID (${reference_sample_id}) is either missing or has no associated reference assembly.") } .map { it[1] } .first()