mahmoodn

gpu-blast-install

Jan 27th, 2020
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.94 KB | None | 0 0
  1. #!/bin/bash
  2. set -x
  3. #
  4. # Progress Indicator
  5. #
  6. function progress_ind {
  7. # Sleep at least 1 second otherwise this algorithm will consume
  8. # a lot system resources.
  9. interval=1
  10.  
  11. while true
  12. do
  13. echo -ne "."
  14. sleep $interval
  15. done
  16. }
  17.  
  18. #
  19. # Stop distraction
  20. #
  21. function stop_progress_ind {
  22. exec 2>/dev/null
  23. kill $1
  24. echo -en "\n"
  25. }
  26.  
  27. ncbi_blast_version="ncbi-blast-2.10"
  28. working_dir=`pwd`
  29. nvcc=`which nvcc`
  30.  
  31. if [ $? -ne 0 ]; then
  32. echo -e "\nError: nvcc cannot be found. Exiting..."
  33. exit 1
  34. fi
  35.  
  36. echo "Do you want to install GPU-BLAST on an existing installation of \"blastp\" [yes/no]"
  37. echo "yes: you will be asked for the installation directory of the \"blastp\" executable"
  38. echo "no: will download and install \"${ncbi_blast_version}\""
  39. read user_input
  40.  
  41. if [ $user_input == "yes" ]; then
  42. echo "Please input the installation directory of \"blastp\" of \"${ncbi_blast_version}\""
  43. read installed_dir
  44. #check if the executable "blastp" exists in the given directory
  45. if [ ! -x $installed_dir/blastp ]; then
  46. echo "Executable \"blastp\" cannot be found"
  47. echo "Exiting..."
  48. exit 0
  49. else
  50. blastp_version=`$installed_dir/blastp -version | grep blastp | awk '{print $NF}'`
  51. if [ $blastp_version == "2.2.28+" ]; then
  52. echo "\"blastp\" version $blastp_version is compatible"
  53. else
  54. echo "\"blastp\" version $blastp_version is not supported"
  55. echo "Exiting..."
  56. exit 0
  57. fi
  58. fi
  59. #check if the source file "blast_engine.c" as a first check that the source code exists
  60. if [ ! -f "$installed_dir/../../src/algo/blast/core/blast_engine.c" ]; then
  61. echo "Source code not detected."
  62. echo "You must have the source code of \"$ncbi_blast_version\" to add GPU-BLAST"
  63. echo "Exiting..."
  64. exit 0
  65. else
  66. echo "Continuing with the installation of GPU-BLAST..."
  67. download=0
  68. fi
  69. elif [ $user_input == "no" ]; then
  70. echo "Continuing with the downloading of $ncbi_blast_version..."
  71. download=1
  72. else
  73. echo "Please enter \"yes\" or \"no\""
  74. echo "Exiting.."
  75. exit 0
  76. fi
  77.  
  78. if [ $download == 1 ]; then
  79.  
  80.  
  81. #Download the version 2.2.28 of NCBI BLAST
  82. echo "Downloading NBCI BLAST"
  83. wget ftp://ftp.ncbi.nlm.nih.gov/blast/executables/blast+/2.2.28/${ncbi_blast_version}.tar.gz
  84. if [ $? -ne 0 ]; then
  85. echo -e "\nError downloading ${ncbi_blast_version}. Verify that the file exists in the server. Exiting..."
  86. exit 1
  87. fi
  88. echo -e "\nExtracting NCBI BLAST"
  89. progress_ind &
  90. pid=$!
  91. trap "stop_progress_ind $pid; exit" INT TERM EXIT
  92.  
  93. tar -xzf ${ncbi_blast_version}.tar.gz
  94.  
  95. stop_progress_ind $pid
  96.  
  97. #Move to the c++ directory which contains the configuration script
  98. cd ${working_dir}/${ncbi_blast_version}/c++/
  99.  
  100. #Configure NCBI BLAST
  101. progress_ind &
  102. pid=$!
  103. trap "stop_progress_ind $pid; exit" INT TERM EXIT
  104. configuration_options="./configure --without-debug --with-mt --without-sybase --without-ftds --without-fastcgi --without-ncbi-c --without-sssdb --without-sss --without-geo --without-sp --without-orbacus --without-boost"
  105. echo -e "\nConfiguring ${ncbi_blast_version} with options:"
  106. echo -e "\n${configuration_options}"
  107. echo -e "\nIf you want to change these options edit the file \"install\", delete the directory ${ncbi_blast_version}, and rerun install"
  108. $configuration_options > ${working_dir}/configure.output
  109. if [ $? -ne 0 ]; then
  110. echo -e "\nError in configuring NCBI BLAST installation. Look at \"configure.output\" for more information"
  111. exit 1
  112. fi
  113.  
  114. stop_progress_ind $pid
  115.  
  116. #extract the installation directory
  117. makefile_line=`cat ../../configure.output | grep Tools`
  118. makefile=`echo $makefile_line | awk -F" " '{print $NF}'`
  119. build_dir=`dirname $makefile`
  120. proj_dir=`dirname $build_dir`
  121. cxx_dir=`dirname $proj_dir`
  122. else
  123. build_dir="$installed_dir/../build/"
  124. proj_dir="$installed_dir/../"
  125. cxx_dir="$installed_dir/../../"
  126. fi
  127.  
  128. #Modify NCBI BLAST files
  129. echo -e "\nModifying NCBI BLAST files"
  130. cd ${working_dir}/gpu_blast/
  131. sh ./modify ${cxx_dir} > ${working_dir}/modify.output
  132.  
  133. if [ $? -ne 0 ]; then
  134. echo -e "\nError: while modifying the source code files. See \"modify.output\" for more details. Exiting..."
  135. exit 1
  136. fi
  137.  
  138. #Compile GPU code
  139. progress_ind &
  140. pid=$!
  141. trap "stop_progress_ind $pid; exit" INT TERM EXIT
  142.  
  143. echo -e "\nCompiling CUDA code"
  144.  
  145. bin_dir=`dirname ${nvcc}`
  146. cuda_dir=`dirname ${bin_dir}`
  147.  
  148. os_version=`uname -m`
  149. if [[ "$os_version" = "i686" ]]; then
  150. cudart_lib=${cuda_dir}/lib
  151. fi
  152.  
  153. if [[ "$os_version" = "x86_64" ]]; then
  154. cudart_lib=${cuda_dir}/lib64
  155. fi
  156.  
  157. if [[ ! -d ${cudart_lib} ]]; then
  158. echo "CUDA library directory cannot be found. Exiting installation..."
  159. exit 1
  160. fi
  161.  
  162. #make -f makefile.shared -B NVCC_PATH=${nvcc} PROJ_DIR=${proj_dir} CXX_DIR=${cxx_dir} CUDA_LIB=${cudart_lib} #> ${working_dir}/gpu_blast.output
  163. make -f Makefile -B NVCC_PATH=${nvcc} PROJ_DIR=${proj_dir} CXX_DIR=${cxx_dir} CUDA_LIB=${cudart_lib} > ${working_dir}/gpu_blast.output
  164.  
  165. #Modify CONF_LIB of Makefile.mk to inlcude the libraries -lgpublast and -lcudart
  166. cp ${build_dir}/Makefile.mk ${build_dir}/Makefile.mk.backup
  167. conf_libs_line=`cat ${build_dir}/Makefile.mk | grep ^CONF_LIB`
  168. conf_libs_line=${conf_libs_line}" -lgpublast -lcudart"
  169. sed "/^CONF_LIBS/ c\ ${conf_libs_line}" ${build_dir}/Makefile.mk > ${build_dir}/Makefile.mk.temp
  170. mv ${build_dir}/Makefile.mk.temp ${build_dir}/Makefile.mk
  171.  
  172. stop_progress_ind $pid
  173.  
  174. #Compile NCBI BLAST
  175. echo "Building NCBI BLAST with GPU BLAST"
  176. cd $build_dir
  177. progress_ind &
  178. pid=$!
  179. trap "stop_progress_ind $pid; exit" INT TERM EXIT
  180.  
  181. make all_r &> ${working_dir}/ncbi_blast.output
  182. if [ $? -ne 0 ]; then
  183. echo -e "\nError in NCBI BLAST installation. Look at \"ncbi_blast.output\" for more information"
  184. exit 1
  185. fi
  186.  
  187. stop_progress_ind $pid
  188.  
  189. exit 0;
Add Comment
Please, Sign In to add comment