You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无需下载直接解析PubChem远程xml.gz文件,提取毒性代码对应CID

直接在PubChem服务器解析获取含H300毒性代码的化合物CID列表

方法1:使用PubChem PUG-REST API查询

这是最便捷的方式,无需处理大文件,直接通过API过滤并获取结果:

  • 构造API请求,指定过滤条件为GHS毒性代码H300,返回仅包含CID的结果
  • 用命令行工具curl发起请求,配合jq提取CID(需提前安装jq):
curl "https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/filter/JSON?ghs_hazard_code=H300&property=CID" | jq -r '.PropertyTable.Properties[].CID'
  • 可将结果直接输出到文件保存:
curl "https://pubchem.ncbi.nlm.nih.gov/rest/pug/compound/filter/JSON?ghs_hazard_code=H300&property=CID" | jq -r '.PropertyTable.Properties[].CID' > h300_cids.txt

方法2:使用NCBI EDirect工具远程查询

EDirect是NCBI官方命令行工具集,可直接与PubChem数据库交互:

  1. 完成EDirect的本地安装
  2. 执行以下命令提取符合条件的CID:
esearch -db pubchem_compound -query "H300[GHS Hazard Code]" | efetch -format docsum | xtract -pattern DocumentSummary -element CID
  • 该命令通过NCBI检索系统直接筛选目标化合物,输出CID列表。

方法3:流式处理FTP上的压缩XML文件

如果需要直接处理FTP上的原始压缩文件,可通过流式解压+XML解析的方式,无需本地存储完整文件:

  • 使用curl获取压缩文件流,通过zcat实时解压,再用xmlstarlet(需提前安装)筛选含H300毒性代码的条目并提取CID:
curl https://ftp.ncbi.nih.gov/pubchem/Compound/CURRENT-Full/XML/Compound_000000001_000025000.xml.gz | zcat | xmlstarlet sel -t -m "/PC-Compound[./PC-Compound_properties/PC-Property/PC-Property_desc/PC-Text[text()='GHS Hazard Statements']/../PC-Property_value/PC-Text[contains(text(), 'H300')]]" -v "./PC-Compound_id/PC-Compound_id_cid" -n
  • 注意:FTP上的化合物XML文件按CID范围分块存储,需遍历所有分块文件执行命令,或编写脚本批量处理。

内容的提问来源于stack exchange,提问作者Diana

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.23 19:35:27