DIAMOND 基因序列快速比对工具使用详解
DIAMOND 是一款快速的序列比对工具,其使用方法如下:
1. 安装 DIAMOND
可从官方网站下载安装包,并安装到本地电脑中。当然还有 Docker、Conda 以及编译安装方式,一般用不上,但注意新版对 GCC 的要求高,出现 GCC 错误时可选择下载低版本的 DIAMOND 或者升级 GCC 到指定版本以上。
# 下载 diamond 程序文件
wget http://github.com/bbuchfink/diamond/releases/download/v2.1.8/diamond-linux64.tar.gz
# 解压会出来一个 diamond 的文件
tar -xzvf diamond-linux64.tar.gz
# 移到系统环境目录、或将当前目录加入系统环境目录,或者直接使用路径加 diamond 命令运行
diamond blastx ./diamond blastx /opt/diamond blastx
2. 准备数据集
首先需要准备用于比对的序列数据集,比如 FASTA 格式的序列文件。
# 下载 nr 数据库,或者自己需要的数据库
wget ftp://ftp.ncbi.nlm.nih.gov/blast/db/FASTA/nr.gz
gunzip nr.gz
# 使用 diamond 命令创建 diamond 格式数据库
diamond makedb --in nr --db nr
3. 运行 DIAMOND
常规使用
在终端中输入以下命令,即可启动 DIAMOND 程序并运行比对任务:
diamond blastx -d [参考序列文件] -q [待比对序列文件] -o [输出文件名]
# 下载 nr 数据库,或者自己需要的数据库
wget ftp://ftp.ncbi.nlm.nih.gov/blast/db/FASTA/nr.gz
gunzip nr.gz
# 使用 diamond 命令创建 diamond 格式数据库
diamond makedb --in nr --db nr
# 命令使用
diamond blastx --db nr -q reads.fna -o dna_matches_fmt6.txt
diamond blastp --db nr -q reads.faa -o protein_matches_fmt6.txt
其中,blastx 表示使用蛋白质序列比对算法,-d 和-q 分别指定参考序列文件和待比对序列文件,-o 指定输出文件名。
超算集群多计算节点并行计算(Distributed computing)
DIAMOND 尽管速度快,但对于大文件进行比对时,大于 1G 以上的文件对于 40 核的单个节点可能仍然需要几天的时间,如果有较多的节点时,可以使用多节点的并行计算。
准备工作:
- 将 DIAMOND 程序目录在各节点间共享
- 样品序列目录在各节点间共享
- 所有节点使用相同的临时目录在各节点间共享
# Diamond distributed-memory parallel processing
# Diamond supports the parallel processing of large alignments on HPC clusters and supercomputers, spanning numerous compute nodes.
# Work distribution is orchestrated by Diamond via a shared file system typically available on such clusters, using lightweight file-based stacks and POSIX functionality.
diamond blastp --db DATABASE.dmnd --query QUERY.fasta --multiprocessing --mp-init --tmpdir --parallel-tmpdir
diamond blastp --db DATABASE.dmnd --query QUERY.fasta -o OUTPUT_FILE --multiprocessing --tmpdir --parallel-tmpdir
module purge
module load gcc impi
SLURM_HINT=multithread
srun diamond FLAGS
FLAGS refers to the aforementioned parallel flags Diamond. Note that the actual configuration of the nodes varies between machines, and therefore, the parameters shown here are not of general applicability. It is recommended to start with few nodes on small problems, first.
Parallel Runs can be aborted and later resumed, and unfinished work packages from a previous run can be recovered and resubmitted a subsequent run. Using the option --multiprocessing --mp-recover the same value of --parallel-tmpdir will scan the working directory and configure a new parallel run including only the work packages that have not been completed the previous run. Placing a file stop the working directory causes DIAMOND processes to shut down a controlled way after finishing the current work package. After removing the stop file, the multiprocessing run can be continued.
The granularity of the size of the work packages can be adjusted via the --block-size at the same affects the memory requirements at runtime. Parallel runs on more than 512 nodes of a supercomputer have been performed successfully.

