forked from guigolab/grape-nf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.circ
executable file
·154 lines (137 loc) · 3.56 KB
/
.circ
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# Print usage information
_ci_usage() {
cat <<-MSG
Run CI tests
Commands:
run run the pipeline in '\$CI_DIR'
check compute checksums and validate results
clean remove the temporary directory used for vaildation
Notes:
If '\$CI_DIR' is in the Nextflow asset folder the pipeline is run using the GitHub repository
to allow to change revision from the comand line, e.g.:
CI_DIR=~/.nextflow/assets/guigolab/grape-nf ci test -r v0.4.1
MSG
}
# Get canonical path of either a directory or a file
_ci_canonicalize_path() {
if [ -d "$1" ]; then
_ci_canonicalize_dir_path "$1"
else
_ci_canonicalize_file_path "$1"
fi
}
# Get canonical path of a directory
_ci_canonicalize_dir_path() {
(cd "$1" 2>/dev/null && pwd -P)
}
# Get canonical path of a file
_ci_canonicalize_file_path() {
local dir file
dir=$(dirname -- "$1")
file=$(basename -- "$1")
(cd "$dir" 2>/dev/null && printf '%s/%s\n' "$(pwd -P)" "$file")
}
# Check that Nextflow is installed and download it to the current
# folder otherwise
_ci_setup_nxf() {
if ! nextflow &>/dev/null; then
export PATH=$PWD:$PATH
if [ ! -x nextflow ]; then
curl -fsSL get.nextflow.io | bash && chmod +x nextflow
fi
fi
}
# Get the content of a BAM file for checksum
_ci_normalize_bam() {
docker run --rm -v $CI_DIR:$CI_DIR -v $1:$1 -w $PWD grapenf/samtools:1.3.1 bash -c "samtools view -h $2 | grep -v '@CO\|@PG' | LC_ALL=C sort > $(basename $2) 2>/dev/null"
}
# Get file to the CI output directory either by creating a symlink
# or normalizing a BAM file
_ci_get_file() {
local baseDir=$1
local filename=$2
case "$filename" in
*.bam)
_ci_normalize_bam "$baseDir" "$filename" ;;
*.bed|*.bw|*.results|*.json|*.g[tf]f)
ln -fs "$filename";;
*)
echo "'${filename##*.}' extension not supported";;
esac
}
# Get current script being sourced
_ci_get_script_dir() {
local CI_SCRIPT="$1"
if [ ! -z "$BASH_SOURCE" ]
then
CI_SCRIPT=${BASH_SOURCE[0]}
fi
echo $(_ci_canonicalize_path $(dirname ${CI_SCRIPT}))
}
# Run the pipeline for CI
_ci_run() {
local WF=${CI_DIR}
if [[ "$CI_DIR" =~ "$HOME/.nextflow/asset" ]]; then
local ORG=$(basename $(dirname $CI_DIR))
local REPO=$(basename $CI_DIR)
WF="${ORG}/${REPO}"
fi
_ci_setup_nxf && nextflow run ${WF} -profile $CI_PROFILE "${CI_RUNOPTS[@]}" "$@"
}
# Check pipeline results for CI
_ci_check() {
(mkdir -p $CI_OUTDIR && cd $CI_OUTDIR
echo $CI_PROFILE > .ci_profile
cut -f 3 ../pipeline.db | while read f
do
_ci_get_file $(_ci_canonicalize_path ..) $f
done
md5sum -c ${CI_DIR}/data/$CI_PROFILE.md5)
}
# Cleanup CI result directory
_ci_clean() {
rm --interactive=never -r $CI_OUTDIR
}
# Perform a ful CI test
_ci_test() {
# Define colors
local RED="\033[1;31m"
local GREEN="\033[1;32m"
local YELLOW="\033[1;33m"
local BLUE="\033[1;34m"
local NORMAL="\033[0m"
echo -e "==$YELLOW Running with profile -> $BLUE${CI_PROFILE}$NORMAL" \
&& _ci_run "$@" \
&& echo -e "==$YELLOW Compute MD5 checksums$NORMAL" \
&& _ci_check \
&& echo -e "==$GREEN SUCCESS$NORMAL" \
&& echo -e "==$YELLOW Cleaning up$NORMAL" \
&& _ci_clean \
&& echo -e "==$YELLOW DONE$NORMAL" && exit 0 \
|| echo -e "==$RED FAILED$NORMAL" && exit 1
}
# Main command
ci() {
case $1 in
run)
shift
(_ci_run "$@");;
check)
shift
(_ci_check);;
clean)
shift
(_ci_clean);;
test)
shift
(_ci_test "$@");;
*)
_ci_usage;;
esac
}
# Define CI environment variables
CI_DIR=$(_ci_get_script_dir $0)
CI_LOG=pipeline-ci.log
CI_PROFILE="starrsem"
CI_OUTDIR="checksum"
CI_RUNOPTS=("-process.errorStrategy=terminate" "-with-docker")