These are chat archives for nextflow-io/nextflow

8th
Sep 2016
Mike Smoot
@mes5k
Sep 08 2016 19:48

@pditommaso I'm wondering if there's an existing way to provide a template string instead of a template file? Something like this:

my_command = 'echo ${name}'

names = Channel.from('homer','marge','lisa')

process echoit {

    input:
    val(name) from names

    script:
    my_command
}

I've tried a few things but haven't found a syntax that allows the name variable to be expanded.

Paolo Di Tommaso
@pditommaso
Sep 08 2016 19:50
You can create a method taking the template vars as arguments
Mike Smoot
@mes5k
Sep 08 2016 19:51
So the method would do the substitution in the string?
Paolo Di Tommaso
@pditommaso
Sep 08 2016 19:51
yep
Mike Smoot
@mes5k
Sep 08 2016 19:52
Interesting, I will experiment!
Paolo Di Tommaso
@pditommaso
Sep 08 2016 19:52
def myTemplate( foo, bar ) {
  """
  echo $foo $bar
  """ 
}
Mike Smoot
@mes5k
Sep 08 2016 19:56
Is there any way to pull the string "echo $foo $bar" out? What I'm experimenting with is specifying the template string separately and ultimately have the string provided from an external source.
Paolo Di Tommaso
@pditommaso
Sep 08 2016 19:57
:)
out where?
Mike Smoot
@mes5k
Sep 08 2016 19:57
I need something analogous to:
my_command = 'echo ${name}'

def myTemplate(name) {
   """
   ${my_command}
   """
}
Paolo Di Tommaso
@pditommaso
Sep 08 2016 19:58
well, but that's the template file .. no?
Mike Smoot
@mes5k
Sep 08 2016 20:00
Welllll, not quite. What I was imagining was creating a simple java class file that defines some string constants and importing those constants using grape grab.
the ultimate goal is to write a command once and share it amongst many systems. I don't think this is particularly good idea, I was just experimenting.
Paolo Di Tommaso
@pditommaso
Sep 08 2016 20:01
TemplateEngine is your friend
:)
Mike Smoot
@mes5k
Sep 08 2016 20:02
Ah, that might do it! Many thanks!