Question: problem with a for loop
0
gravatar for gubrins
3 months ago by
gubrins60
gubrins60 wrote:

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 • 205 views
ADD COMMENTlink modified 7 weeks ago by Biostar ♦♦ 20 • written 3 months ago by gubrins60
1

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 REPLYlink written 3 months ago by _r_am32k

where should I add it? inside the loop?

ADD REPLYlink written 3 months ago by gubrins60
1

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

ADD REPLYlink written 3 months ago by _r_am32k
1

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

ADD REPLYlink modified 3 months ago • written 3 months ago by brunobsouzaa490

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 REPLYlink modified 3 months ago • written 3 months ago by gubrins60

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 REPLYlink written 3 months ago by gubrins60
1

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 REPLYlink written 3 months ago by brunobsouzaa490
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1400 users visited in the last hour