forked from aseetharam/common_scripts
-
Notifications
You must be signed in to change notification settings - Fork 41
/
count_fastq.sh
executable file
·95 lines (74 loc) · 1.61 KB
/
count_fastq.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
# This is a bash script to count number of reads in fastq files
# 08/04/2014
# Arun Seetharam <[email protected]>
function printUsage () {
cat <<EOF
Synopsis
$scriptName [-h | --help] [-b | --base-count] fastq_file1 [fastq_file2 fastq_file3 ..] || *.fastq[.gz]
Description
This is a bash script counts the total number of reads in every fastq file
It also prints the number of reads tabular and easy to read format
-h, --help
Brings up this help page
-b, --base-count
include base counts along with number of reads
fastq_file
A standard fastq file with any extension [but not compressed]
Author
Arun Seetharam, Genome Informatics Facilty, Iowa State University
08 April, 2014
EOF
}
if [ $# -lt 1 ] ; then
printUsage
exit 0
fi
while :
do
case $1 in
-h | --help | -\?)
printUsage
exit 0
;;
--)
shift
break
;;
-*)
printf >&2 'WARNING: Unknown option (ignored): %s\n' "$1"
shift
;;
*)
break
;;
esac
done
filear=${@};
for i in ${filear[@]}
do
if [ ! -f $i ]; then
echo "\"$i\" file not found!"
exit 1;
fi
if [[ $i =~ \.gz$ ]]; then
lines=$(zcat $i | wc -l |cut -d " " -f 1)
count=$(($lines / 4))
echo -n -e "\t$i : "
echo "$count" | \
sed -r '
:L
s=([0-9]+)([0-9]{3})=\1,\2=
t L'
else
lines=$(wc -l $i|cut -d " " -f 1)
count=$(($lines / 4))
echo -n -e "\t$i : "
echo "$count" | \
sed -r '
:L
s=([0-9]+)([0-9]{3})=\1,\2=
t L'
fi
done