Skip to content

Commit

Permalink
Also remove renameKeys
Browse files Browse the repository at this point in the history
  • Loading branch information
DriesSchaumont committed Dec 26, 2024
1 parent 603c756 commit 70aecf5
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 46 deletions.
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" "filter", "runIf", "fromState", "toState", "args", "renameKeys", "debug"]
def expectedKeys = ["key", "directives", "auto" "filter", "runIf", "fromState", "toState", "args", "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 @@ -21,19 +21,6 @@ def workflowFactory(Map args, Map defaultWfArgs, Map meta) {
| _debug(workflowArgs, "input")
| map { tuple ->
tuple = deepClone(tuple)

if (workflowArgs.map) {
tuple = workflowArgs.map(tuple)
}
if (workflowArgs.mapId) {
tuple[0] = workflowArgs.mapId(tuple[0])
}
if (workflowArgs.mapData) {
tuple[1] = workflowArgs.mapData(tuple[1])
}
if (workflowArgs.mapPassthrough) {
tuple = tuple.take(2) + workflowArgs.mapPassthrough(tuple.drop(2))
}

// check tuple
assert tuple instanceof List :
Expand Down Expand Up @@ -73,33 +60,6 @@ def workflowFactory(Map args, Map defaultWfArgs, Map meta) {
" Example: [\"id\", [input: file('foo.txt'), arg: 10]].\n" +
" Expected class: Map. Found: tuple[1].getClass() is ${tuple[1].getClass()}"

// rename keys of data field in tuple
if (workflowArgs.renameKeys) {
assert workflowArgs.renameKeys instanceof Map :
"Error renaming data keys in module '${key_}' id '${tuple[0]}'.\n" +
" Example: renameKeys: ['new_key': 'old_key'].\n" +
" Expected class: Map. Found: renameKeys.getClass() is ${workflowArgs.renameKeys.getClass()}"
assert tuple[1] instanceof Map :
"Error renaming data keys in module '${key_}' id '${tuple[0]}'.\n" +
" Expected class: Map. Found: tuple[1].getClass() is ${tuple[1].getClass()}"

// TODO: allow renameKeys to be a function?
workflowArgs.renameKeys.each { newKey, oldKey ->
assert newKey instanceof CharSequence :
"Error renaming data keys in module '${key_}' id '${tuple[0]}'.\n" +
" Example: renameKeys: ['new_key': 'old_key'].\n" +
" Expected class of newKey: String. Found: newKey.getClass() is ${newKey.getClass()}"
assert oldKey instanceof CharSequence :
"Error renaming data keys in module '${key_}' id '${tuple[0]}'.\n" +
" Example: renameKeys: ['new_key': 'old_key'].\n" +
" Expected class of oldKey: String. Found: oldKey.getClass() is ${oldKey.getClass()}"
assert tuple[1].containsKey(oldKey) :
"Error renaming data keys in module '${key}' id '${tuple[0]}'.\n" +
" Key '$oldKey' is missing in the data map. tuple[1].keySet() is '${tuple[1].keySet()}'"
tuple[1].put(newKey, tuple[1][oldKey])
}
tuple[1].keySet().removeAll(workflowArgs.renameKeys.collect{ newKey, oldKey -> oldKey })
}
tuple
}

Expand Down
5 changes: 0 additions & 5 deletions src/main/scala/io/viash/runners/nextflow/NextflowHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,6 @@ object NextflowHelper {
| // Example: `{ tup -> tup[0] != "skip_this" }`
| runIf: null,
|
| // Rename keys in the data field of the tuple (i.e. the second element)
| // Will likely be deprecated in favour of `fromState`.
| // Example: `[ "new_key": "old_key" ]`
| renameKeys: null,
|
| // Fetch data from the state and pass it to the module without altering the current state.
| //
| // `fromState` should be `null`, `List[String]`, `Map[String, String]` or a function.
Expand Down

0 comments on commit 70aecf5

Please sign in to comment.