File: install-CGAT-tools.sh

package info (click to toggle)
python-pysam 0.15.2%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 17,604 kB
  • sloc: ansic: 125,787; python: 7,782; sh: 284; makefile: 222; perl: 41
file content (281 lines) | stat: -rwxr-xr-x 5,997 bytes parent folder | download | duplicates (5)
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
#!/usr/bin/env bash

# function to detect the Operating System
detect_os(){

if [ -f /etc/os-release ]; then

   OS=$(cat /etc/os-release | awk '/VERSION_ID/ {sub("="," "); print $2;}' | sed 's/\"//g' | awk '{sub("\\."," "); print $1;}')
   if [ "$OS" != "12" ] ; then

      echo       
      echo " Ubuntu version not supported "
      echo
      echo " Only Ubuntu 12.x has been tested so far "
      echo 
      exit 1;

   fi

   OS="ubuntu"

elif [ -f /etc/system-release ]; then

   OS=$(cat /etc/system-release | awk ' {print $4;}' | awk '{sub("\\."," "); print $1;}')
   if [ "$OS" != "6" ] ; then
      echo
      echo " Scientific Linux version not supported "
      echo
      echo " Only 6.x Scientific Linux has been tested so far "
      echo
      exit 1;
   fi

   OS="sl"

else

   echo
   echo " Operating system not supported "
   echo
   echo " Exiting installation "
   echo
   exit 1;

fi
} # detect_os

# message to display when the OS is not correct
sanity_check_os() {
   echo
   echo " Unsupported operating system: $OS "
   echo " Installation aborted "
   echo
   exit 1;
} # sanity_check_os

# function to install operating system dependencies
install_os_packages() {

if [ "$OS" == "ubuntu" -o "$OS" == "travis" ] ; then

   echo
   echo " Installing packages for Ubuntu "
   echo

   apt-get install -y gcc g++

elif [ "$OS" == "sl" ] ; then

   echo 
   echo " Installing packages for Scientific Linux "
   echo

   yum -y install gcc zlib-devel gcc-c++

else

   sanity_check_os

fi # if-OS
} # install_os_packages

# funcion to install Python dependencies
install_python_deps() {

if [ "$OS" == "ubuntu" -o "$OS" == "sl" ] ; then

   echo
   echo " Installing Python dependencies for $1 "
   echo

   # Create virtual environment
   cd
   mkdir CGAT
   cd CGAT
   wget --no-check-certificate https://pypi.python.org/packages/source/v/virtualenv/virtualenv-1.10.1.tar.gz
   tar xvfz virtualenv-1.10.1.tar.gz
   rm virtualenv-1.10.1.tar.gz
   cd virtualenv-1.10.1
   python virtualenv.py cgat-venv
   source cgat-venv/bin/activate

   # Install Python prerequisites
   pip install cython

elif [ "$OS" == "travis" ] ; then
   # Travis-CI provides a virtualenv with Python 2.7
   echo 
   echo " Installing Python dependencies in travis "
   echo

   # Install Python prerequisites
   pip install cython
   pip install nose

else

   sanity_check_os

fi # if-OS
} # install_python_deps

# common set of tasks to prepare external dependencies
nosetests_external_deps() {
echo
echo " Running nosetests for $1 "
echo

pushd .

# create a new folder to store external tools
mkdir -p $HOME/CGAT/external-tools

# install samtools
cd $HOME/CGAT/external-tools
curl -L http://downloads.sourceforge.net/project/samtools/samtools/1.3/samtools-1.3.tar.bz2 > samtools-1.3.tar.bz2
tar xjf samtools-1.3.tar.bz2 
cd samtools-1.3
make
PATH=$PATH:$HOME/CGAT/external-tools/samtools-1.3

echo "installed samtools"
samtools --version

if [ $? != 0 ]; then
    exit 1
fi

# install bcftools
cd $HOME/CGAT/external-tools
curl -L https://github.com/samtools/bcftools/releases/download/1.3/bcftools-1.3.tar.bz2 > bcftools-1.3.tar.bz2
tar xjf bcftools-1.3.tar.bz2
cd bcftools-1.3
make
PATH=$PATH:$HOME/CGAT/external-tools/bcftools-1.3

echo "installed bcftools"
bcftools --version

if [ $? != 0 ]; then
    exit 1
fi

popd

} # nosetests_external_deps


# function to run nosetests
run_nosetests() {

echo
echo " Running nosetests for $1 "
echo

# prepare external dependencies
nosetests_external_deps $OS

# install code
python setup.py install

# change into tests directory. Otherwise,
# 'import pysam' will import the repository,
# not the installed version. This causes
# problems in the compilation test.
cd tests

# create auxilliary data
echo
echo 'building test data'
echo 
make -C pysam_data all
make -C cbcf_data all

# run nosetests
# -s: do not capture stdout, conflicts with pysam.dispatch
# -v: verbose output
nosetests -s -v 

} # run_nosetests

# function to display help message
help_message() {
echo
echo " Use this script as follows: "
echo
echo " 1) Become root and install the operating system* packages: "
echo " ./install-CGAT-tools.sh --install-os-packages"
echo
echo " 2) Now, as a normal user (non root), install the Python dependencies**: "
echo " ./install-CGAT-tools.sh --install-python-deps"
echo
echo " At this stage the CGAT Code Collection is ready to go and you do not need further steps. Please type the following for more information:"
echo " source $HOME/CGAT/virtualenv-1.10.1/cgat-venv/bin/activate"
echo " cgat --help "
echo
echo " The CGAT Code Collection tests the software with nosetests. If you are interested in running those, please continue with the following steps:"
echo
echo " 3) Become root to install external tools and set up the environment: "
echo " ./install-CGAT-tools.sh --install-nosetests-deps"
echo
echo " 4) Then, back as a normal user (non root), run nosetests as follows:"
echo " ./install-CGAT-tools.sh --run-nosetests"
echo 
echo " NOTES: "
echo " * Supported operating systems: Ubuntu 12.x and Scientific Linux 6.x "
echo " ** An isolated virtual environment will be created to install Python dependencies "
echo
exit 1;
}


# the main script starts here

if [ $# -eq 0 -o $# -gt 1 ] ; then

   help_message

else

   if [ "$1" == "--help" ] ; then

      help_message

   elif [ "$1" == "--travis" ] ; then

      OS="travis"
      install_os_packages
      install_python_deps
      run_nosetests

   elif [ "$1" == "--install-os-packages" ] ; then

      detect_os
      install_os_packages

   elif [ "$1" == "--install-python-deps" ] ; then

      detect_os
      install_python_deps

   elif [ "$1" == "--install-nosetests-deps" ] ; then

      detect_os
      install_nosetests_deps

   elif [ "$1" == "--run-nosetests" ] ; then

      detect_os
      run_nosetests

   else 

      echo 
      echo " Incorrect input parameter: $1 "
      help_message

   fi # if argument 1

fi # if number of input parameters