This is a test version of Biostars. For the public version, visit https://www.biostars.org.
problem with a for loop

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

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.

where should I add it? inside the loop?

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

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

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

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.

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!

0 answers

No answers yet.

Log in to answer this question.