Skip to content

Instantly share code, notes, and snippets.

@moonwatcher
Last active March 22, 2019 12:20
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save moonwatcher/2a97f1e1c795f99c390e608028587cc3 to your computer and use it in GitHub Desktop.
Save moonwatcher/2a97f1e1c795f99c390e608028587cc3 to your computer and use it in GitHub Desktop.
script for building bcl2fastq2 2.20.0 on POSIX systems
#!/usr/bin/env zsh
# script to build Illumina bcl2fastq2
# Copyright (C) 2017 Lior Galanti
# NYU Center for Genetics and System Biology
# Author: Lior Galanti <lior.galanti@nyu.edu>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# This script will build bcl2fastq2 version 2.20.0
# for some reason the source code provided by illumina seems to assume and older version
# of boost on POSIX systems that where the boost::property_tree::xml_writer_make_settings
# function is not templatized and so fails to build against newer versions of boost on those platforms.
# a patch is available for correcting this silly assumption here:
# https://gist.github.com/moonwatcher/ac1176971d6032fc9e0d4402e5a81333
BCL2FASTQ_WORK_DIRECTORY="$(cd ~ && pwd)/bcl2fastq_2_20_1_work_directory"
BCL2FASTQ_ARCHIVE_URL="ftp://webdata2:webdata2@ussd-ftp.illumina.com/downloads/software/bcl2fastq/bcl2fastq2-v2-20-0-tar.zip"
BCL2FASTQ_ARCHIVE_URL_MD5="4dc99f1af208498b7279b66556329488"
BCL2FASTQ_ARCHIVE_LOCAL="$BCL2FASTQ_WORK_DIRECTORY/bcl2fastq2-v2-20-0-tar.zip"
BCL2FASTQ_BOOST_PATCH_URL="https://gist.githubusercontent.com/moonwatcher/ac1176971d6032fc9e0d4402e5a81333/raw"
BCL2FASTQ_BOOST_PATCH_MD5="5c887a6316d188f6e34dabe35f6be466"
BCL2FASTQ_BOOST_PATCH_LOCAL="$BCL2FASTQ_WORK_DIRECTORY/bcl2fastq2_2_20_0_xml_writer_make_settings.patch"
BCL2FASTQ_SOURCE="$BCL2FASTQ_WORK_DIRECTORY/bcl2fastq"
BCL2FASTQ_BUILD="$BCL2FASTQ_WORK_DIRECTORY/build"
# create work directory
if [[ ! -d "$BCL2FASTQ_WORK_DIRECTORY" ]]; then
>&2 echo "creating work directory $BCL2FASTQ_WORK_DIRECTORY";
mkdir -p "$BCL2FASTQ_WORK_DIRECTORY";
fi
check_archive() {
local ARCHIVE_REMOTE_URL="$1";
local ARCHIVE_LOCAL_URL="$2";
local ARCHIVE_REMOTE_MD5="$3";
if [[ -f "$ARCHIVE_LOCAL_URL" ]]; then
local ARCHIVE_LOCAL_MD5=$(md5sum "$ARCHIVE_LOCAL_URL" | cut -d ' ' -f 1);
if [[ $ARCHIVE_LOCAL_MD5 == $ARCHIVE_REMOTE_MD5 ]]; then
>&2 echo "archive md5 match $ARCHIVE_LOCAL_URL"
return 0;
else
>&2 echo "archive md5 incorrect $ARCHIVE_LOCAL_URL"
return 1;
fi
else
>&2 echo "missing archive $ARCHIVE_LOCAL_URL"
return 1;
fi
}
download_archive() {
local ARCHIVE_REMOTE_URL="$1";
local ARCHIVE_LOCAL_URL="$2";
local ARCHIVE_REMOTE_MD5="$3";
>&2 echo "downloading $ARCHIVE_REMOTE_URL";
curl -L "$ARCHIVE_REMOTE_URL" > "$ARCHIVE_LOCAL_URL";
local RESULT=$(check_archive "$ARCHIVE_REMOTE_URL" "$ARCHIVE_LOCAL_URL" "$ARCHIVE_REMOTE_MD5");
if [[ $RESULT -eq 0 ]]; then
>&2 echo "successfully downloaded $ARCHIVE_LOCAL_URL";
else
>&2 echo "downloaded archive is corrupt $ARCHIVE_LOCAL_URL";
fi
return $RESULT;
}
# download and verify bcl2fastq source code archive
if [[ -f "$BCL2FASTQ_ARCHIVE_LOCAL" ]]; then
local RESULT=$(check_archive $BCL2FASTQ_ARCHIVE_URL $BCL2FASTQ_ARCHIVE_LOCAL $BCL2FASTQ_ARCHIVE_URL_MD5);
if [[ $RESULT -ne 0 ]]; then
exit 1
fi
else
local RESULT=$(download_archive $BCL2FASTQ_ARCHIVE_URL $BCL2FASTQ_ARCHIVE_LOCAL $BCL2FASTQ_ARCHIVE_URL_MD5);
if [[ $RESULT -ne 0 ]]; then
exit 1
fi
fi
# download and verify boost patch
if [[ -f "$BCL2FASTQ_BOOST_PATCH_LOCAL" ]]; then
local RESULT=$(check_archive $BCL2FASTQ_BOOST_PATCH_URL $BCL2FASTQ_BOOST_PATCH_LOCAL $BCL2FASTQ_BOOST_PATCH_MD5);
if [[ $RESULT -ne 0 ]]; then
exit 1
fi
else
local RESULT=$(download_archive $BCL2FASTQ_BOOST_PATCH_URL $BCL2FASTQ_BOOST_PATCH_LOCAL $BCL2FASTQ_BOOST_PATCH_MD5);
if [[ $RESULT -ne 0 ]]; then
exit 1
fi
fi
# extract source code and apply patch
if [[ ! -d "$BCL2FASTQ_SOURCE" ]]; then
>&2 echo "extracting source code from archive $BCL2FASTQ_ARCHIVE_LOCAL";
( cd "$BCL2FASTQ_WORK_DIRECTORY";
unzip -p "$BCL2FASTQ_ARCHIVE_LOCAL" | tar -xvzf -
( cd "$BCL2FASTQ_SOURCE"
( cd src/cxx/lib/io;
>&2 echo "applying boost patch";
patch < "$BCL2FASTQ_BOOST_PATCH_LOCAL";
)
)
)
fi
# create build directory
if [[ ! -d "$BCL2FASTQ_BUILD" ]]; then
>&2 echo "creating build directory $BCL2FASTQ_BUILD";
mkdir -p "$BCL2FASTQ_BUILD";
fi
( cd "$BCL2FASTQ_BUILD";
>&2 echo "configuring bcl2fastq";
$BCL2FASTQ_SOURCE/src/configure
>&2 echo "making bcl2fastq";
make;
>&2 echo "installing bcl2fastq";
make install;
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment