generated from CarolinaPB/snakemake-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
count_nbseq_V2.sh
executable file
·57 lines (42 loc) · 1.09 KB
/
count_nbseq_V2.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
#!/bin/bash
cd data
for i in $(ls *.fastq)
do
echo $i >> stat_fq_temp.txt
cat $i | echo $(($(wc -l)/4)) >> stat_fq_temp.txt
done
perl -pe 's/fastq\n/fastq\t/' stat_fq_temp.txt > stat_fq.txt
rm *_temp.txt
#Variable that count the total number of reads
t=0
#Variable that count the total number of samples
c=0
cat stat_fq.txt | ( while read line
do
id=$(echo $line | cut -d' ' -f1)
nbseq=$(echo $line | cut -d' ' -f2)
t=$(( $nbseq + t ))
c=$(( c + 1 ))
done
#Compute the average number of reads from the sample pool
m=$((t / c))
echo "Average number of reads: " $m
#Compute 10% of the average
a=`bc <<< "scale=0; $m*0.1"`
#Round to integer the preceeding number
gf=$(echo "$a" | awk '{printf("%d\n",$1 + 0.5)}')
echo "10% of the average: " $gf
cat stat_fq.txt | ( while read line
do
id=$(echo $line | cut -d' ' -f1)
nbseq=$(echo $line | cut -d' ' -f2)
test=""
if [ "$gf" -gt "$nbseq" ]
then test="Remove this sample from the analysis"
mv $id ../reject/
fi
echo $id $nbseq $gf $test
done
)
)
mv stat_fq.txt ../stat