Compile and debug NCBI blast+ source code - NCBI blast源码编译调试教程

Environment and tools

  1. CLion 2020.1.1(C++ IDE, compiledb doesn’t work in older version)
  2. Clang (macOS compile tool)
  3. CLion plugins Makefile support、Compilation Database
  4. python 2.7+ with pip
  5. python package compiledb(blast exectuables were built on GNU Make, when debugging the source code, header files(.h) need to be imported in CLion)

Where to dowload latest ncbi blast+ source code?

All blast+ exectuables are in ftp://ftp.ncbi.nlm.nih.gov/blast/executables/blast+/, and download the source code of 2.10.0 through ftp://ftp.ncbi.nlm.nih.gov/blast/executables/blast+/2.10.0/ncbi-blast-2.10.0+-src.zip

How does folders look like?

unzip the file, there are four folders(compilers, include, scripts and src) and two files(configure and configure.orig), like below:

clip_image001

How to build debug exectuables?

Step 1. generate makefiles

1
2
3
cd ncbi-blast-2.10.0+-src/c++
#Will generate makefiles in DebugMT/build
./configure --with-debug --with-projects=scripts/projects/blast/project.lst --with-build-root=DebugMT

After above commands executed successfully, DebugMT folder with lots of makefiles created. C++ files such as .o(object file) .d(dependency file) binary(executable) will be created in Step 3.

clip_image002

Step 2. using compiledb generate compile_commands.json

1
2
cd ncbi-blast-2.10.0+-src/c++
compiledb -nf --full-path --build-dir=DebugMT/build/ make

After above commands executed successfully, C++ link information will be written into compile_commands.json file.

clip_image003

Step 3. use make to compile whole source code at first time

1
2
cd DebugMT/build/
make all_p

Note: it will take about 45 minutes to build whole exectuables

After above commands executed successfully, the exectuables will be created under build/app/ and bin/

clip_image004

Step 4. use CLion open compile_commands.json as a project,

Note: before that, please install Compilation Database CLion plugin

clip_image005

CLion will index headers according to compile_commands.json created in Step 2, and you are able to see headers in Extranal Libraries, and can open the import file by clicking it as below:

clip_image006

Step 5. Debug in CLion

  • Configure Toolchains using LLDB

clip_image007

  • Create an External Tools called Empty, here not using any external tool.

clip_image008

  • Use Empty tool, and rename Custom Build Targets as LLDB.

clip_image009

  • Click Run → Choose Edit Configurations… → Click Add to create Custom Build Application → Select LLDB as Target → Select DebugMT/build/blastp as Exectuable → Remove Build in Before launch

    clip_image010

  • Click Add in Before launch → Click Add in External Tools → Create one called clean_blastp to clean .o, .d, binary files under DebugMT/build
    And keep Arguments as below: ‘-rf DebugMT/build/app/blast/blastp DebugMT/build/app/blast/blastp_app.d DebugMT/build/app/blast/blastp_app.o’

clip_image011

  • Click Add in Before launch → Click Add in External Tools → Create one called make_blast to build executables(if blastp is missing, make command will generate another new one exectuable called blastp)

clip_image012

  • Rename it as rebuild_blastp, keep clean_blastp and make_blast are selected in Before launch.(This one is to debug after source code changing)

clip_image013

  • Create another Custom Build Application called debug_blastp, and keep empty in Before launch. (This one is only to debug)

clip_image014

  • Fullfill correct arguments in Program arguments for debug_blastp, like

image-20200509115451309

  • Set breakpoint at src/app/blast/blastp_app.cpp, and debug debug_blastp

image-20200509115641583