Use a parameter generated in a task to name a file

We would like to be able to, on the fly, generate a name variable and name an output file with it, say like

TUMOR_SAMPLE_NAME=`samtools view -H ${tumor_bam} |grep -Po 'SM:.*'|cut -f1|grep -Po ':.*'|perl -ne '$_=~s/^://g ; print $_'|head -1`;

mv out.bam "$TUMOR_SAMPLE_NAME".bam

and then use this variable to name an output file, with something that looks like

output {
File tumor="$TUMOR_SAMPLE_NAME".bam
}

I don't think the last line is correct though. Is there a way to change this to get it work?
Thanks!

Tagged:

Best Answer

Answers

  • danbdanb Member, Broadie ✭✭
    edited September 2017

    If you declared this string format as its own task you could capture the output and pass it in to this task.

    Something like

    task fileName {
      command {
        echo `samtools view -H ${tumor_bam} |grep -Po 'SM:.*'|cut -f1|grep -Po ':.*'|perl -ne '$_=~s/^://g ; print $_'|head -1`;
      }
    
      output {
      String filename = read_string(stdout());
      }
    }
    
    task yourtask {
      String fileName 
    
      command {
        mv out.bam ${fileName}.bam
      }
    
      output {
        File tumor="${fileName}.bam"
      }
    }
    
Sign In or Register to comment.