Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nextflow runner: add runElse #786

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/main/resources/io/viash/runners/nextflow/channel/runEach.nf
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ def runEach(Map args) {
def toState_ = args.toState
def filter_ = args.filter
def runIf_ = args.runIf
def runElse_ = args.runElse
def id_ = args.id

assert !runIf_ || runIf_ instanceof Closure: "runEach: must pass a Closure to runIf."
assert !runElse_ || runElse_ instanceof Closure: "runElse: must pass a Closure to runElse."

workflow runEachWf {
take: input_ch
Expand Down Expand Up @@ -65,6 +67,15 @@ def runEach(Map args) {
chRun = id_ch
chPassthrough = Channel.empty()
}
def chPassthroughElse = null
if (runElse_){
chPassthroughElse = chPassthrough.map{tup ->
runElse_(tup[0], tup[1], comp_)
}
} else {
chPassthroughElse = Channel.empty()
}

def data_ch = chRun | map{tup ->
def new_data = tup[1]
if (fromState_ instanceof Map) {
Expand Down Expand Up @@ -105,7 +116,7 @@ def runEach(Map args) {
: out_ch

def return_ch = post_ch
| concat(chPassthrough)
| concat(chPassthroughElse)

return_ch
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def processWorkflowArgs(Map args, Map defaultWfArgs, Map meta) {
assert key ==~ /^[a-zA-Z_]\w*$/ : "Error in module '$key': Expected process argument 'key' to consist of only letters, digits or underscores. Found: ${key}"

// check for any unexpected keys
def expectedKeys = ["key", "directives", "auto", "map", "mapId", "mapData", "mapPassthrough", "filter", "runIf", "fromState", "toState", "args", "renameKeys", "debug"]
def expectedKeys = ["key", "directives", "auto", "map", "mapId", "mapData", "mapPassthrough", "filter", "runIf", "runElse", "fromState", "toState", "args", "renameKeys", "debug"]
def unexpectedKeys = workflowArgs.keySet() - expectedKeys
assert unexpectedKeys.isEmpty() : "Error in module '$key': unexpected arguments to the '.run()' function: '${unexpectedKeys.join("', '")}'"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,15 @@ def workflowFactory(Map args, Map defaultWfArgs, Map meta) {
chPassthrough = Channel.empty()
}

def chPassthroughElse = null
if (workflowArgs.runElse_){
chPassthroughElse = chPassthrough.map{tup ->
workflowArgs.runElse_(tup[0], tup[1])
}
} else {
chPassthroughElse = Channel.empty()
}

def chRunFiltered = workflowArgs.filter ?
chRun | filter{workflowArgs.filter(it)} :
chRun
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ workflow base {
])
| step1.run(
filter: { id, data -> id != "three" },
runIf: { id, data -> data.input.size() == 2 || id == "three" }
runIf: { id, data -> data.input.size() == 2 || id == "three" },
runElse: {it}
)
| view{"output: $it"}
| toSortedList{ a, b -> a[0] <=> b[0] }
Expand Down
Loading