Skip to content

Commit

Permalink
Revert "Remove necessity of meta.id_alt key"
Browse files Browse the repository at this point in the history
This reverts commit 66a2b48.
  • Loading branch information
sgsutcliffe committed Sep 23, 2024
1 parent d23da98 commit 1419462
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
2 changes: 1 addition & 1 deletion assets/schema_input.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions tests/workflows/snvphylnfc.nf.test
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down
30 changes: 13 additions & 17 deletions workflows/snvphylnfc.nf
Original file line number Diff line number Diff line change
Expand Up @@ -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 "_"
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 1419462

Please sign in to comment.