Skip to content
/ PubEx Public

PubMed Literature Information Extraction Tool.

License

Notifications You must be signed in to change notification settings

WhyLIM/PubEx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

PubEx:PubMed 文献基本信息提取工具

一个功能强大的 PubMed 文献数据批量提取工具,支持高效的文献信息爬取、引用关系分析和断点续传功能。

✨ 主要特性

  • 🚀 高性能批量提取:使用 NCBI E-utilities 官方库,支持 API-key 加速。
  • 🔗 引用关系分析:自动获取文章的引用和被引用信息。
  • 📊 进度可视化:实时显示爬取进度和统计信息,支持双层进度条。
  • 📝 详细日志记录:完整的操作日志和错误追踪。
  • ⚙️ 灵活配置:JSON 配置文件支持多任务批处理。
  • 🔄 断点续传:中断后可继续之前的任务。
  • 🛡️ 智能重试机制:自动处理网络异常和 API 限制。
  • 📁 自动备份:数据安全保障。
  • 💡 NCBI History 功能优化: 利用 NCBI 的 History 功能高效处理大量检索结果,避免一次性获取所有 PMID 列表的限制。

🚀 快速开始

1. 环境准备

# 安装依赖
pip install pandas biopython tqdm urllib3

# 克隆或下载项目
git clone git@github.com:WhyLIM/PubEx.git
cd PubEx # 进入项目目录

2. 创建配置文件

运行以下命令生成一个名为 pubmed_config.json 的示例配置文件:

python PubEx.py --create-example

3. 配置 API 密钥(推荐)

  1. 访问 NCBI API Key Management
  2. 登录或注册 NCBI 账户
  3. 创建新的 API 密钥
  4. 将密钥添加到配置文件的api_key字段

4. 运行程序

配置完成后,运行以下命令启动爬取:

python PubEx.py --config pubmed_config.json

📋 配置文件详解

基本设置

参数 类型 必需 默认值 说明
email string null 邮箱地址,NCBI 建议提供以便出现问题时联系
api_key string null NCBI API 密钥,推荐设置

性能设置

参数 类型 默认值 说明
batch_size int 50 每批处理的文章数量
api_wait_time float 自动 API 请求间隔(自动根据是否有 API 密钥设置)
task_wait_time int 5 不同搜索任务之间的等待时间(秒)

重试设置

参数 类型 默认值 说明
retry_wait_time int 5 重试等待时间(秒)
max_retries int 5 最大重试次数

文件设置

参数 类型 默认值 说明
output_dir string "./results" 结果文件输出目录
log_dir string "./logs" 日志文件目录
overwrite_backup bool true 是否覆盖备份文件

搜索任务

search_tasks 是一个数组,每个任务包含:

字段 类型 必需 说明
name string 任务描述名称
term string PubMed 搜索词
output_file string 输出 CSV 文件名

🔍 搜索词语法示例

基本搜索

"term": "cancer[ti] AND treatment[ti]"

时间范围搜索

"term": "covid-19[ti] AND (\"2020/01/01\"[Date - Publication] : \"2023/12/31\"[Date - Publication])"

复杂组合搜索

"term": "(biomarker[ti] OR marker[ti]) AND (cancer[ti] OR tumor[ti]) AND diagnosis[ti]"

大规模数据处理

程序自动处理超过 9999 篇文章的搜索,通过按年份分批获取。

📊 输出数据格式

程序输出 CSV 文件,包含以下字段:

字段名 说明
Title 文章标题
Status 文章状态
Last Revision Date 最后修订日期
ISSN 国际标准期刊号
Type 文章类型
Year of Publication 发表年份
Date of Electronic Publication 电子发表日期
Publication Date 发表日期
Place of Publication 发表地点
F_Author 第一作者(全名)
Author 作者列表
Affiliation 作者机构
Abstract 摘要
Language 语言
Keywords 关键词
PMID PubMed 唯一标识符
Medline Volume Medline 卷号
Medline Issue Medline 期号
Medline Pagination Medline 页码
DOI 数字对象标识符
PMC PMC 标识符
Processing History 处理历史
Publication Status 发表状态
Journal Title Abbreviation 期刊标题缩写
Journal Title 期刊全称
Journal ID 期刊 ID
Source 来源信息
Grant List 资助列表
cited 被引用次数
cited_by 被引用文章 PMID 列表
References 参考文献数量
References_PMID 参考文献 PMID 列表

💡 使用示例

1. 基本使用(无 API 密钥)

{
    "email": "your.email@example.com",
    "api_key": null,
    "search_tasks": [
        {
            "name": "COVID-19 疫苗研究",
            "term": "covid-19[ti] AND vaccine[ti]",
            "output_file": "covid19_vaccine.csv"
        }
    ]
}

2. 高性能使用(有 API 密钥)

{
    "email": "your.email@example.com",
    "api_key": "your_actual_api_key_here",
    "batch_size": 100,
    "search_tasks": [
        {
            "name": "大规模癌症研究",
            "term": "cancer[ti] AND (\"2020/01/01\"[Date - Publication] : \"2024/12/31\"[Date - Publication])",
            "output_file": "cancer_research_2020_2024.csv"
        }
    ]
}

3. 多任务批处理

{
    "email": "your.email@example.com",
    "api_key": "your_api_key_here",
    "search_tasks": [
        {
            "name": "结直肠癌生物标志物研究",
            "term": "(biomarker[ti] OR marker[ti]) AND (colorectal[ti] OR colon[ti]) AND cancer[ti]",
            "output_file": "colorectal_biomarkers.csv"
        },
        {
            "name": "放射性肠道毒性研究",
            "term": "(toxicity[ti] OR injury[ti]) AND radiation[ti] AND (bowel[ti] OR intestinal[ti])",
            "output_file": "radiation_toxicity.csv"
        }
    ]
}

🛠️ 高级功能

断点续传

  • 自动检测已存在的输出文件。
  • 跳过已处理的文章,只处理新增内容。
  • 支持大规模数据爬取的中断恢复。

智能重试机制

  • 自动处理可能遇到的一般网络错误。

进度监控

  • 支持 tqdm 进度条显示获取进度。

日志系统

  • 按日期分类的详细日志。
  • 错误追踪和调试信息。
  • 统计信息自动保存。

📁 文件结构

PubEx/
├── PubEx.py              # 主程序文件
├── pubmed_config.json    # 配置文件(运行--create-example 生成)
├── results/              # 输出结果目录
│   ├── *.csv            # 爬取的文献数据
│   └── *_backup.csv     # 自动备份文件
└── logs/                 # 日志目录
    ├── pubmed_fetch_*.log # 按日期的日志文件
    └── stats.json        # 统计信息

🔧 故障排除

调试模式

查看详细日志:

# 日志文件位置
./logs/pubmed_fetch_YYYYMMDD.log
./logs/stats.json

🤝 贡献指南

欢迎提交 Issue 和 Pull Request 来帮助改进。

📄 许可证

本项目采用 MIT 许可证

About

PubMed Literature Information Extraction Tool.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages