Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,32 @@ private List<Tuple2<String, Map<String, Object>>> _paramsToParamSets(Map params,
// todo: fetch key from run args
def key_ = config.name

def allowedExtra = [
"override_container_registry",
"publishDir",
"publish-dir",
"publish_dir",
"transcripts-dir",
"transcriptsDir",
"param_list",
"id"
]
/* parse regular parameters (not in param_list) */
/*************************************************/
def globalParams = config.allArguments
.findAll { params.containsKey(it.plainName) }
.collectEntries { [ it.plainName, params[it.plainName] ] }
// Get the non-overwrite params. This could result in false negatives:
// these arguments are not checked for validity.
// Note that overrides can only be set in `params` and not through an
// entry in param_list.
def nonOverwriteParams = params.findAll{k, v -> !k.contains("__")}
// When the parameter name is formatted using camelCase,
// a second parameter is created with the same value using
// kebab-case, and vice versa.
def configParamNames = config.allArguments.collect{it.plainName}
def leftover = nonOverwriteParams.keySet().collect() - configParamNames - allowedExtra
assert leftover.isEmpty(): "Found invalid parameter(s) for ${key_}: ${leftover}"
def globalID = params.get("id", null)

/* process params_list arguments */
Expand Down Expand Up @@ -66,6 +87,9 @@ private List<Tuple2<String, Map<String, Object>>> _paramsToParamSets(Map params,
}
assert id != null: "Each parameter set should have at least an 'id'"

def extraArgs = tup[1].keySet().collect() - ["id"] - configParamNames
assert extraArgs.isEmpty(): "Found invalid parameter(s) in param_list, id ${id}: ${extraArgs}"

// Process params
def parValues = globalParams + tup[1]
// // Remove parameters which are null, if the default is also null
Expand Down
16 changes: 16 additions & 0 deletions src/test/scala/io/viash/runners/nextflow/NextflowScriptTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,22 @@ class NextflowScriptTest extends AnyFunSuite with BeforeAndAfterAll {
assert(exitCode == 0, s"\nexit code was $exitCode\nStd output:\n$stdOut\nStd error:\n$stdErr")
}

test("Test nonexistant parameter fails", NextflowTest) {
val (exitCode, stdOut, stdErr) = NextflowTestHelper.run(
mainScript = "target/nextflow/wf/main.nf",
args = List(
"--id", "foo",
"--input1", "resources/lines*.txt",
"--input2", "resources/lines3.txt",
"--publish_dir", "output",
"--nonexistant", "bar",
),
cwd = tempFolFile
)
assert(stdOut.contains("Found invalid parameter(s) for"))
assert(exitCode == 1, s"\nexit code was $exitCode\nStd output:\n$stdOut\nStd error:\n$stdErr")
}

test("Run config pipeline with symlink", NextflowTest) {
val newWorkflowPath = Paths.get(tempFolStr, "workflowsAsSymlink")
Files.createDirectories(newWorkflowPath)
Expand Down
26 changes: 26 additions & 0 deletions src/test/scala/io/viash/runners/nextflow/WorkflowHelperTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,32 @@ class WorkflowHelperTest extends AnyFunSuite with BeforeAndAfterAll {
)
}

test("Run config pipeline with yamlblob and invalid parameter", NextflowTest) {
val fooArgs =
"{id: foo, input: resources/lines3.txt, whole_number: 3, optional_with_default: foo, multiple: [a, b, c], doesnotexist: lorem}"
val barArgs =
"{id: bar, input: resources/lines5.txt, real_number: 0.5, optional: bar, reality: true}"

val (exitCode, stdOut, stdErr) = NextflowTestHelper.run(
mainScript = "workflows/pipeline3/main.nf",
entry = Some("base"),
args = List(
"--param_list", s"[$fooArgs, $barArgs]",
"--real_number", "10.5",
"--whole_number", "10",
"--str", "foo",
"--publish_dir", "output",
),
cwd = tempFolFile
)
assert(stdOut.contains("Found invalid parameter(s) for"))
assert(
exitCode == 1,
s"\nexit code was $exitCode\nStd output:\n$stdOut\nStd error:\n$stdErr"
)

}

test("Run config pipeline with yaml file", NextflowTest) {
val param_list_file =
Paths.get(resourcesPath, "pipeline3.yaml").toFile.toString
Expand Down
Loading