Skip to content

Instantly share code, notes, and snippets.

@LukeGoodsell
Last active June 20, 2017 13:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LukeGoodsell/0352b1e626ddea721474f673bb2173e5 to your computer and use it in GitHub Desktop.
Save LukeGoodsell/0352b1e626ddea721474f673bb2173e5 to your computer and use it in GitHub Desktop.
Processing each item in a list of lists of items and re-nesting in Nextflow
#!/usr/bin/env nextflow
itemLists = [ [1, 2, 3, 4], [5, 6, 7], [8] ]
def groupIdx = 0
itemListChannel =
Channel
.from(itemLists)
.flatMap { it -> L:{ groupIdx++; it.collect { [ groupIdx, it ] } } }
process itemProcess {
input:
val item from itemListChannel
output:
val item into itemChannel
exec:
println("Performing itemProcess on ${item}")
}
itemChannel
.groupTuple(by: 0)
.flatMap { it -> [ it[1] ] }
.subscribe { println("receiving ${it}") }
#!/usr/bin/env nextflow
itemLists = [ [1, 2, 3, 4], [5, 6, 7], [8] ]
def groupIdx = 0
itemListChannel =
Channel
.from(itemLists)
.flatMap { it -> groupIdx++; itemIdx = 0; it.collect { [ groupIdx, ++itemIdx, it ] } }
process itemProcess {
input:
val item from itemListChannel
output:
val result into itemChannel
exec:
println("Performing itemProcess on ${item}")
key = item[0]
order = item[1]
value = item[2]
result = [key, [ order, value * 2] ]
}
itemChannel
.groupTuple(by: 0)
.flatMap { it2 -> [ it2[1].sort { it[0] }.collect { it[1] } ] }
.subscribe { println("receiving ${it}") }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment