Iteration to count the number of raw reads
3
0
Entering edit mode
5.5 years ago
wanaga3166 ▴ 10

Hi everyone,

I made a short script to count the number of raw reads (fastq.gz) in my folder. The results will save in a text file (.txt).

echo "We count the number of reads for each file (fastq.gz)."
echo "file\traw_reads\ttrimmed_reads" > count_read_evolution_trim_test.txt
for f1 in *paired.fq.gz
  do
     echo $f1
     RAW_READS=`gunzip -c $f1 | echo $((`wc -l`/4))`
     echo -e "$f1\t$RAW_READS" >> count_read_evolution_trim_test.txt
  done

But I obtained this error message:

./test_count_raw_reads.sh: command substitution: line 9: syntax error near unexpected token `)'
./test_count_raw_reads.sh: command substitution: line 9: `/4))'
./test_count_raw_reads.sh: command substitution: line 9: unexpected EOF while looking for matching `)'
./test_count_raw_reads.sh: command substitution: line 10: syntax error: unexpected end of file
./test_count_raw_reads.sh: line 9: -l: command not found code here

How I can fix this problem?

Thank you.

sequence raw reads shell script • 2.7k views
ADD COMMENT
0
Entering edit mode

When I did this command line:

gunzip -c $f1 | echo $((`wc -l`/4))

It works, I obtained the number of raw reads. I just want to put the number of raw reads in a table, like in this example.

file | raw_read_number

my_file_1 | 130000

my_file_2 | 160000

my_file_3 | 200000

I don't understand where I did a mistake.

ADD REPLY
0
Entering edit mode
gunzip -c $f1 | echo 

you're piping a stream in echo : wrong

ADD REPLY
0
Entering edit mode

your use of ` is messing up this line:

`gunzip -c $f1 | echo $((`wc -l`/4))`
ADD REPLY
0
Entering edit mode

If you watch my initial code (in the top) of this post, I put the back quote as you wrote. And I can't save the number of raw reads in my text table (count_read_evolution_trim_test.txt).

The problem in my code, that a I have two backquote in this line:

RAW_READS=`gunzip -c $f1 | echo $((`wc -l`/4))`

And it doesn't count the raw reads number.

ADD REPLY
2
Entering edit mode
5.5 years ago
Martombo ★ 3.1k

Yep, exactly. The second ` stops the expression at:

`gunzip -c $f1 | echo $((`

If you want to keep this line you can maybe use awk to divide by 4:

RAW_READS=`gunzip -c $f1 | wc -l | awk '{print($1/4)}'`

edit: this is probably more efficient:

RAW_READS=`gunzip -c $f1 | awk 'END{print(NR/4)}'`
ADD COMMENT
0
Entering edit mode

Thank you Martombo. Your solution works. I will be more careful with the backquotes.

ADD REPLY
1
Entering edit mode
5.5 years ago

you want:

find . -name "*q.gz" | while read F; do echo -n "$F " && echo $(( $(gunzip -c $F | wc -l) / 4 )) ; done
ADD COMMENT
0
Entering edit mode

When I did this command line:

gunzip -c $f1 | echo $((wc -l/4)) It works, I obtained the number of raw reads. I just want to put the number of raw reads in a table, like in this example.

file | raw_read_number my_file_1 | 130000 my_file_2 | 160000 my_file_3 | 200000 I don't understand where I did a mistake.

ADD REPLY
0
Entering edit mode
5.5 years ago
2nelly ▴ 350

Hi wanaga3166

what about this:

for f in *fastq.gz; do echo -n "$f | "  && echo $(($(zcat $f | echo $((`wc -l`/4))))); done > output && sed  -i '1i file | raw_read_number' output
ADD COMMENT

Login before adding your answer.

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