sarthak sarthak - 10 months ago 65
Scala Question

Using multi-line inputs Scala process package

I have the following code:

s"""java ${MemString} -jar ${toolsFolder}/GenomeAnalysisTK.jar -T IndelRealigner -R ${refFolder}/${RefFileName} -I ${tmpFolder}/region${chrRegion}.bam
-targetIntervals ${tmpFolder}/region${chrRegion}.intervals -o ${tmpFolder}/region${chrRegion}-2.bam -L ${tmpFolder}/bed${chrRegion}.bed""" !
s"rm -rf ${tmpFolder}/region${chrRegion}.bam, ${tmpFolder}/region${chrRegion}.bai, ${tmpFolder}/region${chrRegion}.intervals" !

Since I have a big input string for the first line I am trying to use multi-line string input for the process. But I am getting the following error:

sbt package
[info] Set current project to DNASeqAnalyzer (in build file:/home/sarthaksharma/Lab3/dnaseq_analyzer/)
[info] Compiling 1 Scala source to /home/sarthaksharma/Lab3/dnaseq_analyzer/target/scala-2.11/classes...
[error] /home/sarthaksharma/Lab3/dnaseq_analyzer/src/main/scala/DNASeqAnalyzer.scala:148 : type mismatch;
[error] found : String
[error] required: scala.sys.process.ProcessLogger
[error] s"rm -rf ${tmpFolder}/region${chrRegion}.bam, ${tmpFolder}/region${chrRegion}.bai, ${tmpFolder}/region${chrRegion}.intervals" !
[error] ^
[error] one error found
[error] (compile:compileIncremental) Compilation failed

It is running fine if I comment the first line of the code. Why is it showing error for a different line? How can I run this?

Answer Source

The problem occurs because you hit the alternative method .!(logger), instead of the one without arguments. So try just to write the dot explicitly:

s"another command".!

Also, I would recommend you to construct any commands as sequences of strings, this solves your long command problem and is less ambiguous regarding how arguments will be interpreted (and escaped):