diff --git a/01_deploy_via_Docker.sh b/01_deploy_via_Docker.sh index 2146cc0..ae823e1 100644 --- a/01_deploy_via_Docker.sh +++ b/01_deploy_via_Docker.sh @@ -3,7 +3,24 @@ source scripts/colored_print.sh source scripts/check_and_set_email_credentials.sh source scripts/check_CPU_number.sh + +# Function to extract port number from configuration file +extract_port() { + local file=$1 + grep -Eo "listen\s+[0-9]+" "$file" | grep -Eo "[0-9]+" +} + +# Function to format and display elapsed time +show_time() { + local elapsed_time=$1 + local hours=$((elapsed_time / 3600)) + local minutes=$(( (elapsed_time % 3600) / 60)) + local seconds=$((elapsed_time % 60)) + printf "\rElapsed time: %02d:%02d:%02d" $hours $minutes $seconds +} + set -e +chmod -R 766 data result #################### 1 email print_green "1. Configurations of email to send results" @@ -13,7 +30,56 @@ check_and_set_email_credentials print_green "2. Configuration of CPU number" check_cpu_number -#################### 3. Docker build -print_green "3. Docker building" -chmod 777 logs result -docker-compose up -d + +#################### 3. Update shiny and nginx configuration files +print_green "3. Update shiny and nginx configuration files" + +SHINY_CONF="conf/shiny-server.conf" +NGINX_CONF="conf/nginx.conf" + +rm -rf $SHINY_CONF +rm -rf $NGINX_CONF + +print_green "Generating shiny-server.conf..." +bash scripts/create_shiny_server_conf.sh start +print_green "\nGenerating nginx.conf..." +bash scripts/create_nginx_conf.sh start + +# remove line with run_as +sed -i '/^run_as/d' $SHINY_CONF + +# Extract port numbers +NGINX_PORT=$(extract_port "$NGINX_CONF") +SHINY_PORT=$(extract_port "$SHINY_CONF") + +# update nginx link +echo "http://localhost:$NGINX_PORT/result/" > data/nginx_link.txt + +#################### 4. Update dockerfiles and docker-compose.yml +print_green "4. Update dockerfiles and docker-compose.yml" + +# update dockerfiles +sed -i "s|EXPOSE [0-9]*|EXPOSE $NGINX_PORT|" dockerfiles/Dockerfile.nginx +sed -i "s|EXPOSE [0-9]*|EXPOSE $SHINY_PORT|" dockerfiles/Dockerfile.shiny + +# update docker-compose.yml +bash scripts/create_docker_compose.sh $SHINY_PORT $NGINX_PORT + +#################### 5. Docker build +print_green "5. Docker building" + +start_time=$(date +%s) + +docker-compose up -d > logs/docker_img_build.log 2>&1 & + +build_pid=$! +# While the build process is running, display the elapsed time +while kill -0 $build_pid 2> /dev/null; do + current_time=$(date +%s) + elapsed_time=$((current_time - start_time)) + show_time $elapsed_time + sleep 1 +done + +print_green "\n\nYou are safe to colse this console." +wait diff --git a/R/app.R b/R/app.R index 72228bd..1079533 100644 --- a/R/app.R +++ b/R/app.R @@ -1,5 +1,5 @@ -Sys.setenv(R_LIBS_USER = "/usr/local/lib/R/library") -.libPaths(new = "/usr/local/lib/R/library") +# Sys.setenv(R_LIBS_USER = "/usr/local/lib/R/library") +# .libPaths(new = "/usr/local/lib/R/library") source("R/global.R") diff --git a/R/global.R b/R/global.R index c071a88..a625a2e 100644 --- a/R/global.R +++ b/R/global.R @@ -1,5 +1,5 @@ -Sys.setenv(R_LIBS_USER = "/usr/local/lib/R/library") -.libPaths(new = "/usr/local/lib/R/library") +# Sys.setenv(R_LIBS_USER = "/usr/local/lib/R/library") +# .libPaths(new = "/usr/local/lib/R/library") options(shiny.maxRequestSize = 30000 * 1024^2) diff --git a/R/utils/send_mail.R b/R/utils/send_mail.R index f93ab0e..9167edb 100644 --- a/R/utils/send_mail.R +++ b/R/utils/send_mail.R @@ -39,6 +39,9 @@ # SendResultMail(recipient = recipient, result_link = result_link) +library(dplyr) +library(emayili) + SendResultMail <- function(recipient = NULL, result_link = NULL) { email_credential <- readLines("data/email_credential.txt") diff --git a/app.R b/app.R index 6ebdb0a..737e456 100644 --- a/app.R +++ b/app.R @@ -1,5 +1,5 @@ -Sys.setenv(R_LIBS_USER = "/usr/local/lib/R/library") -.libPaths(new = "/usr/local/lib/R/library") +# Sys.setenv(R_LIBS_USER = "/usr/local/lib/R/library") +# .libPaths(new = "/usr/local/lib/R/library") source("R/app.R") diff --git a/01_deploy_via_bash.sh b/archive/01_deploy_via_bash.sh similarity index 100% rename from 01_deploy_via_bash.sh rename to archive/01_deploy_via_bash.sh diff --git a/archive/test_nginx.sh b/archive/test_nginx.sh new file mode 100644 index 0000000..e54c218 --- /dev/null +++ b/archive/test_nginx.sh @@ -0,0 +1,20 @@ +#!/bin/bash +source scripts/colored_print.sh + +rm -rf conf/nginx_singularity.conf + +print_green "生成nginx_singularity.conf..." +bash scripts/create_nginx_conf_singularity.sh start + +# 定义文件和镜像名称 +DEF_FILE="Singularities/Singularity_nginx.def" +SIMG_FILE="Singularities/nginx.simg" + +rm -f "$SIMG_FILE" +print_orange "已删除 $SIMG_FILE 文件,并重现构建镜像。" +singularity build --fakeroot $SIMG_FILE $DEF_FILE + +#################################### 运行镜像 #################################### +singularity run \ + --bind ./result:/etc/nginx/html \ + $SIMG_FILE \ No newline at end of file diff --git a/conf/nginx.conf b/conf/nginx.conf index dbf6cfa..eedf255 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,12 +1,12 @@ server { - listen 84; - listen [::]:84; + listen 19258; + listen [::]:19258; server_name localhost_pmet; - # access_log /var/log/nginx/localhost.access.log; + # access_log /var/log/nginx/localhost_pmet.access.log; location /result { # autoindex on; - alias /usr/share/nginx/pmet; + alias /etc/nginx/html; } } diff --git a/conf/shiny-server.conf b/conf/shiny-server.conf index 68d48a1..ff21a45 100644 --- a/conf/shiny-server.conf +++ b/conf/shiny-server.conf @@ -1,13 +1,10 @@ -# Instruct Shiny Server to run applications as the user "shiny" -run_as shiny; - -# Define a server that listens on port 3838 +run_as wang; server { - listen 3838; + listen 4615; # Define a location at the base URL location / { - app_idle_timeout 0; + # Host the directory of Shiny Apps stored in this directory site_dir /srv/shiny-server; @@ -17,5 +14,8 @@ server { # When a user visits the base URL rather than a particular application, # an index of the applications available in this directory will be shown. directory_index on; + + # keep shiny app alive + app_idle_timeout 0; } } diff --git a/data/nginx_link.txt b/data/nginx_link.txt index a1491b2..dc393eb 100644 --- a/data/nginx_link.txt +++ b/data/nginx_link.txt @@ -1 +1 @@ -https://bar.utoronto.ca/pmet_result/ +http://localhost:84/result/ \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index b8ab219..2281a70 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,11 +5,15 @@ services: build: context: . dockerfile: dockerfiles/Dockerfile.shiny + container_name: shiny + user: "1000:1000" volumes: - - ./result:/home/shiny/PMET_docker/result - - ./logs:/var/log/shiny-server + # - ./data/indexing:/home/shiny/PMET_docker/data/indexing + # - ./result:/home/shiny/PMET_docker/result + # - ./logs:/var/log/shiny-server + - ./result:/srv/shiny-server/pmet/result ports: - - "3838:3838" + - "4615:4615" networks: - app-network @@ -17,16 +21,15 @@ services: build: context: . dockerfile: dockerfiles/Dockerfile.nginx - container_name: test_nginx + container_name: nginx volumes: - - ./result:/usr/share/nginx/pmet + - ./result:/etc/nginx/html ports: - - "84:84" + - "19258:19258" restart: always networks: - app-network - volumes: logs: result: diff --git a/dockerfiles/Dockerfile.nginx b/dockerfiles/Dockerfile.nginx index 0af436e..38d57bc 100644 --- a/dockerfiles/Dockerfile.nginx +++ b/dockerfiles/Dockerfile.nginx @@ -2,13 +2,13 @@ FROM nginx:latest # 创建结果目录 -RUN mkdir -p /usr/share/nginx/pmet && \ - chmod -R 777 /usr/share/nginx/pmet +RUN mkdir -p /etc/nginx/html && \ + chmod -R 777 /etc/nginx/html COPY ./conf/nginx.conf /etc/nginx/conf.d/pmet.conf # Expose Nginx's default port -EXPOSE 84 +EXPOSE 19258 # Start Nginx service CMD ["nginx", "-g", "daemon off;"] diff --git a/dockerfiles/Dockerfile.shiny b/dockerfiles/Dockerfile.shiny index c973767..3f5e9ae 100644 --- a/dockerfiles/Dockerfile.shiny +++ b/dockerfiles/Dockerfile.shiny @@ -1,11 +1,17 @@ FROM rocker/shiny:4.3.3 ############################## 1. shiny setting ############################### +# 添加 shiny 用户到 sudo 组 +RUN usermod -aG sudo shiny + COPY ./conf/shiny-server.conf /etc/shiny-server/shiny-server.conf ENV work_dir="/home/shiny/PMET_docker" +WORKDIR $work_dir COPY . $work_dir +RUN chown -R shiny:shiny $work_dir && \ + chmod -R 777 $work_dir RUN ln -sf $work_dir /srv/shiny-server/pmet # Use the find command to find all .sh, .r, .py, .pl files and grant them 755 permissions @@ -17,28 +23,31 @@ RUN $work_dir/scripts/install_apt_tools.sh # ############################## 3. R libs settings ############################### -ENV R_LIBS_USER=/usr/local/lib/R/library -# Set the directory owner and permissions -RUN mkdir -p $R_LIBS_USER && \ - chmod -R 777 $R_LIBS_USER -# Set environment variables in respective user profiles -RUN echo "export R_LIBS_USER='$R_LIBS_USER'" >> /root/.bashrc && \ - echo "export R_LIBS_USER='$R_LIBS_USER'" >> /home/shiny/.bashrc && \ - echo "R_LIBS_USER='$R_LIBS_USER'" >> /root/.Renviron && \ - echo "R_LIBS_USER='$R_LIBS_USER'" >> /home/shiny/.Renviron +# ENV R_LIBS_USER=/usr/local/lib/R/library + +# RUN chown -R shiny:shiny $R_LIBS_USER && \ +# chmod -R 755 $R_LIBS_USER +# # # Set the directory owner and permissions +# # RUN mkdir -p $R_LIBS_USER && \ +# # chmod -R 777 $R_LIBS_USER +# # # Set environment variables in respective user profiles +# # RUN echo "export R_LIBS_USER='$R_LIBS_USER'" >> /root/.bashrc && \ +# # echo "export R_LIBS_USER='$R_LIBS_USER'" >> /home/shiny/.bashrc && \ +# # echo "R_LIBS_USER='$R_LIBS_USER'" >> /root/.Renviron && \ +# # echo "R_LIBS_USER='$R_LIBS_USER'" >> /home/shiny/.Renviron ############################## 4. install R libs ############################### -# # Configure Java using R CMD javareconf +# Configure Java using R CMD javareconf RUN sudo R CMD javareconf # # renv for package management # RUN Rscript -e "install.packages(c('remotes', 'littler', 'docopt', 'renv', 'jsonlite'))" -# RUN Rscript -e "renv::restore()" +# RUN Rscript -e "Sys.setenv(R_INSTALL_STAGED = FALSE);renv::restore();renv::install('jsonlite')" RUN Rscript $work_dir/R/utils/install_packages.R -RUN rsync -av --ignore-existing /usr/local/lib/R/library/ /usr/local/lib/R/site-library/ && \ - rsync -av --ignore-existing /usr/local/lib/R/site-library/ /usr/local/lib/R/library/ +# RUN rsync -av --ignore-existing /usr/local/lib/R/library/ /usr/local/lib/R/site-library/ && \ +# rsync -av --ignore-existing /usr/local/lib/R/site-library/ /usr/local/lib/R/library/ ############################## 5. install python libs ############################### @@ -51,18 +60,18 @@ RUN $work_dir/scripts/install_python_libs.sh RUN apt -y install bedtools # Samtools 1.3.1 # -ENV SAMTOOLS_INSTALL_DIR=/opt/samtools -ENV HTSLIB_INSTALL_DIR=/opt/htslib - WORKDIR /tmp RUN wget https://github.com/samtools/samtools/releases/download/1.17/samtools-1.17.tar.bz2 && \ tar -xjf samtools-1.17.tar.bz2 && \ cd samtools-1.17 && \ - ./configure --disable-lzma --prefix=$SAMTOOLS_INSTALL_DIR && \ + ./configure --disable-lzma --prefix=/opt/samtools && \ make && \ make install && \ cd / && \ rm -rf /tmp/samtools-1.17 /tmp/samtools-1.17.tar.bz2 + +RUN echo "export PATH=/opt/samtools/bin:$PATH" >> /root/.bashrc && \ + echo "export PATH=/opt/samtools/bin:$PATH" >> /home/shiny/.bashrc # Set the working directory back to the root directory WORKDIR $work_dir @@ -104,6 +113,11 @@ RUN cd $work_dir/PMETdev/src/pmet \ ############################# 8. download homotypic data ############################## RUN $work_dir/scripts/download_pmet_indexing.sh +# RUN chmod -R 777 $work_dir/data $work_dir/result + + +# Clean apt cache to reduce image size +RUN apt-get clean && rm -rf /var/lib/apt/lists/* -EXPOSE 3838 +EXPOSE 4615 CMD ["/usr/bin/shiny-server"] diff --git a/logs/.gitkeep b/logs/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/scripts/create_docker_compose.sh b/scripts/create_docker_compose.sh new file mode 100644 index 0000000..04fc56f --- /dev/null +++ b/scripts/create_docker_compose.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +# 检查是否提供了两个参数 +if [ "$#" -ne 2 ]; then + echo "Usage: $0 " + exit 1 +fi + +SHINY_CONF=$1 +NGINX_CONF=$2 + +# 生成 docker-compose.yml 文件 +cat < docker-compose.yml +x-yml-version: '3.8' + +services: + shiny-app: + build: + context: . + dockerfile: dockerfiles/Dockerfile.shiny + container_name: shiny + user: "$(id -u):$(id -g)" + volumes: + # - ./data/indexing:/home/shiny/PMET_docker/data/indexing + # - ./result:/home/shiny/PMET_docker/result + # - ./logs:/var/log/shiny-server + - ./result:/srv/shiny-server/pmet/result + ports: + - "$SHINY_CONF:$SHINY_CONF" + networks: + - app-network + + nginx-server: + build: + context: . + dockerfile: dockerfiles/Dockerfile.nginx + container_name: nginx + volumes: + - ./result:/etc/nginx/html + ports: + - "$NGINX_CONF:$NGINX_CONF" + restart: always + networks: + - app-network + +volumes: + logs: + result: + +networks: + app-network: +EOF diff --git a/scripts/create_nginx_conf.sh b/scripts/create_nginx_conf.sh new file mode 100644 index 0000000..ba7d800 --- /dev/null +++ b/scripts/create_nginx_conf.sh @@ -0,0 +1,96 @@ +#!/bin/bash + +usage() { + echo "Usage: + -------------------------------------------------------------------------- + 1. Use this script to generate your nginx.conf configuration + + /bin/bash create_nginx_conf.sh + + -------------------------------------------------------------------------- + 2. If needed, you can provide the following arguments + + Commands: + help: show help and exit + + Options: + --port: the port for the application (default is 84) + --base: base folder with applications (default is /etc/nginx/html) + --server-name: server name for Nginx configuration (default is localhost_pmet) + + -------------------------------------------------------------------------- + 3. The generated nginx.conf will be saved to the current directory. + " +} + +# Default values +NGINX_PORT=84 +NGINX_BASE=/etc/nginx/html +NGINX_SERVER_NAME=localhost_pmet + +while true; do + NGINX_PORT=$(( ( RANDOM % 60000 ) + 1025 )) # 选择一个 1025 到 65535 之间的随机端口 + (echo > /dev/tcp/localhost/$NGINX_PORT) >/dev/null 2>&1 + result=$? + if [ $result -ne 0 ]; then # 如果返回非0值,表示端口未被占用 + echo "Selected free port: $NGINX_PORT" + break + fi +done + +if [ $# -eq 0 ]; then + usage + exit +fi + +while true; do + case ${1:-} in + -h|--help|help) + usage + exit + ;; + -p|--port|port) + shift + NGINX_PORT="${1:-}" + shift + ;; + -b|--base|base) + shift + NGINX_BASE="${1:-}" + shift + ;; + -sn|--server-name|server-name) + shift + NGINX_SERVER_NAME="${1:-}" + shift + ;; + -*) + echo "Unknown option: ${1:-}" + exit 1 + ;; + *) + break + ;; + esac +done + +# Generate nginx.conf +cat < conf/nginx.conf +server { + listen ${NGINX_PORT}; + listen [::]:${NGINX_PORT}; + server_name ${NGINX_SERVER_NAME}; + + # access_log /var/log/nginx/${NGINX_SERVER_NAME}.access.log; + + location /result { + # autoindex on; + alias ${NGINX_BASE}; + } +} +EOF + +echo "conf/nginx.conf has been generated with the following settings:" +echo "Port: ${NGINX_PORT}" +echo "Base directory: ${NGINX_BASE}" +echo "Server name: ${NGINX_SERVER_NAME}" \ No newline at end of file diff --git a/scripts/create_shiny_server_conf.sh b/scripts/create_shiny_server_conf.sh new file mode 100644 index 0000000..a545f16 --- /dev/null +++ b/scripts/create_shiny_server_conf.sh @@ -0,0 +1,195 @@ +#!/bin/bash + +usage () { + + echo "Steps: + ---------------------------------------------------------------------- + 1. Use this script to prepare your shiny-server.conf (configuration) + + /bin/bash prepare_template.sh + + ---------------------------------------------------------------------- + 2. If needed, you can provide the following arguments + + Commands: + help: show help and exit + start: the generation of your config + + Options: + --port: the port for the application (e.g., shiny default is 3737) + --user: the user for the run_as directive in the shiny configuration + --base: base folder with applications + --logs: temporary folder with write for logs (not required) + --disable-index: disable directory indexing + + ---------------------------------------------------------------------- + 3. Make sure Singularity is loaded, and run the container using + the commands shown by the template. + + " +} + +# Start the application +SHINY_START="no"; + +# # Port for Flask +# # Find an unused port number +# CHECK_PORT="notnull" +# while [[ ! -z $CHECK_PORT ]]; do +# SHINY_PORT=$(( ( RANDOM % 60000 ) + 1025 )) +# CHECK_PORT=$(netstat -atn | grep $SHINY_PORT) +# done +while true; do + SHINY_PORT=$(( ( RANDOM % 60000 ) + 1025 )) # 选择一个 1025 到 65535 之间的随机端口 + (echo > /dev/tcp/localhost/$SHINY_PORT) >/dev/null 2>&1 + result=$? + if [ $result -ne 0 ]; then # 如果返回非0值,表示端口未被占用 + echo "Selected free port: $SHINY_PORT" + break + fi +done + + +# Base for apps +SHINY_BASE=/srv/shiny-server; + +# Log folder assumed to be bound to +# SHINY_LOGS=$(mktemp -d /tmp/shiny-server.XXXXXX) && rmdir ${SHINY_LOGS}; +SHINY_LOGS=/var/log/shiny-server + +# Disable indexing (on, default, is not disabled) +DISABLE_DIRINDEX="on"; + +# User to run_as, defaults to docker +SHINY_USER="${USER}" + +if [ $# -eq 0 ]; then + usage + exit +fi + +while true; do + case ${1:-} in + -h|--help|help) + usage + exit + ;; + -s|--start|start) + SHINY_START="yes" + shift + ;; + -p|--port|port) + shift + SHINY_PORT="${1:-}" + shift + ;; + -b|--base|base) + shift + SHINY_BASE="${1:-}" + shift + ;; + -u|--user) + shift + SHINY_USER="${1:-}" + shift + ;; + -di|--disable-index|disable-index) + DISABLE_DIRINDEX="off" + shift + ;; + -l|logs|--logs) + shift + SHINY_LOGS="${1:-}" + shift + ;; + -*) + echo "Unknown option: ${1:-}" + exit 1 + ;; + *) + break + ;; + esac +done + +# Functions + +function prepare_conf() { + SHINY_PORT=$1 + SHINY_BASE=$2 + SHINY_LOGS=$3 + DISABLE_DIRINDEX=$4 + SHINY_USER=$5 + CONFIG="run_as ${SHINY_USER}; +server { + listen ${SHINY_PORT}; + + # Define a location at the base URL + location / { + + # Host the directory of Shiny Apps stored in this directory + site_dir ${SHINY_BASE}; + + # Log all Shiny output to files in this directory + log_dir ${SHINY_LOGS}; + + # When a user visits the base URL rather than a particular application, + # an index of the applications available in this directory will be shown. + directory_index ${DISABLE_DIRINDEX}; + + # keep shiny app alive + app_idle_timeout 0; + } +}" + echo "${CONFIG}"; +} + + +# Are we starting the server? + +if [ "${SHINY_START}" == "yes" ]; then + + echo "Generating shiny configuration..."; + echo "port: ${SHINY_PORT}"; + echo "logs:" ${SHINY_LOGS}; + echo "base: ${SHINY_BASE}"; + echo "run_as: ${SHINY_USER}"; + + # Prepare the template + + CONFIG=$(prepare_conf $SHINY_PORT $SHINY_BASE $SHINY_LOGS $DISABLE_DIRINDEX $SHINY_USER); + + # # Temporary directories, if don't exist + # mkdir -p "${SHINY_LOGS}"; + # mkdir -p ${SHINY_LOGS}/logs; + # mkdir -p ${SHINY_LOGS}/lib; + + # Configuration file + echo "${CONFIG}" > "conf/shiny-server.conf"; + echo "Server logging will be in ${SHINY_LOGS}"; +# echo +# echo "To run your server: + +# $ module load singularity +# $ singularity run \\ +# --bind ./logs:/var/log/shiny \\ +# --bind ./lib:/var/lib/shiny-server \\ +# --bind ./conf/shiny-server.conf:/etc/shiny-server/shiny-server.conf \\ +# shiny_server.simg + +# --------------------------------------------------------------------------- +# For custom applications, also add --bind $SHINY_BASE:/srv/shiny-server +# To see your applications, open your browser to http://127.0.0.1:$SHINY_PORT or +# open a ssh connection from your computer to your cluster. +# " + exit +else + usage +fi + + +# $ module load singularity +# $ singularity run --bind $SHINY_LOGS/logs:/var/log/shiny \\ +# --bind $SHINY_LOGS/lib:/var/lib/shiny-server \\ +# --bind ./conf/shiny-server.conf:/etc/shiny-server/shiny-server.conf \\ +# shiny_server.simg diff --git a/scripts/install_apt_tools.sh b/scripts/install_apt_tools.sh index 1dcfeb7..51dd3e5 100644 --- a/scripts/install_apt_tools.sh +++ b/scripts/install_apt_tools.sh @@ -57,7 +57,7 @@ apt -y install gfortran apt -y install rsync wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.0g-2ubuntu4_amd64.deb -sudo dpkg -i libssl1.1_1.1.0g-2ubuntu4_amd64.deb +dpkg -i libssl1.1_1.1.0g-2ubuntu4_amd64.deb rm libssl1.1_1.1.0g-2ubuntu4_amd64.deb export JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java)))) diff --git a/scripts/pmet_binary_compile.sh b/scripts/pmet_binary_compile.sh new file mode 100644 index 0000000..5711960 --- /dev/null +++ b/scripts/pmet_binary_compile.sh @@ -0,0 +1,118 @@ +#!/bin/bash + +print_red(){ + RED='\033[0;31m' + NC='\033[0m' # No Color + printf "${RED}$1${NC}\n" +} + +print_green(){ + GREEN='\033[0;32m' + NC='\033[0m' # No Color + printf "${GREEN}$1${NC}\n" +} + +print_orange(){ + ORANGE='\033[0;33m' + NC='\033[0m' # No Color + printf "${ORANGE}$1${NC}\n" +} + +print_fluorescent_yellow(){ + FLUORESCENT_YELLOW='\033[1;33m' + NC='\033[0m' # No Color + printf "${FLUORESCENT_YELLOW}$1${NC}\n" +} + +print_white(){ + WHITE='\033[1;37m' + NC='\033[0m' # No Color + printf "${WHITE}$1${NC}" +} + +rm -rf PMETdev/scripts/pmetindex +rm -rf PMETdev/scripts/pmetParallel_linux +rm -rf PMETdev/scripts/pmet +rm -rf PMETdev/scripts/fimo + +############################# fimo with pmet index ############################## +print_fluorescent_yellow "Compiling FIMO with PMET homotopic (index) binary..." +cd PMETdev/src/meme-5.5.3 + +make distclean + +currentDir=$(pwd) +echo $currentDir/build + +if [ -d "$currentDir/build" ]; then + rm -rf "$currentDir/build" +fi + +mkdir -p $currentDir/build + +chmod a+x ./configure +./configure --prefix=$currentDir/build --enable-build-libxml2 --enable-build-libxslt +make +make install +cp build/bin/fimo ../../scripts/ +make distclean +rm -rf build +print_fluorescent_yellow "make distclean finished...\n" + + +################################### pmetindex #################################### +print_fluorescent_yellow "Compiling PMET homotopic (index) binary...\n" +cd ../indexing +chmod a+x build.sh +bash build.sh +mv bin/pmetindex ../../scripts/ + + +################################## pmetParallel ################################## +print_fluorescent_yellow "Compiling PMET heterotypic (pair) binary...\n" +cd ../pmetParallel +chmod a+x build.sh +bash build.sh +mv bin/pmetParallel_linux ../../scripts/ + +# pmet +print_fluorescent_yellow "Compiling PMET heterotypic (pair) binary...\n" +cd ../pmet +chmod a+x build.sh +bash build.sh +mv bin/pmet ../../scripts/ + + +cd ../../ +pwd +################### Check if the compilation was successful ######################## +exists="" +not_exists="" + +for file in scripts/pmetindex scripts/pmetParallel_linux scripts/pmet scripts/fimo; do + if [ -f "$file" ]; then + exists="$exists $file" + else + not_exists="$not_exists $file" + fi +done + +if [ ! -z "$exists" ]; then + print_green "Compilation Success:$exists" +fi + + +if [ ! -z "$not_exists" ]; then + print_red "Compilation Failure:$not_exists" +fi + + +############# Give execute permission to all users for the file. ################## +chmod a+x scripts/pmetindex +chmod a+x scripts/pmetParallel_linux +chmod a+x scripts/pmet +chmod a+x scripts/fimo + +# print_green "\n\npmet, pmetParallel_linux, pmetindex and NEW fimo are ready in 'scripts' folder.\n" + +print_green "DONE"