-
Notifications
You must be signed in to change notification settings - Fork 21
/
applyFilter.sh
executable file
·83 lines (65 loc) · 1.77 KB
/
applyFilter.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
#!/bin/bash
SDIR="$( cd "$( dirname "$0" )" && pwd )"
if [ -x "$(command -v git)" ] && [ -r "$SDIR/.git" ]
then
# if both Git CLI and .git exist, then use "git describe" to create version tag
SVERSION=$(git --git-dir=$SDIR/.git --work-tree=$SDIR describe --tags)
else
if [ -r "${SDIR}/.git-commit-hash" ]
then
# if .git-commit-hash exists, then use the git commit hash stored in .git-commit-hash
SVERSION=$(cat ${SDIR}/.git-commit-hash)
else
# if we can't figure it out, use a hardcoded version number that we need to keep updated
SVERSION="v1.2.1"
fi
fi
# construct version tag
VTAG="$(basename $SDIR)/$(basename $0) VERSION=$SVERSION"
usage() {
echo "applyFilter.sh FILTER_SCRIPT IN_MAF OUT_MAF [Additional parameters for Filter]"
echo
echo " Run the filter (FILTER_SCRIPT) on the input maf and"
echo " write a properly headered output maf"
echo
echo " If the filter script require more parameters they"
echo " can be passed after the output maf name"
echo ""
echo " "$VTAG
echo
exit
}
if [ "$#" -lt "3" ]; then
usage
fi
FILTER=$1
MAFIN=$2
MAFOUT=$3
shift 3
# Resolve filter to full path
FILTER=$SDIR/$(basename $FILTER)
if [ ! -e $FILTER ]; then
echo "ERROR: Non-existant filter" $(basename $FILTER)
exit 1
fi
#
# Check if MAF has proper version header
# If not add it.
#
HEADER=$(head -1 $MAFIN)
if [[ ! "$HEADER" =~ ^# ]]; then
echo "#version 2.4" > $MAFOUT
else
egrep "^#" $MAFIN > $MAFOUT
fi
# Add version tag
echo "#$VTAG FILTER=$(basename $FILTER)" >>$MAFOUT
TMPMAF=$(uuidgen).maf
Rscript --vanilla $FILTER -m $MAFIN -o $TMPMAF $*
EXIT_CODE=$?
if [ "$EXIT_CODE" != "0" ]; then
echo "ERROR IN R-script"
exit 1
fi
cat $TMPMAF >>$MAFOUT
rm $TMPMAF