Matthias Zepper
09/03/2024, 4:09 PMChannel.fromSamplesheet() factory support an index ? So can I somehow straightforwardly add the line number of the sample sheet entry to the meta map?
I am asking because we would like to ensure that even if a sample ID is specified twice, we have a unique technical ID and combining it with the line number seemed like a straightforward approach.
At first, I just wanted to merge() the channel with a numeric Channel.of(0…length of sample sheet) , but apart from my inability to get that to work (because I fail to convert the value channel Channel.fromPath(file("samplesheet.csv")).countLines() to an Integer), this will not be deterministic and thus cause issues when resuming the pipeline.Arthur
09/03/2024, 4:12 PMfromSamplesheet can inject an index itself (feature request maybe!?) but I think the output from it might be deterministic and then something like the following may do the job?
ch = Channel.fromSamplesheet()
ch | toList()
| flatMap { it.withIndex().collect{ entry, idx -> [ entry[0] + [index: idx], entry[1] ] } }
| view
[[id:1, index:0], a]
[[id:2, index:1], b]
[[id:3, index:2], c]Matthias Zepper
09/03/2024, 4:19 PMMatthias Zepper
09/03/2024, 4:32 PMtoList().flatMap{ it.withIndex()} was what I needed:
Toy example:
ch_fruit = Channel.from("apple","mango", "banana", "banana","peach")
ch_fruit_unique = ch_fruit.toList().flatMap { it.withIndex().collect{ entry, idx -> [ "${entry}_${idx}"] }}
ch_fruit_unique.view()Nicolas Vannieuwkerke
09/04/2024, 8:17 AMsamplesheetToList() function that converts the samplesheet to a list. You can then add a unique ID based on the list index and convert that list to a channel using Channel.fromList()