跳转至

下载:参数与补充说明

用法和示例见功能教程。

各功能按作用、API、输入、输出、示例代码和结果说明介绍。运行前按说明准备凭据、本地文件与可选依赖;远程结果随数据库版本与查询时间变化。

ENCODE 接口返回文本:多数是 JSON,get_citations 可返回 BibTeX/RIS,export_data 可返回 CSV/TSV。仅 JSON 文本使用 json.loads()。追踪与凭据保存在 ~/.dnakit-encode/;持久化凭据功能需要 dnakit[encode-credentials]。

各功能按作用、API、输入、输出、示例代码和结果说明介绍。运行前按说明准备凭据、本地文件与可选依赖;远程结果随数据库版本与查询时间变化。

通过 HTTP 或 HTTPS 下载文件

dnakit.databases.download_file(*, url, output_path=None, timeout=None, return_content=None, chunk_size=None, follow_redirects=None, verbose=True)

参数 类型 必填 / 默认值 说明与约束
url string 必填 HTTP or HTTPS URL to download from (e.g., https://example.com/file.txt)
output_path string None Optional path to save the file. If not specified, file will be saved to system temp directory.
timeout integer None Request timeout in seconds
return_content boolean None If true, return file content as text instead of saving to disk (default: false)
chunk_size integer None Download chunk size in bytes (default: 8192)
follow_redirects boolean None Follow HTTP redirects (default: true)
verbose bool True 运行提示开关。

下载 ENA 核酸序列并保存校验清单

dnakit.download.ena.sequence(accession, output_path, *, format='fasta', config=None, search_config=None, api_base_url='https://www.ebi.ac.uk/ena/browser/api', verbose=True)

参数 类型 必填 / 默认值 说明与约束
accession str 必填 版本化序列 accession;ENA 使用 INSDC 编号,NCBI 也支持 RefSeq。
output_path str | Path 必填 目标序列文件路径。
format Literal['fasta', 'embl', 'genbank'] 'fasta' fasta、genbank 或 embl;提供方及转换依赖见序列下载教程。
config DownloadConfig | None None 查询使用 SearchConfig;下载使用 DownloadConfig。
search_config SearchConfig | None None 控制查询超时、返回大小和 NCBI 凭据的 SearchConfig。
api_base_url str 'https://www.ebi.ac.uk/ena/browser/api' 服务 API 根地址;默认值见签名。
verbose bool True 是否显示 DNAKit 运行提示;不会改变返回值。

下载 NCBI 核酸或蛋白质序列

dnakit.download.ncbi.sequence(accession, output_path, *, database='nuccore', format='fasta', seq_start=None, seq_stop=None, strand=1, config=None, search_config=None, api_base_url='https://eutils.ncbi.nlm.nih.gov/entrez/eutils', verbose=True)

参数 类型 必填 / 默认值 说明与约束
accession str 必填 版本化序列 accession;ENA 使用 INSDC 编号,NCBI 也支持 RefSeq。
output_path str | Path 必填 目标序列文件路径。
database Literal['nuccore', 'protein'] 'nuccore' NCBI 序列数据库 nuccore 或 protein。
format Literal['fasta', 'genbank', 'embl'] 'fasta' fasta、genbank 或 embl;提供方及转换依赖见序列下载教程。
seq_start int | None None NCBI 核酸子区间起点,1-based 闭区间;须同时指定 seq_stop。
seq_stop int | None None NCBI 核酸子区间终点,1-based 闭区间;须同时指定 seq_start。
strand Literal[1, 2] 1 NCBI 核酸序列链方向,1 正向、2 反向互补。
config DownloadConfig | None None 查询使用 SearchConfig;下载使用 DownloadConfig。
search_config SearchConfig | None None 控制查询超时、返回大小和 NCBI 凭据的 SearchConfig。
api_base_url str 'https://eutils.ncbi.nlm.nih.gov/entrez/eutils' 服务 API 根地址;默认值见签名。
verbose bool True 是否显示 DNAKit 运行提示;不会改变返回值。

批量检索并下载 ENCODE 文件

dnakit.encode.batch_download(download_dir, file_format=None, output_type=None, output_category=None, assembly=None, assay_title=None, organism='Homo sapiens', organ=None, biosample_type=None, target=None, preferred_default=None, organize_by='experiment', verify_md5=True, limit=100, dry_run=True, *, verbose=True)

参数 类型 必填 / 默认值 说明与约束
download_dir str 必填 Local directory to save files
file_format str | None None File format filter ("fastq", "bam", "bed", "bigWig", etc.)
output_type str | None None Output type filter ("reads", "peaks", "signal", etc.)
output_category str | None None Output category ("raw data", "alignment", "annotation", etc.)
assembly str | None None Genome assembly ("GRCh38", "mm10", etc.)
assay_title str | None None Assay type ("Histone ChIP-seq", "ATAC-seq", "total RNA-seq", etc.)
organism str 'Homo sapiens' Organism (default: "Homo sapiens")
organ str | None None Organ/tissue ("pancreas", "brain", "liver", etc.)
biosample_type str | None None Biosample type ("tissue", "cell line", "primary cell", etc.)
target str | None None ChIP/CUT&RUN target ("H3K27me3", "CTCF", etc.)
preferred_default bool | None None If True, only download default/recommended files
organize_by Literal['flat', 'experiment', 'format', 'experiment_format'] 'experiment' File organization ("flat", "experiment", "format", "experiment_format")
verify_md5 bool True Verify downloads with MD5 checksums (default True)
limit int 100 Max files to download (default 100, safety limit)
dry_run bool True If True (default), only preview what would be downloaded. Set False to download.
verbose bool True 是否显示 DNAKit 运行提示;不会改变返回值。

按文件编号下载 ENCODE 数据

dnakit.encode.download_files(file_accessions, download_dir, organize_by='flat', verify_md5=True, *, verbose=True)

参数 类型 必填 / 默认值 说明与约束
file_accessions list[str] 必填 List of file accessions to download (e.g., ["ENCFF635JIA", "ENCFF388RZD"])
download_dir str 必填 Local directory path to save files (e.g., "./data/encode")
organize_by Literal['flat', 'experiment', 'format', 'experiment_format'] 'flat' How to organize downloaded files: - "flat": All files in download_dir (default) - "experiment": download_dir/ENCSR.../filename - "format": download_dir/bed/filename - "experiment_format": download_dir/ENCSR.../bed/filename
verify_md5 bool True Verify file integrity with MD5 checksum (default True)
verbose bool True 是否显示 DNAKit 运行提示;不会改变返回值。