These are chat archives for nextflow-io/nextflow

30th
Jul 2015
Sascha Steinbiss
@satta
Jul 30 2015 08:36
hmmm... quick question
Paolo Di Tommaso
@pditommaso
Jul 30 2015 08:37
hi
Sascha Steinbiss
@satta
Jul 30 2015 08:37
as a non-Groovy person... how can I conditionally execute parts of a script depending on whether an input file is empty or not?
process merge_hints {
    input:
    file 'hints.concatenated.txt' from exn_hints.concat(trans_hints).collectFile()

    output:
    set val(outline), file('hints.txt') into all_hints

    script:
    f = new File('hints.concatenated.txt')
    if (f.length() > 0) {
      outline = "--hintsfile=augustus.hints"
      """
      cp hints.concatenated.txt hints.txt
      """
    } else {
      outline = ""
      """
      touch hints.txt
      """
    }
}
this always runs the empty case
hi Paolo :)
Paolo Di Tommaso
@pditommaso
Jul 30 2015 08:39
the problem is that when the groovy code is evaluated that file is not yet staged
Sascha Steinbiss
@satta
Jul 30 2015 08:39
ah
that explains it
Paolo Di Tommaso
@pditommaso
Jul 30 2015 08:39
yep
you can do in the bash script
Sascha Steinbiss
@satta
Jul 30 2015 08:39
ok, but I will also need to set the outline variable
would I need to squeeze this through a file as well?
Paolo Di Tommaso
@pditommaso
Jul 30 2015 08:40
I see
yes, I think currently there's not other way to do that
Sascha Steinbiss
@satta
Jul 30 2015 08:43
hm ok... could you quickly remind me how to get the contents of a file into a val?
Paolo Di Tommaso
@pditommaso
Jul 30 2015 08:43
I need to enhance the file handling mechanism, so that it could be possible to access that file
you could echo to the stdout and capture as set stdout, file('hints.txt') into all_hints
Sascha Steinbiss
@satta
Jul 30 2015 08:45
ah, yes
that seems to be the easiest solution
Paolo Di Tommaso
@pditommaso
Jul 30 2015 08:45
a bit tricky
Sascha Steinbiss
@satta
Jul 30 2015 08:46
yes... it seems that implementing optional processes is not particularly easy...
at least not if they make whole channels disappear or require setting different switches in the scripts
but thanks, I will try your suggestion :)
Paolo Di Tommaso
@pditommaso
Jul 30 2015 08:48
ok, you are welcome
Paolo Di Tommaso
@pditommaso
Jul 30 2015 08:58
@satta I had a better idea
Sascha Steinbiss
@satta
Jul 30 2015 08:58
oh?
if [ -s hints.concatenated.txt ] ; then mv hints.concatenated.txt hints.txt; echo '--hintsfile=augustus.hints'; fi seems to work for me
Paolo Di Tommaso
@pditommaso
Jul 30 2015 08:59
ok, just another way could be
Sascha Steinbiss
@satta
Jul 30 2015 08:59
but now I'm curious ;)
Paolo Di Tommaso
@pditommaso
Jul 30 2015 09:00
input:
   input:
    set hints, file('hints.concatenated.txt') from exn_hints.concat(trans_hints).collectFile().map { [it,it] }
basically you provide the same input twice
Sascha Steinbiss
@satta
Jul 30 2015 09:01
hmmmm ok... and then?
Paolo Di Tommaso
@pditommaso
Jul 30 2015 09:01
the first time is managed a simple value, so it refers to the to real file and you should be able to access it
Sascha Steinbiss
@satta
Jul 30 2015 09:01
ah, so I can then use script to handle it
Paolo Di Tommaso
@pditommaso
Jul 30 2015 09:02
the second is staged as it should
Sascha Steinbiss
@satta
Jul 30 2015 09:02
I see
Paolo Di Tommaso
@pditommaso
Jul 30 2015 09:02
yes, you should be able to handle externally
Sascha Steinbiss
@satta
Jul 30 2015 09:02
cool, good to know. will keep this in mind
Paolo Di Tommaso
@pditommaso
Jul 30 2015 09:03
yes, it could be useful in other cases
:)