problem with a for loop
0
0
Entering edit mode
3.6 years ago
gubrins ▴ 310

Heys!

I'm implementing GATK best practises for doing SNP calling and I have a problem in my first for loop. I'm trying to run it through /dev/stdin and /dev/stdout in order to avoid creating intermediate files, but when I run it, the last file (NEW_"$i".fastq) is created but with anything inside.

new_fastq () {
fastq=$1

for i in $(cat $fastq);

do

(java -Xmx2g -Djava.io.tmpdir=`pwd`/tmp -jar ~/softwares/picard/picard.jar FastqToSam FASTQ="$i"1.fastq.gz \
FASTQ2="$i"2.fastq.gz OUTPUT=/dev/stdout SAMPLE_NAME="$i" READ_GROUP_NAME="$i" TMP_DIR=`pwd`/tmp\

java -Xmx2g -Djava.io.tmpdir=`pwd`/tmp -jar ~/softwares/picard/picard.jar SortSam I=/dev/stdin \
O=/dev/stdout SORT_ORDER=queryname TMP_DIR=`pwd`/tmp \

java -Xmx2g -Djava.io.tmpdir=`pwd`/tmp -jar ~/softwares/picard/picard.jar MarkIlluminaAdapters \
I=/dev/stdin O=/dev/stdout METRICS=metrics_"$i".txt TMP_DIR=`pwd`/tmp \

java -Xmx2g -Djava.io.tmpdir=`pwd`/tmp -jar ~/softwares/picard/picard.jar SamToFastq \
I=/dev/stdin FASTQ=NEW_"$i".fastq CLIPPING_ATTRIBUTE=XT CLIPPING_ACTION=2 \
INTERLEAVE=true NON_PF=true TMP_DIR=`pwd`/tmp) &

done

wait
}

new_fastq fastq.txt

What am I missing?

Thanks in advance!

linux shell loop • 1.2k views
ADD COMMENT
1
Entering edit mode

Add a set -x to the script and run it. That will print (to STDOUT) the exact commands being run, which you can use to debug.

ADD REPLY
0
Entering edit mode

where should I add it? inside the loop?

ADD REPLY
1
Entering edit mode

Save the function to a script and add set -x to the second line, the first line being #!/bin/bash.

ADD REPLY
1
Entering edit mode

Can you try this? OUTPUT=/dev/stdout/$i.bam on your first command and check the output?

ADD REPLY
0
Entering edit mode

Sorry, maybe I did not explain properly want I want to obtain. There are four functions and I want that the output from the first one was to the second one and so on until the end, where this FASTQ=NEW_"$i".fastq should be created

ADD REPLY
0
Entering edit mode

If I have an output in each of the functions it works, but I would like to avoid having intermediate files that in this case I will not use.

ADD REPLY
1
Entering edit mode

Oh, now I got it! You can simply remove the intermediate files as soon as they are used (I do this!) or you can try to use pipe | between your functions. I've never tried this approach but doesn't hurt to try!

ADD REPLY

Login before adding your answer.

Traffic: 2402 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