-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_refgenie.sh
executable file
·148 lines (117 loc) · 6.33 KB
/
test_refgenie.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
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
#!/bin/bash
# Set up script
shopt -s expand_aliases
set -e
alias python=python3.6
# Work in virtual environment (requires virtualenv to be installed)
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
export WORKDIR="$DIR/testing_refgenie"
export VENVDIR="$DIR/venv_refgenie"
# requires bulker to be installed
#python -m pip install --user --upgrade bulker
PROGNAME=$(basename $0)
ErrorExit()
{
#
# Function to handle error
# :param str 1: descriptive error message
#
echo "${PROGNAME}: ${1:-"Unknown Error"}" 1>&2
# remove any created directories or files prior to exit
if [ -d "$WORKDIR" ]; then
rm -rf $WORKDIR
fi
if [ -d "$VENVDIR" ]; then
rm -rf $VENVDIR
fi
exit 1
}
# activate bulker environment so you can build stuff (samtools etc)
# Requires BULKERCFG environment variable to be set
# Must load once before activating
#bulker load databio/refgenie:0.7.0
# [Must prevent bulker activate from creating a new shell](https://bulker.databio.org/en/dev/tips/#how-can-i-prevent-bulker-activate-from-creating-a-new-shell)
echo -e "\n-- Activate bulker --\n"
bulker-activate() {
eval "$(bulker activate -e $@)"
}
bulker-activate databio/refgenie:0.7.3 || ErrorExit "$LINENO: Failed to activate bulker."
echo -e "\n-- Create and activate virtualenv --\n"
python -m venv $VENVDIR || ErrorExit "$LINENO: Failed to create virtual environment."
source $VENVDIR/bin/activate || ErrorExit "$LINENO: Failed to activate virtual environment."
# `refgenie` universe testing
mkdir $WORKDIR && cd $WORKDIR || ErrorExit "$LINENO: Failed to create working environment."
# install refgenie universe tools
python -m pip install --quiet wheel || ErrorExit "$LINENO: Failed to install wheel module."
echo -e "\n-- Create dockerfile --\n"
cat > testrgs.Dockerfile <<EOF
FROM tiangolo/uvicorn-gunicorn:python3.7-alpine3.8
LABEL authors="Nathan Sheffield, Michal Stolarczyk"
COPY . /app
# RUN pip install https://github.com/databio/refgenconf/archive/dev.zip
# RUN pip install https://github.com/databio/refgenieserver/archive/dev.zip
RUN pip install https://github.com/databio/refgenieserver/archive/master.zip
EOF
if [ ! -f "$WORKDIR/testrgs.Dockerfile" ]; then
ErrorExit "$LINENO: Failed to create test Dockerfile."
fi
echo -e "\n-- Build refgenieserver container --\n"
docker build -t testrgs --no-cache -f testrgs.Dockerfile . || ErrorExit "$LINENO: Failed to build refgenieserver container."
echo -e "\n-- Grab a small test asset --\n"
wget http://big.databio.org/example_data/rCRS.fa.gz || ErrorExit "$LINENO: Failed to retrieve test fastq file."
echo -e "\n-- Initialize refgenie --\n"
refgenie init -c refgenie_rCRS.yaml || ErrorExit "$LINENO: Failed to initialize refgenie."
refgenie init -c refgenie_test.yaml || ErrorExit "$LINENO: Failed to initialize refgenie."
echo -e "\n-- Build assets --\n"
refgenie build -c refgenie_rCRS.yaml -g rCRS -a fasta --files fasta=rCRS.fa.gz || ErrorExit "$LINENO: Failed to build rCRS asset."
refgenie build -c refgenie_test.yaml -g test -a fasta --files fasta=rCRS.fa.gz || ErrorExit "$LINENO: Failed to build test asset."
echo -e "\n-- Add genome_archive to refgenie config files --"
sed -i '' '1s;^;genome_archive: $WORKDIR/archive\
;' refgenie_rCRS.yaml
sed -i '' '1s;^;genome_archive: $WORKDIR/archive2\
;' refgenie_test.yaml
echo -e "\n-- Archive asset --\n"
docker run --user=$(id -u):$(id -g) -v $WORKDIR:$WORKDIR -e WORKDIR=`echo $WORKDIR` testrgs refgenieserver archive -c $WORKDIR/refgenie_rCRS.yaml || ErrorExit "$LINENO: Failed to archive rCRS asset."
docker run --user=$(id -u):$(id -g) -v $WORKDIR:$WORKDIR -e WORKDIR=`echo $WORKDIR` testrgs refgenieserver archive -c $WORKDIR/refgenie_test.yaml || ErrorExit "$LINENO: Failed to archive test asset."
echo -e "\n-- Run refgenieserver --\n"
docker run --rm -d -p 80:80 --name refgenieservercon -v $WORKDIR/archive:/genomes testrgs refgenieserver serve -c /genomes/refgenie_rCRS.yaml || ErrorExit "$LINENO: Failed to run rCRS refgenieserver."
docker run --rm -d -p 81:80 --name refgenieservercon2 -v $WORKDIR/archive2:/genomes testrgs refgenieserver serve -c /genomes/refgenie_test.yaml || ErrorExit "$LINENO: Failed to run test refgenieserver."
echo -e "\n-- Initialize multiserver refgenie config --\n"
mkdir pull_test || ErrorExit "$LINENO: Failed to create pull_test directory."
export REFGENIE=pull_test/refgenie_multiserver_testing.yaml
refgenie init -c $REFGENIE -s http://0.0.0.0:80 http://0.0.0.0:81 || ErrorExit "$LINENO: Failed to initialize multiserver refgenie yaml file."
echo -e "\n-- List all remote assets --\n"
refgenie listr -c $REFGENIE || ErrorExit "$LINENO: Failed to list remote assets."
echo -e "\n-- List rCRS remote assets --\n"
refgenie listr -c $REFGENIE -g rCRS || ErrorExit "$LINENO: Failed to list remote rCRS assets."
refgenie listr -c $REFGENIE -g test || ErrorExit "$LINENO: Failed to list remote test assets."
echo -e "\n-- Pull remote asset --\n"
refgenie pull -c $REFGENIE rCRS/fasta || ErrorExit "$LINENO: Failed to pull remote rCRS asset."
refgenie pull -c $REFGENIE test/fasta || ErrorExit "$LINENO: Failed to pull remote test asset."
echo -e "\n-- List local assets --\n"
refgenie list -c $REFGENIE || ErrorExit "$LINENO: Failed to list local assets."
echo -e "\n-- Tag asset --\n"
refgenie tag -c $REFGENIE test/fasta:default --tag test || ErrorExit "$LINENO: Failed to tag asset."
echo -e "\n-- Remove asset --\n"
refgenie remove -c $REFGENIE test/fasta --force || ErrorExit "$LINENO: Failed to remove asset."
echo -e "\n-- Get asset digest --\n"
refgenie id -c $REFGENIE rCRS/fasta || ErrorExit "$LINENO: Failed to get asset digest."
echo -e "\n-- Subscribe --\n"
refgenie subscribe -c $REFGENIE -s http://faulty.com || ErrorExit "$LINENO: Failed to subscribe."
echo -e "\n-- Unsubscribe --\n"
refgenie subscribe -c $REFGENIE -s http://faulty.com || ErrorExit "$LINENO: Failed to unsubscribe."
echo -e "\n-- Shut down local servers --\n"
docker stop refgenieservercon || ErrorExit "$LINENO: Failed to stop remote rCRS server."
docker stop refgenieservercon2 || ErrorExit "$LINENO: Failed to stop remote test server."
echo -e "\n-- Deactivate the virtual environment --"
deactivate || ErrorExit "$LINENO: Failed to deactivate virtual environment."
echo -e "\n-- Clean up workspace --"
cd $DIR || ErrorExit "$LINENO: Failed to change to parent directory."
if [ -d "$WORKDIR" ]; then
rm -rf $WORKDIR
fi
if [ -d "$VENVDIR" ]; then
rm -rf $VENVDIR
fi
echo -e "\n-- DONE! --"
exit 0