Does the `Channel.fromSamplesheet()` factory supp...
# nf-schema
m
Does the
Channel.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.
a
I don’t believe
fromSamplesheet
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?
Copy code
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]
👀 1
m
Thanks a lot, I will experiment in that direction!
Wonderful, the
toList().flatMap{ it.withIndex()}
was what I needed: Toy example:
Copy code
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()
👍 2
n
Alternatively you could also migrate to nf-schema which has a
samplesheetToList()
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()
🙏 1