<commit_before>#!/usr/bin/env bash

# message to display when the OS is not correct
sanity_check_os() {
   echo
   echo " Unsupported operating system: $OS"
   echo " Installation aborted."
   echo 
   echo " Supported operating systems are: "
   echo " Ubuntu 12.x"
   echo " CentOS 6.x"
   echo " Scientific Linux 6.x"
   echo
   exit 1;
} # sanity_check_os


# 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 " Sorry, this version of Ubuntu has not been tested. Only Ubuntu 12.x is supported so far. "
      echo
      exit 1;

   fi

   OS="ubuntu"

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

   OP=$(cat /etc/system-release | awk ' {print $1;}')
   if [ "$OP" == "Scientific" ] ; then
      OP=$(cat /etc/system-release | awk ' {print $4;}' | awk '{sub("\\."," "); print $1;}')
      if [ "$OP" != "6" ] ; then
         echo
         echo " Sorry, this version of Scientific Linux has not been tested. Only 6.x versions are supported so far. "
         echo
         exit 1;
      else
         OS="sl"
      fi
   elif [ "$OP" == "CentOS" ] ; then
      OP=$(cat /etc/system-release | awk ' {print $3;}' | awk '{sub("\\."," "); print $1;}')
      if [ "$OP" != "6" ] ; then
         echo
         echo " Sorry, this version of CentOS has not been tested. Only 6.x versions are supported so far. "
         echo
         exit 1;
      else
         OS="centos"
      fi
   else
      sanity_check_os
   fi

else

   sanity_check_os

fi
} # detect_os


# install operating system dependencies
install_os_packages() {

detect_os

if [ "$OS" == "ubuntu" ] || [ "$OS" == "travis" ] ; then

   echo
   echo " Installing packages for Ubuntu "
   echo

   sudo apt-get --quiet install -y gcc g++ zlib1g-dev libssl-dev libssl1.0.0 libbz2-dev libfreetype6-dev libpng12-dev libblas-dev libatlas-dev liblapack-dev gfortran libpq-dev r-base-dev libreadline-dev libmysqlclient-dev libboost-dev libsqlite3-dev;

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

   echo 
   echo " Installing packages for Scientific Linux / CentOS "
   echo

   yum -y install gcc zlib-devel openssl-devel bzip2-devel gcc-c++ freetype-devel libpng-devel blas atlas lapack gcc-gfortran postgresql-devel R-core-devel readline-devel mysql-devel boost-devel sqlite-devel

   # additional configuration for scipy (Scientific Linux only)
   if [ "$OS" == "sl" ] ; then
      ln -s /usr/lib64/libatlas.so.3 /usr/lib64/libatlas.so
   fi

   # additional configuration for blas and lapack
   ln -s /usr/lib64/libblas.so.3 /usr/lib64/libblas.so
   ln -s /usr/lib64/liblapack.so.3 /usr/lib64/liblapack.so;

else

   sanity_check_os $OS

fi # if-OS
} # install_os_packages


# detect CGAT installation
detect_cgat_installation() {

RESULT=0

if [ -z "$CGAT_HOME" ] ; then

   if [ -d "$HOME/cgat-install/conda-install" ] ; then
      UNINSTALL_DIR="$HOME/cgat-install"
      RESULT=1
   fi


else

   if [ -d "$CGAT_HOME/conda-install" ] ; then
      UNINSTALL_DIR="$CGAT_HOME"
      RESULT=1
   fi

fi

return $RESULT

}


# proceed with conda installation
conda_install() {

detect_cgat_installation

if [ ! -z "$UNINSTALL_DIR" ] ; then

   echo
   echo " An installation of the CGAT code was found in: $UNINSTALL_DIR"
   echo " Please use --location to install CGAT code in a different location "
   echo " or uninstall the current version before proceeding."
   echo
   echo " Installation is aborted."
   echo
   exit 1

fi

# check installation type
if [ "$OS" != "travis" ] ; then
   if [ "$INSTALL_SCRIPTS" == "1" ] ; then
      if [ "$INSTALL_LITE" == "1" ] ; then
         CONDA_INSTALL_TYPE="cgat-scripts-lite"
      elif [ "$INSTALL_DEVEL" == "1" ] ; then
         CONDA_INSTALL_TYPE="cgat-scripts"
      else
         CONDA_INSTALL_TYPE="cgat-scripts"
      fi
   elif [ "$INSTALL_DEVEL" == "1" ] ; then
      if [ "$INSTALL_LITE" == "1" ] ; then
         CONDA_INSTALL_TYPE="cgat-devel-lite"
      elif [ "$INSTALL_DEVEL" == "1" ] ; then
         CONDA_INSTALL_TYPE="cgat-devel"
      else
         CONDA_INSTALL_TYPE="cgat-devel"
      fi
   else
      echo
      echo " Wrong installation type! "
      echo " Installation aborted. "
      echo
      exit 1
   fi # if install type
fi # if travis install

# check installation target
if [ "$OS" == "travis" ] ; then

   CONDA_INSTALL_TYPE="cgat-devel"
   export CONDA_INSTALL_DIR=$TRAVIS_BUILD_DIR/conda-install
   cd $TRAVIS_BUILD_DIR

else

   # Go to CGAT_HOME to continue with installation
   if [ -z "$CGAT_HOME" ] ; then
      # install in default location
      export CGAT_HOME=$HOME/cgat-install
      mkdir -p $CGAT_HOME
   fi

   export CONDA_INSTALL_DIR=$CGAT_HOME/conda-install
   cd $CGAT_HOME

fi # if-OS

# download and install conda
wget http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh
bash Miniconda-latest-Linux-x86_64.sh -b -p $CONDA_INSTALL_DIR
export PATH="$CONDA_INSTALL_DIR/bin:$PATH"
hash -r

# add cgat channel
conda config --add channels https://conda.binstar.org/asmeurer
conda config --add channels https://conda.binstar.org/cgat

# install cgat environment
conda update -q conda --yes
conda info -a
conda create -q -n $CONDA_INSTALL_TYPE $CONDA_INSTALL_TYPE bioconductor-deseq bioconductor-deseq2 r-wgcna r r-dtw r-rcolorbrewer r-flashclust bioconductor-masigpro bioconductor-timecourse --yes

# if installation is 'devel' (outside of travis), checkout latest version from github
if [ "$OS" != "travis" ] ; then

   if [ "$INSTALL_DEVEL" == "1" ] ; then

      # get latest version from Git Hub
      git clone https://github.com/CGATOxford/cgat.git $CGAT_HOME/cgat-code
      cd $CGAT_HOME/cgat-code

      # activate cgat environment
      source $CONDA_INSTALL_DIR/bin/activate $CONDA_INSTALL_TYPE

      # Set up other environment variables
      export CFLAGS=$CFLAGS" -I/usr/include/x86_64-linux-gnu -L/usr/lib/x86_64-linux-gnu"
      export C_INCLUDE_PATH=$C_INCLUDE_PATH:"/usr/include/x86_64-linux-gnu"
      export LIBRARY_PATH=$LIBRARY_PATH:"/usr/lib/x86_64-linux-gnu"
      export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CONDA_INSTALL_DIR/envs/$CONDA_INSTALL_TYPE/lib/R/lib

      # Python preparation
      python setup.py develop

      if [ ! $? -eq 0 ] ; then
         echo
         echo " There was a problem doing: 'python setup.py develop' "
         echo " Installation did not finish properly. "
         echo 
         echo " Please submit this issue via Git Hub: "
         echo " https://github.com/CGATOxford/cgat/issue "
         echo 
      fi # if-$?
   fi # if INSTALL_DEVEL

   clear
   echo 
   echo " The CGAT code was successfully installed!"
   echo
   echo " To activate the CGAT environment type: "
   echo " $ source $CONDA_INSTALL_DIR/bin/activate $CONDA_INSTALL_TYPE"
   [ "$INSTALL_SCRIPTS" == "1" ] && echo " cgat --help"
   echo
   echo " To deactivate the environment, use:"
   echo " $ source deactivate"
   echo

fi

} # conda install


# test code with conda install
conda_test() {

# setup environment and run tests
if [ "$OS" == "travis" ] ; then

   CONDA_INSTALL_DIR=$TRAVIS_BUILD_DIR/conda-install

   # activate cgat environment
   if [ "$INSTALL_LITE" == "1" ] ; then
      source $CONDA_INSTALL_DIR/bin/activate cgat-devel-lite
      export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CONDA_INSTALL_DIR/envs/cgat-devel-lite/lib/R/lib
   elif [ "$INSTALL_FULL" == "1" ] ; then
      source $CONDA_INSTALL_DIR/bin/activate cgat-devel
      export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CONDA_INSTALL_DIR/envs/cgat-devel/lib/R/lib
   else
      source $CONDA_INSTALL_DIR/bin/activate cgat-devel
      export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CONDA_INSTALL_DIR/envs/cgat-devel/lib/R/lib
   fi

   # configure environment
   export CFLAGS=$CFLAGS" -I/usr/include/x86_64-linux-gnu -L/usr/lib/x86_64-linux-gnu"
   export CPATH=$CPATH" -I/usr/include/x86_64-linux-gnu -L/usr/lib/x86_64-linux-gnu"
   export C_INCLUDE_PATH=$C_INCLUDE_PATH:"/usr/include/x86_64-linux-gnu"
   export CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:"/usr/include/x86_64-linux-gnu"
   export LIBRARY_PATH=$LIBRARY_PATH:"/usr/lib/x86_64-linux-gnu"

   # try installing R dependencies to fix errors on Travis

   cd $TRAVIS_BUILD_DIR
   python setup.py develop

   # run nosetests
   if [ "$TEST_IMPORT" == "1" ] ; then
      nosetests -v tests/test_import.py ;
   elif [ "$TEST_STYLE" == "1" ] ; then
      nosetests -v tests/test_style.py ;
   elif [ "$TEST_CMDLINE" == "1" ] ; then
      echo -e "restrict:\n    manifest:\n" > tests/_test_commandline.yaml<commit_msg> troubleshooting gcc memory errors on Travis<commit_after>#!/usr/bin/env bash

# message to display when the OS is not correct
sanity_check_os() {
   echo
   echo " Unsupported operating system: $OS"
   echo " Installation aborted."
   echo 
   echo " Supported operating systems are: "
   echo " Ubuntu 12.x"
   echo " CentOS 6.x"
   echo " Scientific Linux 6.x"
   echo
   exit 1;
} # sanity_check_os


# 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 " Sorry, this version of Ubuntu has not been tested. Only Ubuntu 12.x is supported so far. "
      echo
      exit 1;

   fi

   OS="ubuntu"

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

   OP=$(cat /etc/system-release | awk ' {print $1;}')
   if [ "$OP" == "Scientific" ] ; then
      OP=$(cat /etc/system-release | awk ' {print $4;}' | awk '{sub("\\."," "); print $1;}')
      if [ "$OP" != "6" ] ; then
         echo
         echo " Sorry, this version of Scientific Linux has not been tested. Only 6.x versions are supported so far. "
         echo
         exit 1;
      else
         OS="sl"
      fi
   elif [ "$OP" == "CentOS" ] ; then
      OP=$(cat /etc/system-release | awk ' {print $3;}' | awk '{sub("\\."," "); print $1;}')
      if [ "$OP" != "6" ] ; then
         echo
         echo " Sorry, this version of CentOS has not been tested. Only 6.x versions are supported so far. "
         echo
         exit 1;
      else
         OS="centos"
      fi
   else
      sanity_check_os
   fi

else

   sanity_check_os

fi
} # detect_os


# install operating system dependencies
install_os_packages() {

detect_os

if [ "$OS" == "ubuntu" ] || [ "$OS" == "travis" ] ; then

   echo
   echo " Installing packages for Ubuntu "
   echo

   sudo apt-get --quiet install -y gcc g++ zlib1g-dev libssl-dev libssl1.0.0 libbz2-dev libfreetype6-dev libpng12-dev libblas-dev libatlas-dev liblapack-dev gfortran libpq-dev r-base-dev libreadline-dev libmysqlclient-dev libboost-dev libsqlite3-dev;

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

   echo 
   echo " Installing packages for Scientific Linux / CentOS "
   echo

   yum -y install gcc zlib-devel openssl-devel bzip2-devel gcc-c++ freetype-devel libpng-devel blas atlas lapack gcc-gfortran postgresql-devel R-core-devel readline-devel mysql-devel boost-devel sqlite-devel

   # additional configuration for scipy (Scientific Linux only)
   if [ "$OS" == "sl" ] ; then
      ln -s /usr/lib64/libatlas.so.3 /usr/lib64/libatlas.so
   fi

   # additional configuration for blas and lapack
   ln -s /usr/lib64/libblas.so.3 /usr/lib64/libblas.so
   ln -s /usr/lib64/liblapack.so.3 /usr/lib64/liblapack.so;

else

   sanity_check_os $OS

fi # if-OS
} # install_os_packages


# detect CGAT installation
detect_cgat_installation() {

RESULT=0

if [ -z "$CGAT_HOME" ] ; then

   if [ -d "$HOME/cgat-install/conda-install" ] ; then
      UNINSTALL_DIR="$HOME/cgat-install"
      RESULT=1
   fi


else

   if [ -d "$CGAT_HOME/conda-install" ] ; then
      UNINSTALL_DIR="$CGAT_HOME"
      RESULT=1
   fi

fi

return $RESULT

}


# proceed with conda installation
conda_install() {

detect_cgat_installation

if [ ! -z "$UNINSTALL_DIR" ] ; then

   echo
   echo " An installation of the CGAT code was found in: $UNINSTALL_DIR"
   echo " Please use --location to install CGAT code in a different location "
   echo " or uninstall the current version before proceeding."
   echo
   echo " Installation is aborted."
   echo
   exit 1

fi

# check installation type
if [ "$OS" != "travis" ] ; then
   if [ "$INSTALL_SCRIPTS" == "1" ] ; then
      if [ "$INSTALL_LITE" == "1" ] ; then
         CONDA_INSTALL_TYPE="cgat-scripts-lite"
      elif [ "$INSTALL_DEVEL" == "1" ] ; then
         CONDA_INSTALL_TYPE="cgat-scripts"
      else
         CONDA_INSTALL_TYPE="cgat-scripts"
      fi
   elif [ "$INSTALL_DEVEL" == "1" ] ; then
      if [ "$INSTALL_LITE" == "1" ] ; then
         CONDA_INSTALL_TYPE="cgat-devel-lite"
      elif [ "$INSTALL_DEVEL" == "1" ] ; then
         CONDA_INSTALL_TYPE="cgat-devel"
      else
         CONDA_INSTALL_TYPE="cgat-devel"
      fi
   else
      echo
      echo " Wrong installation type! "
      echo " Installation aborted. "
      echo
      exit 1
   fi # if install type
fi # if travis install

# check installation target
if [ "$OS" == "travis" ] ; then

   CONDA_INSTALL_TYPE="cgat-devel"
   export CONDA_INSTALL_DIR=$TRAVIS_BUILD_DIR/conda-install
   cd $TRAVIS_BUILD_DIR

else

   # Go to CGAT_HOME to continue with installation
   if [ -z "$CGAT_HOME" ] ; then
      # install in default location
      export CGAT_HOME=$HOME/cgat-install
      mkdir -p $CGAT_HOME
   fi

   export CONDA_INSTALL_DIR=$CGAT_HOME/conda-install
   cd $CGAT_HOME

fi # if-OS

# download and install conda
wget http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh
bash Miniconda-latest-Linux-x86_64.sh -b -p $CONDA_INSTALL_DIR
export PATH="$CONDA_INSTALL_DIR/bin:$PATH"
hash -r

# add cgat channel
conda config --add channels https://conda.binstar.org/asmeurer
conda config --add channels https://conda.binstar.org/cgat

# install cgat environment
conda update -q conda --yes
conda info -a
conda create -q -n $CONDA_INSTALL_TYPE $CONDA_INSTALL_TYPE bioconductor-deseq bioconductor-deseq2 r-wgcna r r-dtw r-rcolorbrewer r-flashclust bioconductor-masigpro bioconductor-timecourse --yes

# if installation is 'devel' (outside of travis), checkout latest version from github
if [ "$OS" != "travis" ] ; then

   if [ "$INSTALL_DEVEL" == "1" ] ; then

      # get latest version from Git Hub
      git clone https://github.com/CGATOxford/cgat.git $CGAT_HOME/cgat-code
      cd $CGAT_HOME/cgat-code

      # activate cgat environment
      source $CONDA_INSTALL_DIR/bin/activate $CONDA_INSTALL_TYPE

      # Set up other environment variables
      export CFLAGS=$CFLAGS" -I/usr/include/x86_64-linux-gnu -L/usr/lib/x86_64-linux-gnu"
      export C_INCLUDE_PATH=$C_INCLUDE_PATH:"/usr/include/x86_64-linux-gnu"
      export LIBRARY_PATH=$LIBRARY_PATH:"/usr/lib/x86_64-linux-gnu"
      export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CONDA_INSTALL_DIR/envs/$CONDA_INSTALL_TYPE/lib/R/lib

      # Python preparation
      python setup.py develop

      if [ ! $? -eq 0 ] ; then
         echo
         echo " There was a problem doing: 'python setup.py develop' "
         echo " Installation did not finish properly. "
         echo 
         echo " Please submit this issue via Git Hub: "
         echo " https://github.com/CGATOxford/cgat/issue "
         echo 
      fi # if-$?
   fi # if INSTALL_DEVEL

   clear
   echo 
   echo " The CGAT code was successfully installed!"
   echo
   echo " To activate the CGAT environment type: "
   echo " $ source $CONDA_INSTALL_DIR/bin/activate $CONDA_INSTALL_TYPE"
   [ "$INSTALL_SCRIPTS" == "1" ] && echo " cgat --help"
   echo
   echo " To deactivate the environment, use:"
   echo " $ source deactivate"
   echo

fi

} # conda install


# test code with conda install
conda_test() {

# setup environment and run tests
if [ "$OS" == "travis" ] ; then

   CONDA_INSTALL_DIR=$TRAVIS_BUILD_DIR/conda-install

   # activate cgat environment
   if [ "$INSTALL_LITE" == "1" ] ; then
      source $CONDA_INSTALL_DIR/bin/activate cgat-devel-lite
      export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CONDA_INSTALL_DIR/envs/cgat-devel-lite/lib/R/lib
   elif [ "$INSTALL_FULL" == "1" ] ; then
      source $CONDA_INSTALL_DIR/bin/activate cgat-devel
      export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CONDA_INSTALL_DIR/envs/cgat-devel/lib/R/lib
   else
      source $CONDA_INSTALL_DIR/bin/activate cgat-devel
      export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CONDA_INSTALL_DIR/envs/cgat-devel/lib/R/lib
   fi

   # configure environment
   export CFLAGS="-O0"
   export CPATH=$CPATH" -I/usr/include/x86_64-linux-gnu -L/usr/lib/x86_64-linux-gnu"
   export C_INCLUDE_PATH=$C_INCLUDE_PATH:"/usr/include/x86_64-linux-gnu"
   export CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:"/usr/include/x86_64-linux-gnu"
   export LIBRARY_PATH=$LIBRARY_PATH:"/usr/lib/x86_64-linux-gnu"

   # try installing R dependencies to fix errors on Travis

   cd $TRAVIS_BUILD_DIR
   python setup.py develop

   # run nosetests
   if [ "$TEST_IMPORT" == "1" ] ; then
      nosetests -v tests/test_import.py ;
   elif [ "$TEST_STYLE" == "1" ] ; then
      nosetests -v tests/test_style.py ;
   elif [ "$TEST_CMDLINE" == "1" ] ; then
      echo -e "restrict:\n    manifest:\n" > tests/_test_commandline.yaml
{'fraction_non_alphanumeric': 0.12064482579303172, 'fraction_numerical': 0.013462760732651529, 'mean_word_length': 2.834293309703146, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3788215', 'n_tokens_mistral': 6500, 'n_tokens_neox': 5992, 'n_words': 1547}