-
Notifications
You must be signed in to change notification settings - Fork 0
/
deleteInvalidBAMs.sh
executable file
·42 lines (30 loc) · 1.06 KB
/
deleteInvalidBAMs.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
#!/bin/bash
validationResults="/home/ccurnin/cnv/cnvkit/BAMValidationResults/*"
udn="/scratch/PI/euan/common/udn"
metadata="/home/ccurnin/metadata/finalMetadata.csv"
for validationResult in $validationResults
do
success=$(grep -ci "success" "$validationResult") #-i: case-insensitive; -c gives number of matches (though doubtful ever would be more than one)
if (( "$success" >= 1 ))
then
echo "${validationResult} is valid"
else
base=$(basename $validationResult)
BAM=${base%.*}
echo "${BAM} is invalid"
BAI=$(sed "s|bam|bai|" <<< "$BAM")
echo "removing ${BAI}"
$(find "$udn" -name "$BAI" -delete)
count=$(find "$udn" -name "$BAM" | wc -l)
if (( $count == 1 ))
then
echo "removing ${BAM}"
$(find "$udn" -name "$BAM" -delete)
elif (( $count == 0 ))
then
echo "couldn't find ${BAM}: already deleted?"
else
echo "multiple files named ${BAM}"
fi
fi
done