-
Notifications
You must be signed in to change notification settings - Fork 13
/
silentscorefile
executable file
·74 lines (59 loc) · 2.07 KB
/
silentscorefile
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
#!/bin/bash
if [ $# -ne 1 ]; then
echo >&2 "silentscorefile by bcov - a tool to extract a scorefile from a silentfile"
echo >&2 "Usage:"
echo >&2 " silentscorefile myfile.silent"
echo >&2 ""
echo >&2 "Note: This utility ensures that all score lines contain the same elements in"
echo >&2 " the same order. If this is not the case, multiple scorefiles are produced"
exit 1
fi
if [[ ! -f $1 ]]; then
echo >&2 "silentscorefile: File not found: $1"
exit 1
fi
silent_dir="$(dirname $(type -p "$0"))"
"$silent_dir"/silentassertuniquetags $1
silentname=$(basename $1 .silent)
scorename=${silentname}.sc
# tmp_file=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 13)
# tmp_file="tmp_${tmp_file}.tmp"
types=$(grep -a description $1 | tr -d "[:blank:]" | sort | uniq)
num_types=$(echo "$types" | wc -l)
if [[ $num_types -eq 1 ]]; then
head -n 2 $1 | grep -a description > $scorename # just in case there's no sequence line
grep -a '^SCORE:' $1 | grep -a -v description >> $scorename
exit 0
fi
# Don't change this wording unless you change silentinjectscores
echo >&2 "Warning!! Multiple scorefiles produced!!"
for tp in $(echo $types); do echo >&2 $tp; done
scorefiles=()
has_header=()
for i in $(seq 1 ${num_types}); do
scorefiles+=(${silentname}${i}.sc)
has_header+=('0')
done
current_file=-1
IFS=$'\n'
for line in $(grep -a '^SCORE:' $1); do
if $(echo "$line" | grep -a -q description); then
# echo >&2 "$line"
current_file=$(echo "$types" | grep -a --line-number $(echo $line | tr -d "[:blank:]" ) | cut -d ':' -f1)
if [[ -z $current_file ]]; then
echo >&2 "Uh oh"
exit 1
fi
current_file=$((current_file-1))
if [[ ${has_header[current_file]} -eq 0 ]]; then
echo "$line" > ${scorefiles[current_file]}
has_header[$current_file]='1'
fi
else
# echo >&2 "$current_file"
# echo >&2 "$line"
# echo >&2 "${scorefiles[current_file]}"
echo "$line" >> ${scorefiles[current_file]}
fi
done
unset IFS