I am trying to add a function to my Plugin that us...
# nextflow-plugins
s
I am trying to add a function to my Plugin that uses the `params`and
workflow
objects from the current Nextflow run to generate some pre-formatted text however when I write the function, I am doing it like this;
Copy code
@Function
    String makeTable(Map params, Map workflow, Map manifest, List bad_params){
}
I am not sure if this is the best way to write the function? Should I be passing the
params
and
workflow
objects as input args to the function? It seems like it might not be a great idea to try to get them from implicit environment variables at runtime. However since I am typing these input args as
Map
I am not sure if this is gonna actually break in my Nextflow pipeline when I use it like this
Copy code
include { makeTable } from 'plugin/nf-myutils'
makeTable(params: params, workflow: workflow, manifest: workflow.manifest, bad_params: ['foo_key'])
it keeps breaking with errors like this
Copy code
nextflow.exception.MissingProcessException: Missing process or function makeTable([[params:[:], workflow:repository: null, projectDir: /Users/.../examples, commitId: null, revision: null, startTime: 2024-03-21T15:12:05.581281-04:00, endTime: null, duration: null, container: {}, commandLine: nextflow run examples/test.nf, nextflow: nextflow.NextflowMeta(version:23.10.1, build:5891, timestamp:12-01-2024 22:01 UTC, preview:nextflow.NextflowMeta$Preview@35d60381, enable:nextflow.NextflowMeta$Features@68ab6ab0, dsl2:true, dsl2Final:true, strictModeEnabled:false), success: false, workDir: /Users/.../work, launchDir: /Users/.../nf-myutils, profile: standard, manifest:nextflow.config.Manifest@5c4cc644, bad_params:[foo_key]]]) -- Did you mean 'makeTable' instead?
not sure what is wrong with this? Does it not like the typing of the Nextflow
params
and
workflow
objects I am trying to pass?
j
You're using python syntax Try with
Copy code
include { makeTable } from 'plugin/nf-myutils' 

makeTable(params, workflow, workflow.manifest, ['foo_key'])
s
I tried that and it gives the same error
Copy code
makeTable(params, workflow, workflow.manifest, ['foo_key'])
gives
Copy code
Missing process or function makeTable([[:], repository: null, projectDir: /Users/.../examples, commitId: null, revision: null, startTime: 2024-03-21T15:53:28.814071-04:00, endTime: null, duration: null, container: {}, commandLine: nextflow run examples/test.nf, nextflow: nextflow.NextflowMeta(version:23.10.1, build:5891, timestamp:12-01-2024 22:01 UTC, preview:nextflow.NextflowMeta$Preview@4dfe8b37, enable:nextflow.NextflowMeta$Features@11dcd42c, dsl2:true, dsl2Final:true, strictModeEnabled:false), success: false, workDir: /Users/.../work, launchDir: /Users/.../, profile: standard, nextflow.config.Manifest@3c81cd82, [foo_key]]) -- Did you mean 'makeTable' instead?
maybe I need to convert
params
and
workflow
into
Map
objects? not sure
j
Try to simplify and increase step by step. Fisrt try without args, next with param and so on.
s
well it works in the test case...
Copy code
def 'should return a workflow table' () {
        given:
        def example = new ExampleFunctions()
        example.init(new Session([:]))
        def params = ['foo': 1, 'bar': 2, "buzzzz": 5]
        def bad_params = ["buzzzz"]
        def workflow = ['baz': 3]
        def manifest = ['buzz': 4]
        def expected = """
some text goes here
"""
        when:
        def result = example.makeTable(params, workflow, manifest, bad_params)
        println result

        then:
        result == expected
    }
yea in the Nextflow script if I change it to take no args, it works, but as soon as I try to pass args, it breaks.
for example the included
randomString()
function also works.
I am suspecting that maybe it has something to do with the
@Function
decorator or something like that, it seems to be breaking arg passing to the function
because no matter what args I pass in, it keeps reporting in the error log that the input arg was a list of some sort
Copy code
println makeTable(1)
Copy code
Missing process or function makeTable([1]) -- Did you mean 'makeTable' instead?
j
Strange Maybe nextflow version? If you can share the repo maybe I can take a look tomorrow
s
its here https://github.com/stevekm/nf-niceutils I can build and test fine
Copy code
./gradlew test
but when I try to run in a real pipeline, its giving these errors shown
Copy code
./nextflow run examples/test.nf
hmm yea I think its because the
workflow
object is not acceptable as an arg that is expecting
Map