forked from guigolab/grape-nf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·85 lines (69 loc) · 1.82 KB
/
test.sh
File metadata and controls
executable file
·85 lines (69 loc) · 1.82 KB
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
#!/bin/bash
set -e
set -o pipefail
usage() {
echo "Usage:"
echo " $0 <profile>"
exit 1
}
mkcd() {
local DIR=$1
mkdir -p $DIR && cd $DIR
}
canonicalize_path() {
if [ -d "$1" ]; then
_canonicalize_dir_path "$1"
else
_canonicalize_file_path "$1"
fi
}
_canonicalize_dir_path() {
(cd "$1" 2>/dev/null && pwd -P)
}
_canonicalize_file_path() {
local dir file
dir=$(dirname -- "$1")
file=$(basename -- "$1")
(cd "$dir" 2>/dev/null && printf '%s/%s\n' "$(pwd -P)" "$file")
}
nxf_setup() {
if ! nextflow &>/dev/null; then
export PATH=$PWD:$PATH
if [ ! -x nextflow ]; then
curl -fsSL get.nextflow.io | bash && chmod +x nextflow
fi
fi
}
normalize_bam() {
docker run --rm -v $1:$1 -w $PWD grape/contig:rgcrg-0.1 bash -c "samtools view -h $2 | grep -v '@CO\|@PG' | samtools view -Sb - > $(basename $2) 2>/dev/null"
}
get_file() {
baseDir=$1
filename=$2
case "$filename" in
*.bam) normalize_bam "$baseDir" "$filename" ;;
*) ln -fs "$filename"
esac
}
export -f get_file normalize_bam
RED="\033[1;31m"
GREEN="\033[1;32m"
YELLOW="\033[1;33m"
BLUE="\033[1;34m"
NORMAL="\033[0m"
[[ $1 == "help" ]] && usage
BASE_DIR=$(canonicalize_path $(dirname $0))
PROFILE=${PROFILE-"starrsem"}
CHECKDIR=${CHECKDIR-"checksum"}
RUN_OPTS=${RUN_OPTS-"-process.errorStrategy=terminate"}
WITH_DOCKER=${WITH_DOCKER-"1"}
[[ $WITH_DOCKER ]] && RUN_OPTS=" -with-docker"
echo -e "==$YELLOW Running pipeline with profile -> $BLUE${PROFILE}$NORMAL"
nxf_setup && nextflow run ${BASE_DIR} -profile $PROFILE ${RUN_OPTS} "$@"
echo -e "==$YELLOW Compare results$NORMAL"
mkcd $CHECKDIR
cut -f 3 ../pipeline.db | xargs -I{} bash -c "get_file $BASE_DIR {}"
md5sum -c ${BASE_DIR}/data/$PROFILE.md5
echo -e "==$YELLOW Clean up$NORMAL"
cd .. && rm -rf $CHECKDIR
echo -e "==$YELLOW DONE$NORMAL"