This is a test version of Biostars. For the public version, visit https://www.biostars.org.
MACS2: Albeit outdir definition, my output goes to folder of input

Hi, I seem to have a problem getting my output in the right location. Using the following call..

workdir="$1"
files=($(awk '{print $1}' $2 ))
infile="$workdir"/bam/${files[$SGE_TASK_ID]}.sorted.dedup.bam 
macs2 predictd -i $infile -f BAM -g mm -m 5 50 --outdir "$workdir"/macs2/qc --rfile ${$infile%.sorted.dedup.bam}_model.r

..my input goes to $workdir/bam

Any suggestions? Thanks!

chip-seq macs2

1 answer

Your quoting is off by a bit. Here is some cleaned up code:

workdir="$1"
files=($(awk '{print $1}' $2 ))
infile="${workdir}/bam/${files[$SGE_TASK_ID]}.sorted.dedup.bam"
macs2 predictd -i ${infile} -f BAM -g mm -m 5 50 --outdir "${workdir}/macs2/qc" --rfile ${$infile%.sorted.dedup.bam}_model.r

The double quotes should work with the parameter expansion quotes ({}), not isolate the variable to an extent that it renders the context meaningless. EDIT: Your style of quoting is not wrong, it's just different. Sorry!

Thanks for your suggestions, always happy to improve my quoting. Unfortunately, this didn't seem to solve the issue:

INFO  @ Tue, 04 Sep 2018 08:41:05: # Generate R script for model : /mnt/iscsi_speed/bam/SRR1202461_model.r

Any other ideas? Do you think it is a quoting issue?

Can you verify that the command looks OK? Change the last line to

echo "macs2 predictd -i ${infile} -f BAM -g mm -m 5 50 --outdir \"${workdir}/macs2/qc\" --rfile ${$infile%.sorted.dedup.bam}_model.r"

Also, it would help if you could give an example of how you invoke the script, with actual parameters.

I get the following error:

/opt/sge625/sge/default/spool/go-node-38/job_scripts/114466: line 17: macs2 predictd -i ${infile} -f BAM -g mm -m 5 50 --outdir "${workdir}/macs2/qc" --rfile ${$infile%.sorted.dedup.bam}_model.r: bad substitution

Here an attempt to clarify my parameters:

workdir="/mnt/iscsi_speed"
samples="${workdir}/samplesheet.txt"  #tab-separated text file with file basename in first column
files=($(awk '{print $1}' $samples ))
infile="${workdir}/bam/${files[0]}.sorted.dedup.bam"
macs2 predictd -i ${infile} -f BAM -g mm -m 5 50 --outdir "${workdir}/macs2/qc" --rfile ${$infile%.sorted.dedup.bam}_model.r

Should've spotted this early on: change ${$infile%.sorted.dedup.bam} to ${infile%.sorted.dedup.bam}

Here is the echo'd output:

macs2 predictd -i /mnt/iscsi_speed/blelloch/deniz/buecker2014/naive/bam/SRR1202453.sorted.dedup.bam -f BAM -g mm -m 5 50 --outdir "/mnt/iscsi_speed/macs2/qc" --rfile /mnt/iscsi_speed/bam/SRR1202453_model.r

That echo call made me realize what is wrong:

the $infile variable seems to overwrite the output dir because it contains an absolute path. Changing the call option to:

--rfile $(basename ${infile%.sorted.dedup.bam}_model.r)

solves the problem.

Thanks for pointing me towards the answer!

Log in to answer this question.