calculating read depth via a for in loop over many fastq files ?
2
0
Entering edit mode
9 months ago

I have been trying to get the depth of several fastq files using for in loop approach: I have used this code to print out name of each fastq then the depth of that file: what I used was:

  Sample=(*.fastq)
for f in *.fastq
do
Depth=$(grep -c @ $f)
echo "$Sample:$Depth" >> Depth_before_trimm
done

but what it produces is the file name of the first fastq and keep repeating it again instead of the names of other files.

Could you tell what might be causing this ?

Linux R bash • 823 views
ADD COMMENT
0
Entering edit mode

you cannot get a "DEPTH" from a fastq file. the depth is associated to BAM/SAM/CRAM/VCF files.

ADD REPLY
0
Entering edit mode
9 months ago
Buffo ★ 2.4k

What you need is count bases, not reads. See this post

ADD COMMENT
0
Entering edit mode
9 months ago

grep -c @ $f

are you trying to count the number of lines in the fastqs ? do not ever try to use '@' because '@' can also be present in the quality string.

Here is a loop

rm -f output.txt
for F in *.fastq
do
   echo -n "$F" >> output.txt
   cat "$F" | paste - - - - | wc -l  >> output.txt
done
ADD COMMENT
0
Entering edit mode

I really appreciate this, but I am trying to make it with even a simple loop, the one I provided: could you please let me know what wrong I have done with that loop ?

I know it is trivial, but I want to create a variable with all names of the files, and then pass it to the echo within the loop.

ADD REPLY

Login before adding your answer.

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