Last active
June 20, 2017 13:26
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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}") } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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