Bootstrap: docker
From: condaforge/mambaforge:23.3.1-1

%labels
    Maintainer "Gurasis Osahan <gurasis.osahan@phac-aspc.gc.ca>"
    Description "HIV Resistance Interpretation & Scoring Engine"
    Version "1.0.0"
    Source "https://github.com/phac-nml/hyrise"

%environment
    export PYTHONDONTWRITEBYTECODE=1
    export PYTHONUNBUFFERED=1
    export MAMBA_ROOT_PREFIX=/opt/conda
    export PATH=$PATH:/opt/conda/bin

%post
    # System Dependencies
    apt-get update
    apt-get install -y --no-install-recommends \
        build-essential \
        git \
        ca-certificates \
        wget \
        minimap2 \
        procps \
        curl \
        unzip
    apt-get clean
    rm -rf /var/lib/apt/lists/*

    # Create working directory
    mkdir -p /opt
    cd /opt

    # Create environment.yml file inline
    cat > /opt/environment.yml << 'EOF'
name: base
channels:
  - conda-forge
  - bioconda
  - defaults
dependencies:
  - python=3.10
  - pip
  - cython=0.29.32
  - more-itertools=9.1.0
  - orjson=3.9.1
  - requests
  - pyyaml
  - jinja2
  - markdown
  - colorlog
  - click
  - numpy<2.0.0,>=1.24.3
  - multiqc=1.14
  - pip:
    - types-setuptools==67.8.0.0
EOF

    # Setup Conda environment
    mamba env update -n base -f /opt/environment.yml
    mamba clean --all -f -y

    # Install Post-Align (specific commit as recommended)
    pip install --no-cache-dir \
        git+https://github.com/hivdb/post-align@8e2ee118261987208c17add6cef5c1270e325a4c

    # Install Sierra-Local from GitHub
    git clone --depth 1 https://github.com/PoonLab/sierra-local.git
    cd sierra-local
    python setup.py install
    cd /opt
    rm -rf sierra-local/.git

    # Additional Python packages
    pip install --no-cache-dir \
        matplotlib==3.7.2 \
        seaborn==0.12.2 \
        pandas==2.0.3 \
        plotly==5.15.0 \
        kaleido==0.2.1 \
        tabulate==0.9.0 \
        beautifulsoup4>=4.13.4

    # Create wrapper script for HyRISE functionality
    cat > /usr/local/bin/hyrise << 'EOF'
#!/bin/bash
set -e

# Basic wrapper for HyRISE functionality
if [[ "$1" == "multiqc" ]]; then
    # Run MultiQC with all arguments after "multiqc"
    shift
    exec multiqc "$@"
elif [[ "$1" == "help" || "$1" == "--help" || "$1" == "-h" ]]; then
    echo "HyRISE - HIV Resistance Interpretation & Scoring Engine"
    echo ""
    echo "Available commands:"
    echo "  sierralocal [args]  - Run Sierra-Local with provided arguments"
    echo "  multiqc [args]      - Run MultiQC with provided arguments"
    echo "  help                - Display this help message"
    echo ""
    echo "For tool-specific help:"
    echo "  sierralocal --help"
    echo "  multiqc --help"
else
    # Default to Sierra-Local
    exec sierralocal "$@"
fi
EOF
    chmod +x /usr/local/bin/hyrise

    # Create data directory that will be the default working directory
    mkdir -p /data

%runscript
    exec /usr/local/bin/hyrise "$@"

%startscript
    exec /usr/local/bin/hyrise "$@"

%help
    HyRISE - HIV Resistance Interpretation & Scoring Engine
    
    A comprehensive container for HIV drug resistance prediction and reporting 
    with integrated visualization capabilities through MultiQC.
    
    Features:
      - Sierra-Local for HIV-1 drug resistance prediction
      - MultiQC for comprehensive visualization reporting
      - Support for visualization tools and dependencies
    
    Usage:
      1. Analysis only:
         singularity run hyrise.sif RT.fa
      
      2. Run MultiQC:
         singularity run hyrise.sif multiqc .
      
      3. Display help:
         singularity run hyrise.sif help

%test
    # Test that main tools are installed correctly
    sierralocal --version
    multiqc --version