Setting variable from inside (non-groovy) script

440 views
Skip to first unread message

Robert Syme

unread,
Aug 31, 2015, 2:51:34 PM8/31/15
to Nextflow
Hi all

I'd like a process that takes a single input and returns a set of two elements; an id (determined by a script) and an output file. At the moment, I've got a process that outputs the file using the id in the filename. The channel is then mapped to split the id from the file:

process example {
  input:
  val foo from example_in

  output:
  'file.txt' into example_out

  """
id=`get_id $foo`
get_file $foo > \$id.txt
"""
}

example_out.map{  out_file -> [out_file.getBaseName(), out_file]

Is there a better way of writing a process that takes a single value and then outputs a set of val, file where the val is the output of a script?

Thanks!

Paolo Di Tommaso

unread,
Aug 31, 2015, 3:57:08 PM8/31/15
to nextflow
Hi Robert, 

A slightly better workaround is using the stdout output to capture the BASH variable value. Something like the following: 

process example {
  input:
  val foo from 2

  output:
  set stdout, file('file.txt') into example_out

  """
  id=`get_id $foo`
  echo $foo > file.txt
  printf "$foo"
  """
}


However I agree that should be a more specific mechanism to capture the BASH variable as output values. 


Would you like to open a feature request for this? 


Cheers,
Paolo
  
 

--
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 http://groups.google.com/group/nextflow.
For more options, visit https://groups.google.com/d/optout.

Rob Syme

unread,
Aug 31, 2015, 5:40:14 PM8/31/15
to next...@googlegroups.com
Thanks Paolo

I think that in most cases, users will need to extract only a single ID variable, in which case the stdout solution is sufficient. I've opened an issue in case others would like a more complete solution.

-r

--
You received this message because you are subscribed to a topic in the Google Groups "Nextflow" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nextflow/pIojNRFzdlM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nextflow+u...@googlegroups.com.

Rob Syme

unread,
Sep 1, 2015, 10:49:38 AM9/1/15
to next...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages