CWL for star for multiple bam files with javascript expression
1
0
Entering edit mode
5.8 years ago
a.james ▴ 240

Hello All,

I wanted to get 2 BAM files from STAR.cwl tool, one sorted and one unsorted, for that I wrote the following expression.

outputs:
 star_bam:
  type: File
  outputBinding:
   glob: |
       ${
         var p = inputs.outFileNamePrefix?inputs.outFileNamePrefix:"";
         if (inputs.outSAMtype.indexOf("BAM") > -1) {
             return p+"Aligned.out.bam";
         } else {
          if ( inputs.outSAMtype.indexOf("Unsorted") > -1 )
             return p+"Aligned.out.bam";
           else
             return p+"Aligned.out.bam";
         } else {
          if ( inputs.outSAMtype.indexOf("SortedByCoordinate") > -1 )
             return p+"Aligned.sortedByCoord.out.bam";
           else
             return p+"Aligned.out.bam";
         }
       }

The part where inputs.outSAMtype and outfileprefix are defined in the inputs is here,

inputs:
    outSAMtype:
          default: [BAM, Unsorted, SortedByCoordinate]
      outFileNamePrefix:
         type: string
         inputBinding:
        position: 23
        prefix: --outFileNamePrefix

And the tool stoped at the above expression part and threw the following SyntaxError:

../../../../../../..cwltools/star.cwl:167:4: 269 (function(){
    ../../../../../../../cwltools/star.cwl:167:4: 270   var p = inputs.outFileNamePrefix?inputs.outFileNamePrefix:"";
    ../../../../../../../cwltools/star.cwl:167:4: 271   if (inputs.outSAMtype.indexOf("BAM") > -1) {
    ../../../../../../../cwltools/star.cwl:167:4: 272       return p+"Aligned.out.bam";
    ../../../../../../..//cwltools/star.cwl:167:4: 273   } else {
    ../../../../../../..//cwltools/star.cwl:167:4: 274    if ( inputs.outSAMtype.indexOf("Unsorted") > -1 )
    ../../../../../../..//cwltools/star.cwl:167:4: 275       return p+"Aligned.out.bam";
    ../../../../../../..//cwltools/star.cwl:167:4: 276     else
    ../../../../../../../star.cwl:167:4: 277       return p+"Aligned.out.bam";
    ../../../../../../..//cwltools/star.cwl:167:4: 278   } else {
    ../../../../../../../cwltools/star.cwl:167:4: 279    if ( inputs.outSAMtype.indexOf("SortedByCoordinate") > -1 )
    ../../../../../../../cwltools/star.cwl:167:4: 280       return p+"Aligned.sortedByCoord.out.bam";
    ../../../../../../..r/cwltools/star.cwl:167:4: 281     else
    ../../../../../.././cwltools/star.cwl:167:4: 282       return p+"Aligned.out.bam";
    ../../../../../.././cwltools/star.cwl:167:4: 283   }
    ../../../../../../..r/cwltools/star.cwl:167:4: 284 })()
    ../../../../../../../cwltools/star.cwl:167:4: stdout was: ''
    ../../../../../.././cwltools/star.cwl:167:4: stderr was: 'evalmachine.<anonymous>:278
    ../../../../../../../cwltools/star.cwl:167:4:   } else {
    ../../../../../../../cwltools/star.cwl:167:4:     ^^^^
    ../../../../../../../cwltools/star.cwl:167:4: 
    ../../../../../../..//cwltools/star.cwl:167:4: SyntaxError: Unexpected token else
    ../../../../../.././cwltools/star.cwl:167:4:     at new Script (vm.js:74:7)
    ../../../../../../../cwltools/star.cwl:167:4:     at createScript (vm.js:246:10)
    ../../../../../.././cwltools/star.cwl:167:4:     at Object.runInNewContext (vm.js:291:10)
    ../../../../../../../cwltools/star.cwl:167:4:     at Socket.<anonymous> ([eval]:11:57)
    ../../../../../../../cwltools/star.cwl:167:4:     at Socket.emit (events.js:182:13)
    ../../../../../../cwltools/star.cwl:167:4:     at addChunk (_stream_readable.js:283:12)
    ../../../../../.././cwltools/star.cwl:167:4:     at readableAddChunk (_stream_readable.js:260:13)
    ../../../../../.././cwltools/star.cwl:167:4:     at Socket.Readable.push (_stream_readable.js:219:10)
    ../../../../../../..//cwltools/star.cwl:167:4:     at Pipe.onread (net.js:639:20)'
    [job star] completed permanentFail

Any help is greatly appreciated

CWL • 1.1k views
ADD COMMENT
1
Entering edit mode
5.8 years ago
Tom ▴ 540

Your third else does not seem to have an if it can refer to.

I might be misunderstanding the intention of your expression. But it looks to me like you can just drop all the else statements from your code and it will still serve the intended purpose.

${
var p = inputs.outFileNamePrefix?inputs.outFileNamePrefix:"";
         if (inputs.outSAMtype.indexOf("BAM") > -1) {
             return p+"Aligned.out.bam";
         }
         if ( inputs.outSAMtype.indexOf("Unsorted") > -1 )
             return p+"Aligned.out.bam";
         }
         if ( inputs.outSAMtype.indexOf("SortedByCoordinate") > -1 )
             return p+"Aligned.sortedByCoord.out.bam";
         }
}
ADD COMMENT
1
Entering edit mode

Hello Tom,

Thanks for the comment and possible solution. The current expression (yours), is throwing a glob error as follows,

I made a little change and it is now working fine.

glob:
     ${
       var p = inputs.outFileNamePrefix?inputs.outFileNamePrefix:"";
     if (inputs.outSAMtype.indexOf("SortedByCoordinate") > -1) {
        return p+"Aligned.sortedByCoord.out.bam";
     }
     }

Also with else

glob:
         ${
           var p = inputs.outFileNamePrefix?inputs.outFileNamePrefix:"";
         if (inputs.outSAMtype.indexOf("SortedByCoordinate") > -1) {
            return p+"Aligned.sortedByCoord.out.bam";
         }
     else {
      if ( inputs.outSAMtype.indexOf("BAM") > -1 )
         return p+"Aligned.out.bam";
         }
       }
ADD REPLY

Login before adding your answer.

Traffic: 2497 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6