1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
#!/usr/bin/python3
import os
import shutil
import subprocess
import tempfile
def isArm():
return subprocess.getoutput("uname -p") == "aarch64"
def runCommand(command):
if(os.system(command)):
raise Exception("Error running command: " + command)
def installPackage(package):
runCommand("sudo apt-get install --assume-yes " + package)
def installAptPackages():
packages = [
"git",
"g++",
"make",
"cmake",
"libboost-system-dev",
"libboost-program-options-dev",
"libboost-graph-dev",
"libboost-chrono-dev",
"libpng-dev",
"libblas-dev",
"liblapack-dev",
"gfortran",
"ncbi-blast+",
"graphviz",
"gnuplot",
"python3-dev",
]
runCommand("sudo apt-get install --assume-yes " + " ".join(packages))
# We don't use Ubuntu package libseqan2-dev because
# it does not include the fix for this issue:
# https://github.com/seqan/seqan/issues/2524
# Instead, we clone the GitHub seqan/seqan repository,
# then copy seqan/include/seqan to /usr/include/seqan.
def installSeqan():
# The path where the include files will go.
installPath = "/usr/include/seqan"
# First check that this path does not exist.
if os.path.exists(installPath):
raise Exception("The seqan install path %s already exists. "
"Remove it first (using apt remove if it was installed using apt)." % installPath)
with tempfile.TemporaryDirectory() as temporaryDirectory:
print("Building seqan library using temporary directory", temporaryDirectory)
# Change to the temporary directory.
oldDirectory = os.getcwd()
os.chdir(temporaryDirectory)
# Clone the Github repository.
runCommand("git clone https://github.com/seqan/seqan.git")
# Copy the include files.
shutil.copytree("seqan/include/seqan", installPath)
# Change back to the original directory.
os.chdir(oldDirectory)
def installPybind11():
try:
# This works for Ubuntu 22.04 and older
print("Attempting pybind11 installation using pip3")
installPackage("python3-pip")
runCommand("sudo pip3 install pybind11")
except:
# This works for Ubuntu 24.04 (and newer, presumably).
print("Pybind11 installation using pip3 did not work, installing using apt-get.")
installPackage("python3-pybind11")
def installSpoa():
# The spoa library is available in the stable Ubuntu repository, but
# without the static version.
# So we have to build it from source.
with tempfile.TemporaryDirectory() as temporaryDirectory:
print("Building spoa library using temporary directory", temporaryDirectory)
# Change to the temporary directory.
oldDirectory = os.getcwd()
os.chdir(temporaryDirectory)
# Get the code.
runCommand("sudo apt-get install curl")
runCommand("curl -L https://github.com/rvaser/spoa/archive/refs/tags/4.0.8.tar.gz -o 4.0.8.tar.gz")
runCommand("tar -xvf 4.0.8.tar.gz")
# Set spoa build flags.
if isArm():
spoaBuildFlags="-DCMAKE_BUILD_TYPE=Release -Dspoa_build_tests=OFF"
else:
# The spoa dispatcher feature selects code at run time based on available hardware features,
# which can improve performance.
# However, in spoa v4.0.8 it introduces two additional dependencies:
# - USCiLab/cereal
# - google/cpu_features
# To avoid these additional dependencies, we turn off the dispatcher feature for now.
# We could turn it back on if we see significant performance degradation in this area.
spoaBuildFlags = "-DCMAKE_BUILD_TYPE=Release -Dspoa_optimize_for_portability=ON -Dspoa_build_tests=OFF"
# Build the shared library.
print("\n******** Building spoa shared library")
os.mkdir("build")
os.chdir("build")
runCommand("cmake ../spoa-4.0.8 -DBUILD_SHARED_LIBS=ON " + spoaBuildFlags)
runCommand("make -j all")
runCommand("make install")
# Build the static library.
os.chdir("..")
print("\n******** Building spoa static library")
os.mkdir("build-static")
os.chdir("build-static")
runCommand("cmake ../spoa-4.0.8 -DBUILD_SHARED_LIBS=OFF " + spoaBuildFlags)
runCommand("make -j all")
runCommand("make install")
# Change back to the original directory.
os.chdir(oldDirectory)
installAptPackages()
installSeqan()
installPybind11()
installSpoa()
# Make sure the newly created libraries are immediately visible to the loader.
runCommand("ldconfig")
print("Installation of Shasta prerequisies completed successfully.")
|