double-dash input parameters with multiple arguments?

1,043 views
Skip to first unread message

Owen S.

unread,
Apr 13, 2017, 12:58:36 AM4/13/17
to Nextflow
Is there any way to pass a list of arguments as input parameters?

For example:
nextflow run tutorial.nf --str Hola Hello Aloha
I know I could put them in a quoted string --  the reason I'd like to be able to pass multiple items is to leverage bash filename expansion when starting the script from the command line.

Thanks in advance.

Phil Ewels

unread,
Apr 13, 2017, 2:32:49 AM4/13/17
to next...@googlegroups.com
I don't think so - I've asked Paolo the same question previously. Nextflow is able to handle positional arguments at the end of the command, not not multiple items for a param. If you do figure out a solution please let us know as one of the most common modes of error on our pipelines is people forgetting to use quotes around filenames ;)

Phil
--
You received this message because you are subscribed to the Google Groups "Nextflow" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nextflow+u...@googlegroups.com.
Visit this group at https://groups.google.com/group/nextflow.
For more options, visit https://groups.google.com/d/optout.

Paolo Di Tommaso

unread,
Apr 13, 2017, 4:15:44 AM4/13/17
to nextflow
No (yet). This is one of the many CLI improvements we would like to implement. 

However this's a quick workaround for that. 

Supposing you want to specify a list a values as you are suggesting, eg. 

nextflow run tutorial.nf --str Hola Hello Aloha


You can have in your script: 

params.str = 'Hi'
str_list = params.str.tokenize(' ')


Then `str_list` can be used in place of the `params.str` and it contains the list of values you have specified on the command line. 


Hope it helps

Cheers,
Paolo


On Thu, Apr 13, 2017 at 8:32 AM, Phil Ewels <phil....@scilifelab.se> wrote:
I don't think so - I've asked Paolo the same question previously. Nextflow is able to handle positional arguments at the end of the command, not not multiple items for a param. If you do figure out a solution please let us know as one of the most common modes of error on our pipelines is people forgetting to use quotes around filenames ;)

Phil





On Thursday, 13 April 2017 at 06:58, Owen S. wrote:

Is there any way to pass a list of arguments as input parameters?

For example:
nextflow run tutorial.nf --str Hola Hello Aloha
I know I could put them in a quoted string --  the reason I'd like to be able to pass multiple items is to leverage bash filename expansion when starting the script from the command line.

Thanks in advance.

--
You received this message because you are subscribed to the Google Groups "Nextflow" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nextflow+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Nextflow" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nextflow+unsubscribe@googlegroups.com.

Owen S.

unread,
Apr 13, 2017, 12:45:09 PM4/13/17
to Nextflow
Thank you Paolo and Phil.

Being able to pass an array of values by repeating the flag could be handy, but I don't think it would help in my case (where I want to use bash filename expansion to pass in a list of files.)   I also have a workaround, which is to escape the asterisk on the command line (or alternatively, to quote the pattern) and then let the NF workflow glob the files.  Something like this:

nextflow run tutorial.nf --input input\*.txt

In the nf script, I've learned that file(params.input) will automatically do the file globbing (no need to use Groovy libraries for this).  

Also, in order to allow the user to provide either a single file or an (escaped) wildcard pattern, I do something like this:

if (params.input.contains("*")) {
    myFileList = file(params.input)
} else {
    myFileList = [file(params.input)]
}

This allows the rest of the workflow to assume that the input will always be a list of files, even if the length of the list is 1.   And a more better version (allowing more sophisticated glob patterns) could look something like this:

inputFileList = file(params.input)
inputFileListClass = inputFileList.getClass().toString()
if (inputFileListClass == "class java.util.LinkedList") {
    log.info("Found file glob: " + inputFileList)
} else if (inputFileListClass == "class sun.nio.fs.UnixPath") {
    log.info("Found single file: " + inputFileList)
    inputFileList = [inputFileList]
} else {
    throw new Exception("Unknown class (" + inputFileListClass+ ") of input file: " +  params.input)
}

Apologies for asking a repeated question/request!  I did try to search for it in this forum before asking. :) 

Thanks
Owen


On Thursday, April 13, 2017 at 1:15:44 AM UTC-7, Paolo Di Tommaso wrote:
No (yet). This is one of the many CLI improvements we would like to implement. 

However this's a quick workaround for that. 

Supposing you want to specify a list a values as you are suggesting, eg. 

nextflow run tutorial.nf --str Hola Hello Aloha


You can have in your script: 

params.str = 'Hi'
str_list = params.str.tokenize(' ')


Then `str_list` can be used in place of the `params.str` and it contains the list of values you have specified on the command line. 


Hope it helps

Cheers,
Paolo

On Thu, Apr 13, 2017 at 8:32 AM, Phil Ewels <phil....@scilifelab.se> wrote:
I don't think so - I've asked Paolo the same question previously. Nextflow is able to handle positional arguments at the end of the command, not not multiple items for a param. If you do figure out a solution please let us know as one of the most common modes of error on our pipelines is people forgetting to use quotes around filenames ;)

Phil





On Thursday, 13 April 2017 at 06:58, Owen S. wrote:

Is there any way to pass a list of arguments as input parameters?

For example:
nextflow run tutorial.nf --str Hola Hello Aloha
I know I could put them in a quoted string --  the reason I'd like to be able to pass multiple items is to leverage bash filename expansion when starting the script from the command line.

Thanks in advance.

--
You received this message because you are subscribed to the Google Groups "Nextflow" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nextflow+u...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Nextflow" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nextflow+u...@googlegroups.com.

Paolo Di Tommaso

unread,
Apr 13, 2017, 12:55:55 PM4/13/17
to nextflow
Make sense, but don't do 


inputFileListClass = inputFileList.getClass().toString()
if (inputFileListClass == "class java.util.LinkedList")
.. 


it's ugly! :) 

You can do: 

if ( inputFileList.class instanceof List )
..


Note it uses the interface List instead of the concreate class LinkedList, or even: 

switch( inputFileList.class ) {
  case List: 
    ..
    break

  case Path:
    .. 
   break

  default: 
     ..
}



Enjoy,
p

Owen S.

unread,
Apr 13, 2017, 12:58:56 PM4/13/17
to Nextflow
Thank you -- looks much nicer!! 

Owen S.

unread,
Apr 13, 2017, 1:20:11 PM4/13/17
to Nextflow
Oh,  a slight correction to your suggestion:

It should be:
if ( inputFileList instanceof List )

not:  
if ( inputFileList.class instanceof List )

Obviously you know this Paolo -- I am just posting this for others who might come across the thread.

Thanks
Owen

Paolo Di Tommaso

unread,
Apr 13, 2017, 1:22:06 PM4/13/17
to nextflow
Thanks Owen. 


p

--
You received this message because you are subscribed to the Google Groups "Nextflow" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nextflow+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages