Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a setup.sh script for easier instalation #35

Merged
merged 14 commits into from
Aug 28, 2024
27 changes: 16 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,18 @@ If you find Chainsaw useful in your research, please cite:

Jude Wells, Alex Hawkins-Hooker, Nicola Bordin, Brooks Paige and Christine Orengo

[bioRxiv](https://doi.org/10.1101/2023.07.19.549732)
[Bioinformatics](https://doi.org/10.1093/bioinformatics/btae296)

## Installation

1) install stride: source code and instructions are packaged in this repository in the
`stride` directory. You will need to compile stride and put the executable in your
path. Update the `STRIDE_EXE` variable in `src/constants.py` to point to the stride
executable.

2) install the python dependencies: `pip install -r requirements.txt`

3) test it's working by running `python get_predictions.py --structure_file example_files/AF-A0A1W2PQ64-F1-model_v4.pdb --output results/test.tsv`
by default the output will be saved in the `results` directory.
Ensure that python 3.8, 3.9, 3.10, or 3.11 is installed, then install dependencies with
the command `bash setup.sh`

Optional:
To visualise the domain assignments, ensure that you have pymol installed and update the
`PYMOL_EXE` variable in `src/constants.py` to point to the pymol executable.

Chainsaw is tested on Linux and MacOS. It may work on Windows but this is not guaranteed.

## Usage
`python get_predictions.py --structure_file /path/to/file.pdb`
or
Expand All @@ -35,3 +29,14 @@ or
Note that the output predicted boundaries are based on residue consecutive indexing
starting from 1 (not based on pdb auth numbers).

## Installation Troubleshooting
If setup.sh fails follow the instructions below:

1) install stride: source code and instructions are packaged in this repository in the
`stride` directory. See stride/README_stride for instructions.

2) install the python dependencies: `pip install -r requirements.txt`

3) test it's working by running `python get_predictions.py --structure_file example_files/AF-A0A1W2PQ64-F1-model_v4.pdb --output results/test.tsv`
by default the output will be saved in the `results` directory.

135 changes: 135 additions & 0 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#!/bin/bash

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
STRIDE_DIR="${SCRIPT_DIR}/stride"

# Function to check if a command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}

# Function to install build tools
install_build_tools() {
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
# Linux
if command_exists apt-get; then
sudo apt-get update
sudo apt-get install -y build-essential
elif command_exists yum; then
sudo yum groupinstall -y "Development Tools"
else
echo "Error: Unsupported package manager. Please install build tools manually."
return 1
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
# macOS
if ! command_exists gcc || ! command_exists make; then
echo "Installing Xcode Command Line Tools..."
xcode-select --install
read -p "Press enter after Xcode Command Line Tools installation is complete"
fi
elif [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" ]]; then
# Windows (Git Bash or Cygwin)
if ! command_exists gcc || ! command_exists make; then
echo "Please install MinGW-w64 or Cygwin with gcc and make."
echo "Visit: https://sourceforge.net/projects/mingw-w64/ or https://www.cygwin.com/"
return 1
fi
else
echo "Unsupported operating system"
return 1
fi
return 0
}

# Function to compile stride
compile_stride() {
echo "Starting stride compilation process..."

# Decompress stride
if [ -f "$STRIDE_DIR/stride.tgz" ]; then
echo "Decompressing stride..."
tar -zxf "$STRIDE_DIR/stride.tgz" -C "$STRIDE_DIR" || return 1
else
echo "Error: stride.tgz not found in $STRIDE_DIR"
return 1
fi

# Install build tools if necessary
echo "Checking and installing build tools if necessary..."
install_build_tools || return 1

# Compile stride
echo "Compiling stride..."
cd "$STRIDE_DIR" || return 1
make || return 1

# Change permissions
echo "Changing stride permissions to executable..."
chmod +x stride || return 1

# Test run
echo "Performing a test run of stride..."
./stride --help || return 1

# Change back to the original directory
cd - || return 1

echo "Stride compilation successful!"
return 0
}

# Main script execution starts here

# Check if venv directory chswEnv exists
if [ ! -d "$SCRIPT_DIR/chswEnv" ]; then
echo "Creating virtual environment..."
if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" ]]; then
python -m venv "$SCRIPT_DIR/chswEnv"
# Try Python 3.11, then 3.10, then 3.9
elif command_exists python3.11; then
python3.11 -m venv "$SCRIPT_DIR/chswEnv"
echo "Created virtual environment with Python 3.11"
elif command_exists python3.10; then
python3.10 -m venv "$SCRIPT_DIR/chswEnv"
echo "Created virtual environment with Python 3.10"
elif command_exists python3.9; then
python3.9 -m venv "$SCRIPT_DIR/chswEnv"
echo "Created virtual environment with Python 3.9"
elif command_exists python3.8; then
python3.9 -m venv "$SCRIPT_DIR/chswEnv"
echo "Created virtual environment with Python 3.8"
else
echo "Error: Python 3.8, 3.9, 3.10, or 3.11 is not installed. Please install one of these versions and try again."
exit 1
fi
else
echo "Virtual environment already exists."
fi

# Activate the virtual environment
if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" ]]; then
source "$SCRIPT_DIR/chswEnv/Scripts/activate"
else
source "$SCRIPT_DIR/chswEnv/bin/activate"
fi

echo "Upgrading pip..."
pip install --upgrade pip
echo "Installing dependencies from requirements.txt..."
pip install -r "$SCRIPT_DIR/requirements.txt"

# Compile stride
if compile_stride; then
echo "Stride compilation and setup completed successfully."
echo "Chainsaw setup complete. Test the installation by running the following command:"
echo "python get_predictions.py --structure_file example_files/AF-A0A1W2PQ64-F1-model_v4.pdb --output results/test.tsv"
else
echo "Error occurred during stride compilation."
echo "Please compile stride manually by following these steps:"
echo "1. Navigate to the stride directory: cd $STRIDE_DIR"
echo "2. Decompress the source: tar -zxf stride.tgz"
echo "3. Compile the source: make"
echo "4. Make the binary executable: chmod +x stride"
echo "5. Test the binary: ./stride --help"
fi
Loading