Pattern match on input veriable name inside stage

18 views
Skip to first unread message

ben curran

unread,
Apr 3, 2019, 11:41:41 PM4/3/19
to bpipe-discuss
I have a stage for alignment :

align = {
    output.dir="/nesi/nobackup/uoa02461/data/intermediateFiles"
    exec """bwa mem -t 12 -R '@RG\\tID:$SAMPLE\\tSM:$SAMPLE\\tLB:$SAMPLE\\tPL:ILLUMINA' $bwaIndex $input1 $input2 | samtools sort -@12 -O BAM -o $output.bam""", "align"
}

And I have samples for coming into the stage as $input1 and $input 2. When you echo $input1 and $input2, it gives the full filename i.e.

/nesi/nobackup/uoa02461/data/intermediateFiles/sample1_1.fastq.gz.trim
/nesi/nobackup/uoa02461/data/intermediateFiles/sample1_2.fastq.gz.trim

I'd like the sample name to be recorded in the bam files (not just in the name of the bam files), which is what $SAMPLE is meant to be for. How do I get from:

$input1 = /nesi/nobackup/uoa02461/data/intermediateFiles/sample1_1.fastq.gz.trim

to $SAMPLE = sample1


I've been trying to exec various bash pattern matching approaches, but it appears regex skills using bash have deteriorated or I'm attempting to integrate them incorrectly. And I never could grok pattern matching in Java.

Cheers
Ben.

ben curran

unread,
Apr 4, 2019, 12:24:31 AM4/4/19
to bpipe-discuss
The closest I've got is something like this:

    exec """ echo $input """
    def SAMPLE = exec """ filename=\$(basename -- "$input");
                          filename="\${filename%_*}";
                          echo $filename"""
    exec """ $SAMPLE """

As in I have bash code that will isolate the part of the filename I want. It works when I run it in it's own script. I don't see any way to assign the final value output from the bash code to the local variable SAMPLE though. Is this possible?
Reply all
Reply to author
Forward
0 new messages