Kraken2安装与数据库构建2022-01-02

Kraken2是一款快速宏基因组DNA序列进行物种注释的软件。我将其用于测序数据以及序列的物种的物种注释,检查测序数据以及序列是否有污染。
conda以及github网址:
https://anaconda.org/bioconda/kraken2
https://github.com/DerrickWood/kraken2
官方帮助文档:
https://github.com/DerrickWood/kraken2/blob/master/docs/MANUAL.markdown
两种安装方式,我选择conda安装,提示我会改变环境中的软件,有的会被移除或者降级,于是改为创建一个环境。

kraken2安装

#直接在系统中安装
conda install -c bioconda kraken2
#创建一个新环境在环境中安装
conda create -n kraken2 -c bioconda kraken2
source activate kraken2 

kraken2建库

kraken2 主要有两个命令一个是kraken2-buildkraken2
进行筛选则需要现建立库,那我们先看kraken2-build

Usage: kraken2-build [task option] [options]

Task options (exactly one must be selected):
  --download-taxonomy        Download NCBI taxonomic information
  --download-library TYPE    Download partial library
                             (TYPE = one of "archaea", "bacteria", "plasmid",
                             "viral", "human", "fungi", "plant", "protozoa",
                             "nr", "nt", "UniVec", "UniVec_Core")
  --special TYPE             Download and build a special database
                             (TYPE = one of "greengenes", "silva", "rdp")
  --add-to-library FILE      Add FILE to library
  --build                    Create DB from library
                             (requires taxonomy d/l'ed and at least one file
                             in library)
  --clean                    Remove unneeded files from a built database
  --standard                 Download and build default database
  --help                     Print this message
  --version                  Print version information

Options:
  --db NAME                  Kraken 2 DB name (mandatory except for
                             --help/--version)
  --threads #                Number of threads (def: 1)
  --kmer-len NUM             K-mer length in bp/aa (build task only;
                             def: 35 nt, 15 aa)
  --minimizer-len NUM        Minimizer length in bp/aa (build task only;
                             def: 31 nt, 12 aa)
  --minimizer-spaces NUM     Number of characters in minimizer that are
                             ignored in comparisons (build task only;
                             def: 7 nt, 0 aa)
  --protein                  Build a protein database for translated search
  --no-masking               Used with --standard/--download-library/
                             --add-to-library to avoid masking low-complexity
                             sequences prior to building; masking requires
                             dustmasker or segmasker to be installed in PATH,
                             which some users might not have.
  --max-db-size NUM          Maximum number of bytes for Kraken 2 hash table;
                             if the estimator determines more would normally be
                             needed, the reference library will be downsampled
                             to fit. (Used with --build/--standard/--special)
  --use-ftp                  Use FTP for downloading instead of RSYNC; used with
                             --download-library/--download-taxonomy/--standard.
  --skip-maps                Avoids downloading accession number to taxid maps,
                             used with --download-taxonomy.
  --load-factor FRAC         Proportion of the hash table to be populated
                             (build task only; def: 0.7, must be
                             between 0 and 1).
  --fast-build               Do not require database to be deterministically
                             built when using multiple threads.  This is faster,
                             but does introduce variability in minimizer/LCA
                             pairs.  Used with --build and --standard options.

首先构建一个标准数据库看看吧,执行如下命令。

mkdir -p standard_db
kraken2-build --standard --threads 12 --db standard_db

出现以下报错的时候不要慌,有人已经解决了。
https://github.com/DerrickWood/kraken2/issues/508

rsync_from_ncbi.pl: unexpected FTP path (new server?) for https://ftp.ncbi.nlm.nih.gov/genomes/all/GCF/000/762/265/GCF_000762265.1_ASM762
报错调整

使用conda安装的话,出错的rsync_from_ncbi.pl在$your_path/anaconda3/envs/kraken2/libexec/rsync_from_ncbi.pl
把rsync_from_ncbi.pl文件的

if (! ($full_path =~ s#^ftp://${qm_server}${qm_server_path}/##)) 

换成

if (! ($full_path =~ s#^https://${qm_server}${qm_server_path}/##))

————————————————
原文链接:https://blog.csdn.net/weixin_52602016/article/details/120689897
构建完毕的标准库内应该以下文件

hash.k2d
library
opts.k2d
seqid2taxid.map
taxo.k2d
taxonomy
unmapped.txt

hash.k2d: 包含最小值到分类单元的映射
opts.k2d: 包含有关用于构建数据库的选项的信息
taxo.k2d: 包含用于构建数据库的分类信息
使用这条命令kraken2-build --standard --threads 12 --db standard_db按照其帮助文档应该是下载并建立索引库,但有时候会缺少以上几个文件可能是没有建立索引,可以用如下命令建立索引。

kraken2-build --build --threads 24 --db standard_db

整个下载以及构建时间是比较长的,我们可以在任务完成以后使用kraken2-inspect -db standard_db | head -5命令来检查一下数据库是否完整,如果正常会在屏幕上打印测试检索报告。

kraken2的库

我们可以使用kraken2-build --download-library $library_name下载其提供的库,并建立后续的索引库。

archaea: RefSeq complete archaeal genomes/proteins #古菌

bacteria: RefSeq complete bacterial genomes/proteins #细菌
plasmid: RefSeq plasmid nucleotide/protein sequences #质粒
viral: RefSeq complete viral genomes/proteins #病毒
human: GRCh38 human genome/proteins #人
fungi: RefSeq complete fungal genomes/proteins #真菌
plant: RefSeq complete plant genomes/proteins #植物
protozoa: RefSeq complete protozoan genomes/proteins #原始动物
nr: NCBI non-redundant protein database #非冗余蛋白库
nt: NCBI non-redundant nucleotide database #非冗余蛋白库
UniVec: NCBI-supplied database of vector, adapter, linker, 
        and primer sequences that may be contaminating sequencing 
        projects and/or assemblies #常用污染序列,如载体、头、引物等
UniVec_Core: A subset of UniVec chosen to minimize false positive 
         hits to the vector database #常用污染序列核心库

标准模式下建的数据库只包括archaea、bacteria、human、plasmid、UniVec_Core、viral。
可以给一个db库下载多个数据

kraken2-build --download-library archaea --db $DBNAME
kraken2-build --download-library viral --db $DBNAME

添加序列数据,也可以根据需要添加自己的序列,但是需要根据Kraken2修改fasta序列的抬头信息>序列号|kraken:taxid|NCBI的分类好(详细查看官方帮助文档)

数据库序列准备完毕以后,就可建立索引了

 kraken2-build --build --db $DBNAME

建立好索引以后就可以使用了。

你可能感兴趣的:(Kraken2安装与数据库构建2022-01-02)