ncbi-genome-download批量下载基因组数据

2023-11-21 14:40

本文主要是介绍ncbi-genome-download批量下载基因组数据,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1. ncbi-genome-download 的下载和安装

ncbi-genome-download 是一个可以直接从NCBI上批量下载序列的软件,支持下载多种格式

利用 conda 对其直接安装 参考

#创建环境
conda create -n ncbi_genome_download
#激活环境
conda activate ncbi_genome_download
# 安装
conda install -c bioconda ncbi-genome-download

2.常用的参数

  • -s:选择数据库(genbank,refseq),默认是refseq数据库
  • -F:需要下载基因组的格式,可以多种格式同时下载,用逗号隔开,默认是genbank格式
  • -l:序列组装程度,可以多种格式同时下载,用逗号隔开
  • -g:需要下载序列的属,后面要指定类群,比如bacteria
  • S:下载的具体的菌种名称,用逗号隔开,也可以写入一个文件中,一行一个菌种名称
  • -o:输出的文件名称
  • -r:失败时重新连接的次数,默认是0次
  • --flat-output:将下载的文件输入到一个目录中,不创建新的子文件(即下载的数据在指定的文件夹中,每个 Taxonomy ID 一个压缩文件)

参数详情:

(ncbi_genome_download) [hgzhong@head01 ~]$ ncbi-genome-download -h                                                               
usage: ncbi-genome-download [-h] [-s {refseq,genbank}] [-F FILE_FORMATS]                                                         [-l ASSEMBLY_LEVELS] [-g GENERA] [--genus GENERA]                                                    [--fuzzy-genus] [-S STRAINS] [-T SPECIES_TAXIDS]                                                     [-t TAXIDS] [-A ASSEMBLY_ACCESSIONS]                                                                 [--fuzzy-accessions] [-R REFSEQ_CATEGORIES]                                                          [--refseq-category REFSEQ_CATEGORIES] [-o OUTPUT]                                                    [--flat-output] [-H] [-P] [-u URI] [-p N] [-r N]                                                     [-m METADATA_TABLE] [-n] [-N] [-v] [-d] [-V]                                                         [-M TYPE_MATERIALS]                                                                                  groups                                                                                               positional arguments:                                                                                                            groups                The NCBI taxonomic groups to download (default: all).                                                    A comma-separated list of taxonomic groups is alsopossible. For example: "bacteria,viral"Choose from:['all', 'archaea', 'bacteria', 'fungi','invertebrate', 'metagenomes', 'plant', 'protozoa','vertebrate_mammalian', 'vertebrate_other', 'viral']optional arguments:-h, --help            show this help message and exit-s {refseq,genbank}, --section {refseq,genbank}NCBI section to download (default: refseq)-F FILE_FORMATS, --formats FILE_FORMATSWhich formats to download (default: genbank).A comma-separated list of formats is also possible. Forexample: "fasta,assembly-report". Choose from:['genbank', 'fasta', 'rm', 'features', 'gff','protein-fasta', 'genpept', 'wgs', 'cds-fasta', 'rna-fna', 'rna-fasta', 'assembly-report', 'assembly-stats', 'translated-cds', 'all']-l ASSEMBLY_LEVELS, --assembly-levels ASSEMBLY_LEVELSAssembly levels of genomes to download (default: all).A comma-separated list of assembly levels is alsopossible. For example: "complete,chromosome". Choosefrom: ['all', 'complete', 'chromosome', 'scaffold','contig']-g GENERA, --genera GENERAOnly download sequences of the provided genera. Acomma-seperated list of genera is also possible. Forexample: "Streptomyces coelicolor,Escherichia coli".(default: [])--genus GENERA        Deprecated alias of --genera--fuzzy-genus         Use a fuzzy search on the organism name instead of anexact match.-S STRAINS, --strains STRAINSOnly download sequences of the given strain(s). Acomma-separated list of strain names is possible, aswell as a path to a filename containing one name perline.-T SPECIES_TAXIDS, --species-taxids SPECIES_TAXIDSOnly download sequences of the provided species NCBItaxonomy IDs. A comma-separated list of species taxidsis also possible. For example: "52342,12325".(default: [])-t TAXIDS, --taxids TAXIDSOnly download sequences of the provided NCBI taxonomyIDs. A comma-separated list of taxids is alsopossible. For example: "9606,9685". (default: [])-A ASSEMBLY_ACCESSIONS, --assembly-accessions ASSEMBLY_ACCESSIONSOnly download sequences matching the provided NCBIassembly accession(s). A comma-separated list ofaccessions is possible, as well as a path to afilename containing one accession per line.--fuzzy-accessions    Use a fuzzy search on the entry accession instead ofan exact match.-R REFSEQ_CATEGORIES, --refseq-categories REFSEQ_CATEGORIESOnly download sequences of the provided refseqcategories [refrerence, representative, na]. A comma-separated list of categories is also possible.(default: download all categories)--refseq-category REFSEQ_CATEGORIESDeprecated alias for --refseq-categories-o OUTPUT, --output-folder OUTPUTCreate output hierarchy in specified folder (default:/data/home/hgzhong)--flat-output         Dump all files right into the output folder withoutcreating any subfolders.-H, --human-readable  Create links in human-readable hierarchy (might failon Windows)-P, --progress-bar    Create a progress bar for indicating the downloadprogress-u URI, --uri URI     NCBI base URI to use (default:https://ftp.ncbi.nih.gov/genomes)-p N, --parallel N    Run N downloads in parallel (default: 1)-r N, --retries N     Retry download N times when connection to NCBI fails(default: 0)-m METADATA_TABLE, --metadata-table METADATA_TABLESave tab-delimited file with genome metadata-n, --dry-run         Only check which files to download, don't downloadgenome files.-N, --no-cache        Don't cache the assembly summary file in/data/home/hgzhong/.cache/ncbi-genome-download.-v, --verbose         increase output verbosity-d, --debug           print debugging information-V, --version         print version information-M TYPE_MATERIALS, --type-materials TYPE_MATERIALSSpecifies the relation to type material for theassembly (default: any). "any" will include assemblieswith no relation to type material value defined, "all"will download only assemblies with a defined value. Acomma-separated list of relatons. For example:"reference,synonym". Choose from: ['any', 'all','type', 'reference', 'synonym', 'proxytype','neotype'] .

3. 批量下载基因组数据

3.1 根据属名下载

将需要下载的属名放置至一个txt文档(换行),利用参数--genera  pant_download.txt  plant

3.2 根据物种的 ID下载

将需要下载的物种的分类 ID 放置至一个txt文档(换行),利用参数--taxids my_taxids.txt 

再加上参数 --assembly-levels 指定下载的基因组的不同类型(包括contig,scaffold,chromosome,all,compete)

不同物种的 taxonomy id查询地址 taxonomy id query

例如 Oryza sativa 的 taxonomy id为4530

3.3 根据物种拉丁名下载

当你有一系列菌种需要下载时,你可以将这一系列菌种名保存到一个txt文件里,每个菌种名为一行,文件名为genera.txt

希望下载这些菌种基因组中的cds序列,并将下载的每个文件放在MyGenera文件夹中,在MyGenera目录下进入终端,运行:

ncbi-genome-download --genera genera.txt bacteria --flat-output --formats cds-fasta

然后,每个物种均会自动下载好指定的基因组类型序列

这样genera文本中的所有菌种的基因组cds序列就一条代码下载完成了。

注意:genera.txt文本中有10个菌种名,而下载了13个文件,说明有的菌种名下面有来自不同上传者提供的基因组信息(即一对多)

如下图,我要下载GCAlist.txt文本中的基因组序列的fasta文件,并保存在Assembly文件夹中,在Assembly目录下进入终端,运行:

ncbi-genome-download --assembly-accessions GCAlist.txt bacteria --section genbank --for

4.帮助查询

查询地址 帮助文档

  • 查看版本
ncbi-genome-download -V
  • 查看帮助
ncbi-genome-download -h
  • 语法格式
ncbi-genome-download [optional arguments] groups

optional arguments为可选参数,详细介绍见下文

groups为物种选择,可选['all', 'archaea', 'bacteria', 'fungi', 'invertebrate', 'metagenomes', 'plant', 'protozoa', 'vertebrate_mammalian', 'vertebrate_other', 'viral'],可选项即为NCBI的FTP下载目录Index of/genomes/refseq和Index of/genomes/genbank下的内容

  • 可选参数
--section

指定下载的数据库,可选['refseq', 'genbank'],默认refseq

--formats

指定下载的文件格式,可选['genbank', 'fasta', 'rm', 'features', 'gff', 'protein-fasta', 'genpept', 'wgs', 'cds-fasta', 'rna-fna', 'rna-fasta', 'assembly-report', 'assembly-stats', 'all'],默认genbank

--assembly-levels

指定下载的基因组组装水平,可选['all', 'complete', 'chromosome', 'scaffold', 'contig'],默认all

--genera

根据菌种名下载,后面可接想要下载的菌种名,如--genera 'Rhizobium alamii'

--taxids

根据NCBI taxonomy ID下载,后面可接想要下载的菌种的taxonomy ID,如--taxids '492774'

(还以Rhizobium alamii举例,通过NCBI Taxonomy Browser可以查询到该菌种的txid为492774)

--assembly-accessions

根据assembly accession下载,后面可接想要下载的菌种的assembly accession,如--assembly-accessions ‘GCF_000799895.1’

⚠️注意:因为默认下载的数据库是refseq,所以选择RefSeq assembly accession下载时无需加--section参数即可正常下载,如果要根据GenBank assembly accession下载,请再加上--section genbank。

--output-folder

指定下载目录,后面可接你想要存放的下载目录,如--output-folder ~/Downloads(下载到当前用户的下载文件夹中)

--flat-output

直接将下载的文件放入指定文件夹中,不创建子文件夹

详情参考 ncbi-genome-download工具

5. 核查下载情况

由于利用ncbi-genome-download下载物种的基因组数据时存在未成功下载(后续需自己手动下载)的情况,所有需要将当前目录下的a.genomic.fna.gz文件进行汇总

5.1 利用grep命令查找

随后将sequence_name.txt文件导入excel表中,与自己需要下载的物种进行vlookup函数匹配,找出未成功下载的基因组序列的物种名

grep ".*genomic.fna.gz” ./present dictionary > sequence_name.txt

5.2 将.txt文件转换成.bat文件

另一种方法,比较简单实用:

这篇关于ncbi-genome-download批量下载基因组数据的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/402994

相关文章

Python在二进制文件中进行数据搜索的实战指南

《Python在二进制文件中进行数据搜索的实战指南》在二进制文件中搜索特定数据是编程中常见的任务,尤其在日志分析、程序调试和二进制数据处理中尤为重要,下面我们就来看看如何使用Python实现这一功能吧... 目录简介1. 二进制文件搜索概述2. python二进制模式文件读取(rb)2.1 二进制模式与文本

C#实现将XML数据自动化地写入Excel文件

《C#实现将XML数据自动化地写入Excel文件》在现代企业级应用中,数据处理与报表生成是核心环节,本文将深入探讨如何利用C#和一款优秀的库,将XML数据自动化地写入Excel文件,有需要的小伙伴可以... 目录理解XML数据结构与Excel的对应关系引入高效工具:使用Spire.XLS for .NETC

MySQL数据目录迁移的完整过程

《MySQL数据目录迁移的完整过程》文章详细介绍了将MySQL数据目录迁移到新硬盘的整个过程,包括新硬盘挂载、创建新的数据目录、迁移数据(推荐使用两遍rsync方案)、修改MySQL配置文件和重启验证... 目录1,新硬盘挂载(如果有的话)2,创建新的 mysql 数据目录3,迁移 MySQL 数据(推荐两

Python数据验证神器Pydantic库的使用和实践中的避坑指南

《Python数据验证神器Pydantic库的使用和实践中的避坑指南》Pydantic是一个用于数据验证和设置的库,可以显著简化API接口开发,文章通过一个实际案例,展示了Pydantic如何在生产环... 目录1️⃣ 崩溃时刻:当你的API接口又双叒崩了!2️⃣ 神兵天降:3行代码解决验证难题3️⃣ 深度

MySQL快速复制一张表的四种核心方法(包括表结构和数据)

《MySQL快速复制一张表的四种核心方法(包括表结构和数据)》本文详细介绍了四种复制MySQL表(结构+数据)的方法,并对每种方法进行了对比分析,适用于不同场景和数据量的复制需求,特别是针对超大表(1... 目录一、mysql 复制表(结构+数据)的 4 种核心方法(面试结构化回答)方法 1:CREATE

详解C++ 存储二进制数据容器的几种方法

《详解C++存储二进制数据容器的几种方法》本文主要介绍了详解C++存储二进制数据容器,包括std::vector、std::array、std::string、std::bitset和std::ve... 目录1.std::vector<uint8_t>(最常用)特点:适用场景:示例:2.std::arra

SpringBoot返回文件让前端下载的几种方式

《SpringBoot返回文件让前端下载的几种方式》文章介绍了开发中文件下载的两种常见解决方案,并详细描述了通过后端进行下载的原理和步骤,包括一次性读取到内存和分块写入响应输出流两种方法,此外,还提供... 目录01 背景02 一次性读取到内存,通过响应输出流输出到前端02 将文件流通过循环写入到响应输出流

pandas批量拆分与合并Excel文件的实现示例

《pandas批量拆分与合并Excel文件的实现示例》本文介绍了Pandas中基于整数位置的iloc和基于标签的loc方法进行数据索引和切片的操作,并将大Excel文件拆分合并,具有一定的参考价值,感... 目录一、Pandas 进行索引和切编程片的iloc、loc方法二、Pandas批量拆分与合并Exce

MySQL中的DELETE删除数据及注意事项

《MySQL中的DELETE删除数据及注意事项》MySQL的DELETE语句是数据库操作中不可或缺的一部分,通过合理使用索引、批量删除、避免全表删除、使用TRUNCATE、使用ORDERBY和LIMI... 目录1. 基本语法单表删除2. 高级用法使用子查询删除删除多表3. 性能优化策略使用索引批量删除避免

MySQL 数据库进阶之SQL 数据操作与子查询操作大全

《MySQL数据库进阶之SQL数据操作与子查询操作大全》本文详细介绍了SQL中的子查询、数据添加(INSERT)、数据修改(UPDATE)和数据删除(DELETE、TRUNCATE、DROP)操作... 目录一、子查询:嵌套在查询中的查询1.1 子查询的基本语法1.2 子查询的实战示例二、数据添加:INSE