Bootstrap: library
From: default/alpine:3.14.0

%post
  # Get the actual dependencies
  apk add --no-cache ncurses libbz2 xz zlib bash

  # Get the build dependencies
  apk add --no-cache --virtual .build-deps ncurses-dev musl-dev g++ make zlib-dev bzip2-dev xz-dev

  # Make versioning easier
  SAMTOOLS_VERSION='1.13'

  # Download the source tarball and build
  cd /tmp || exit 1
  wget https://github.com/samtools/samtools/releases/download/$SAMTOOLS_VERSION/samtools-$SAMTOOLS_VERSION.tar.bz2
  tar xjvf samtools-$SAMTOOLS_VERSION.tar.bz2
  cd samtools-$SAMTOOLS_VERSION || exit 1
  ./configure
  make && make install
  cd .. || exit 1
  rm -rf samtools-$SAMTOOLS_VERSION*
  cd || exit 1

  # Cleanup build packages
  apk del --no-cache .build-deps

%test
  test_command () {
    if ! command -v "${1}"; then
      echo "command ${1} not found!"
      export FAILED_TESTS=1
    fi
  }

  test_command bash
  test_command ps
  test_command samtools

  if [ -n "$FAILED_TESTS" ]; then
    exit 1
  fi

%runscript
  samtools "$@"

%labels
  Author 25492070+MillironX@users.noreply.github.com
  SoftwareVersion 1.13
  SingularityDefinitionVersion 1

%help
  Samtools
  ========

  Samtools is a set of utilities that manipulate alignments in the SAM
  (Sequence Alignment/Map), BAM, and CRAM formats. It converts between the
  formats, does sorting, merging and indexing, and can retrieve reads in any
  regions swiftly.

  For more help, see
  - <https://www.htslib.org/doc/samtools.html>
  - <https://github.com/MillironX/singularity-builds>
