Datasets:
Upload folder using huggingface_hub
Browse files- .gitattributes +5 -0
- 2023/journal_impact.csv +0 -0
- 2023/meta.jsonl +3 -0
- 2023/pmid_to_citation.json +3 -0
- 2023/pmid_to_meta_offset.json +3 -0
- 2025/merge_large_data.py +13 -0
- 2025/meta_info_2025_0327_part1.csv +3 -0
- 2025/meta_info_2025_0327_part2.csv +3 -0
- 2025/split_large_data.py +17 -0
- download.py +105 -0
- process_metadata.py +171 -0
- readme.md +15 -0
.gitattributes
CHANGED
|
@@ -57,3 +57,8 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 57 |
# Video files - compressed
|
| 58 |
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 59 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
# Video files - compressed
|
| 58 |
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 59 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
| 60 |
+
2023/meta.jsonl filter=lfs diff=lfs merge=lfs -text
|
| 61 |
+
2023/pmid_to_citation.json filter=lfs diff=lfs merge=lfs -text
|
| 62 |
+
2023/pmid_to_meta_offset.json filter=lfs diff=lfs merge=lfs -text
|
| 63 |
+
2025/meta_info_2025_0327_part1.csv filter=lfs diff=lfs merge=lfs -text
|
| 64 |
+
2025/meta_info_2025_0327_part2.csv filter=lfs diff=lfs merge=lfs -text
|
2023/journal_impact.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
2023/meta.jsonl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d944bf7e0d0a9c490e4684492efd20ec6c2a7641e2cf6d8166b1f6fbf047c5f1
|
| 3 |
+
size 7925257329
|
2023/pmid_to_citation.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:44b21bb4458488a0393cf2d4c55b921aedd68b19f27297bccd13b99371a7f071
|
| 3 |
+
size 404894565
|
2023/pmid_to_meta_offset.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d255923d407a0f10172fda82396fa6983a2604bcfeec681813c00225ed2d0f8c
|
| 3 |
+
size 834226190
|
2025/merge_large_data.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
|
| 3 |
+
# 读取拆分后的 CSV 文件
|
| 4 |
+
df1 = pd.read_csv('meta_info_2025_0327_part1.csv')
|
| 5 |
+
df2 = pd.read_csv('meta_info_2025_0327_part2.csv')
|
| 6 |
+
|
| 7 |
+
# 合并数据框
|
| 8 |
+
df_merged = pd.concat([df1, df2], ignore_index=True)
|
| 9 |
+
|
| 10 |
+
# 保存合并后的 CSV 文件
|
| 11 |
+
df_merged.to_csv('meta_info_2025_0327.csv', index=False)
|
| 12 |
+
|
| 13 |
+
print("CSV 文件已成功合并!")
|
2025/meta_info_2025_0327_part1.csv
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a881cb2c324f11c5ecd3c4789b96f49bbfb10c6484b6b59c7349c1abd75150e6
|
| 3 |
+
size 24783788188
|
2025/meta_info_2025_0327_part2.csv
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:20ca28405daf4d59dfef1b361166d4675d323898cfbf78583675767510eacc35
|
| 3 |
+
size 25430171535
|
2025/split_large_data.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
|
| 3 |
+
# 读取原始 CSV 文件
|
| 4 |
+
df = pd.read_csv('meta_info_2025_0327.csv')
|
| 5 |
+
|
| 6 |
+
# 计算拆分点,假设将文件拆分为两半
|
| 7 |
+
split_index = len(df) // 2
|
| 8 |
+
|
| 9 |
+
# 拆分数据帧
|
| 10 |
+
df1 = df.iloc[:split_index] # 前半部分
|
| 11 |
+
df2 = df.iloc[split_index:] # 后半部分
|
| 12 |
+
|
| 13 |
+
# 保存拆分后的 CSV 文件
|
| 14 |
+
df1.to_csv('meta_info_2025_0327_part1.csv', index=False)
|
| 15 |
+
df2.to_csv('meta_info_2025_0327_part2.csv', index=False)
|
| 16 |
+
|
| 17 |
+
print("CSV 文件拆分完成!")
|
download.py
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import os
|
| 3 |
+
import ftplib
|
| 4 |
+
import hashlib
|
| 5 |
+
import logging
|
| 6 |
+
from time import sleep
|
| 7 |
+
|
| 8 |
+
# 配置参数
|
| 9 |
+
ftp_url = "download.nmdc.cn"
|
| 10 |
+
ftp_dir = "/pubmed"
|
| 11 |
+
local_dir = "./pubmed_data"
|
| 12 |
+
file_patterns = (".xml.gz", ".md5") # 需要下载的文件类型
|
| 13 |
+
max_retries = 3 # 单个文件下载失败重试次数
|
| 14 |
+
retry_delay = 10 # 重试间隔(秒)
|
| 15 |
+
|
| 16 |
+
# 初始化日志
|
| 17 |
+
logging.basicConfig(
|
| 18 |
+
filename='pubmed_download.log',
|
| 19 |
+
level=logging.INFO,
|
| 20 |
+
format='%(asctime)s - %(levelname)s - %(message)s',
|
| 21 |
+
encoding='utf-8'
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
def verify_md5(file_path, expected_md5):
|
| 25 |
+
"""验证文件的MD5校验码"""
|
| 26 |
+
hash_md5 = hashlib.md5()
|
| 27 |
+
with open(file_path, "rb") as f:
|
| 28 |
+
for chunk in iter(lambda: f.read(4096), b""):
|
| 29 |
+
hash_md5.update(chunk)
|
| 30 |
+
return hash_md5.hexdigest() == expected_md5
|
| 31 |
+
|
| 32 |
+
def download_file(ftp, filename, local_path):
|
| 33 |
+
"""带重试机制的文件下载"""
|
| 34 |
+
for attempt in range(max_retries):
|
| 35 |
+
try:
|
| 36 |
+
with open(local_path, 'wb') as f:
|
| 37 |
+
ftp.retrbinary(f"RETR {filename}", f.write)
|
| 38 |
+
return True
|
| 39 |
+
except Exception as e:
|
| 40 |
+
logging.error(f"Attempt {attempt+1} failed for {filename}: {str(e)}")
|
| 41 |
+
if attempt < max_retries - 1:
|
| 42 |
+
sleep(retry_delay)
|
| 43 |
+
os.remove(local_path)
|
| 44 |
+
return False
|
| 45 |
+
|
| 46 |
+
def main():
|
| 47 |
+
# 创建本地目录
|
| 48 |
+
os.makedirs(local_dir, exist_ok=True)
|
| 49 |
+
error_files = []
|
| 50 |
+
try:
|
| 51 |
+
# 连接FTP
|
| 52 |
+
ftp = ftplib.FTP(ftp_url, timeout=30)
|
| 53 |
+
ftp.login() # 匿名登录
|
| 54 |
+
ftp.cwd(ftp_dir)
|
| 55 |
+
|
| 56 |
+
# 获取文件列表
|
| 57 |
+
files = [f for f in ftp.nlst() if f.endswith(file_patterns) and f.startswith('pubmed25')]
|
| 58 |
+
logging.info(f"Found {len(files)} files to process")
|
| 59 |
+
|
| 60 |
+
# 下载主循环
|
| 61 |
+
for idx, filename in enumerate(files, 1):
|
| 62 |
+
try:
|
| 63 |
+
local_path = os.path.join(local_dir, filename)
|
| 64 |
+
|
| 65 |
+
# 跳过已存在的完整文件
|
| 66 |
+
if os.path.exists(local_path):
|
| 67 |
+
logging.info(f"Skipping existing file: {filename}")
|
| 68 |
+
continue
|
| 69 |
+
|
| 70 |
+
# 下载文件
|
| 71 |
+
logging.info(f"Downloading ({idx}/{len(files)}) {filename}")
|
| 72 |
+
success = download_file(ftp, filename, local_path)
|
| 73 |
+
|
| 74 |
+
# MD5校验
|
| 75 |
+
if success and filename.endswith(".md5"):
|
| 76 |
+
continue # 不需要校验MD5文件本身
|
| 77 |
+
else:
|
| 78 |
+
logging.info(f"Downloading MD5 for {filename}")
|
| 79 |
+
md5_file = filename + ".md5"
|
| 80 |
+
md5_local_path = os.path.join(local_dir, md5_file)
|
| 81 |
+
success2 = download_file(ftp, md5_file, md5_local_path)
|
| 82 |
+
|
| 83 |
+
if success and success2 and filename.endswith(".xml.gz"):
|
| 84 |
+
md5_file = filename + ".md5"
|
| 85 |
+
if md5_file in files:
|
| 86 |
+
md5_path = os.path.join(local_dir, md5_file)
|
| 87 |
+
with open(md5_path) as f:
|
| 88 |
+
expected_md5 = f.read().split()[1].replace('\n', '')
|
| 89 |
+
if not verify_md5(local_path, expected_md5):
|
| 90 |
+
logging.error(f"MD5 mismatch for {filename}")
|
| 91 |
+
os.remove(local_path) # 删除损坏文件
|
| 92 |
+
except Exception as e:
|
| 93 |
+
logging.error(f"{filename}:Fatal error: {str(e)}")
|
| 94 |
+
error_files.append(filename)
|
| 95 |
+
|
| 96 |
+
except Exception as e:
|
| 97 |
+
logging.error(f"Fatal error: {str(e)}")
|
| 98 |
+
finally:
|
| 99 |
+
if 'ftp' in locals():
|
| 100 |
+
ftp.quit()
|
| 101 |
+
with open('./error_file.json', 'w') as f:
|
| 102 |
+
json.dump(error_files, f)
|
| 103 |
+
|
| 104 |
+
if __name__ == "__main__":
|
| 105 |
+
main()
|
process_metadata.py
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import gzip
|
| 3 |
+
import xml.etree.ElementTree as ET
|
| 4 |
+
import pandas as pd
|
| 5 |
+
import tqdm
|
| 6 |
+
import glob
|
| 7 |
+
|
| 8 |
+
import xml.etree.ElementTree as ET
|
| 9 |
+
|
| 10 |
+
def extract_meta_info(xml_content):
|
| 11 |
+
root = ET.fromstring(xml_content)
|
| 12 |
+
meta_info_list = [] # List to hold metadata of each article
|
| 13 |
+
|
| 14 |
+
# Loop over each article in the XML (assuming it's in a root <PubmedArticle> list)
|
| 15 |
+
articles = root.findall(".//PubmedArticle") # Or adjust the XPath based on your XML structure
|
| 16 |
+
|
| 17 |
+
for article in articles:
|
| 18 |
+
meta_info = {}
|
| 19 |
+
|
| 20 |
+
# Extract PMID
|
| 21 |
+
pmid = article.find(".//PMID")
|
| 22 |
+
meta_info['PMID'] = pmid.text if pmid is not None else None
|
| 23 |
+
|
| 24 |
+
# Extract DateCompleted
|
| 25 |
+
date_completed = article.find(".//DateCompleted")
|
| 26 |
+
if date_completed is not None:
|
| 27 |
+
year = date_completed.find(".//Year")
|
| 28 |
+
month = date_completed.find(".//Month")
|
| 29 |
+
day = date_completed.find(".//Day")
|
| 30 |
+
meta_info['DateCompleted'] = f"{year.text}-{month.text}-{day.text}" if year is not None and month is not None and day is not None else None
|
| 31 |
+
|
| 32 |
+
# Extract DateRevised
|
| 33 |
+
date_revised = article.find(".//DateRevised")
|
| 34 |
+
if date_revised is not None:
|
| 35 |
+
year = date_revised.find(".//Year")
|
| 36 |
+
month = date_revised.find(".//Month")
|
| 37 |
+
day = date_revised.find(".//Day")
|
| 38 |
+
meta_info['DateRevised'] = f"{year.text}-{month.text}-{day.text}" if year is not None and month is not None and day is not None else None
|
| 39 |
+
|
| 40 |
+
# Extract ISSN
|
| 41 |
+
issn = article.find(".//ISSN")
|
| 42 |
+
meta_info['ISSN'] = issn.text if issn is not None else None
|
| 43 |
+
|
| 44 |
+
# Extract Journal Title
|
| 45 |
+
journal_title = article.find(".//Journal/Title")
|
| 46 |
+
meta_info['JournalTitle'] = journal_title.text if journal_title is not None else None
|
| 47 |
+
|
| 48 |
+
# Extract Article Title
|
| 49 |
+
article_title = article.find(".//ArticleTitle")
|
| 50 |
+
meta_info['ArticleTitle'] = article_title.text if article_title is not None else None
|
| 51 |
+
|
| 52 |
+
# Extract Authors
|
| 53 |
+
authors = article.findall(".//AuthorList/Author")
|
| 54 |
+
author_names = []
|
| 55 |
+
for author in authors:
|
| 56 |
+
last_name = author.find(".//LastName")
|
| 57 |
+
fore_name = author.find(".//ForeName")
|
| 58 |
+
if last_name is not None and fore_name is not None:
|
| 59 |
+
author_names.append(f"{last_name.text} {fore_name.text}")
|
| 60 |
+
meta_info['Authors'] = ', '.join(author_names) if author_names else None
|
| 61 |
+
|
| 62 |
+
# Extract Language
|
| 63 |
+
language = article.find(".//Language")
|
| 64 |
+
meta_info['Language'] = language.text if language is not None else None
|
| 65 |
+
|
| 66 |
+
# Extract Grants
|
| 67 |
+
grants = article.findall(".//GrantList/Grant")
|
| 68 |
+
grant_info = []
|
| 69 |
+
for grant in grants:
|
| 70 |
+
grant_id = grant.find(".//GrantID")
|
| 71 |
+
agency = grant.find(".//Agency")
|
| 72 |
+
country = grant.find(".//Country")
|
| 73 |
+
if grant_id is not None and agency is not None and country is not None:
|
| 74 |
+
grant_info.append(f"{grant_id.text} ({agency.text}, {country.text})")
|
| 75 |
+
meta_info['Grants'] = '; '.join(grant_info) if grant_info else None
|
| 76 |
+
|
| 77 |
+
# Extract Publication Types
|
| 78 |
+
publication_types = article.findall(".//PublicationTypeList/PublicationType")
|
| 79 |
+
pub_types = []
|
| 80 |
+
for pub_type in publication_types:
|
| 81 |
+
pub_types.append(pub_type.text)
|
| 82 |
+
meta_info['PublicationTypes'] = ', '.join(pub_types) if pub_types else None
|
| 83 |
+
|
| 84 |
+
# Extract Chemicals
|
| 85 |
+
chemicals = article.findall(".//ChemicalList/Chemical")
|
| 86 |
+
chemical_info = []
|
| 87 |
+
for chemical in chemicals:
|
| 88 |
+
substance_name = chemical.find(".//NameOfSubstance")
|
| 89 |
+
if substance_name is not None:
|
| 90 |
+
chemical_info.append(substance_name.text)
|
| 91 |
+
meta_info['Chemicals'] = ', '.join(chemical_info) if chemical_info else None
|
| 92 |
+
|
| 93 |
+
# Extract CitationSubset
|
| 94 |
+
citation_subset = article.find(".//CitationSubset")
|
| 95 |
+
meta_info['CitationSubset'] = citation_subset.text if citation_subset is not None else None
|
| 96 |
+
|
| 97 |
+
# Extract Article IDs (DOI, etc.)
|
| 98 |
+
article_ids = article.findall(".//ArticleIdList/ArticleId")
|
| 99 |
+
article_id_info = []
|
| 100 |
+
for article_id in article_ids:
|
| 101 |
+
article_id_info.append(article_id.text)
|
| 102 |
+
meta_info['ArticleIds'] = ', '.join(filter(None, article_id_info)) if article_id_info else None
|
| 103 |
+
|
| 104 |
+
# Extract Abstract
|
| 105 |
+
abstract = article.find(".//Abstract/AbstractText")
|
| 106 |
+
meta_info['Abstract'] = abstract.text if abstract is not None else None
|
| 107 |
+
|
| 108 |
+
# Extract Mesh Terms
|
| 109 |
+
mesh_terms = article.findall(".//MeshHeadingList/MeshHeading")
|
| 110 |
+
mesh_terms_info = []
|
| 111 |
+
for mesh_term in mesh_terms:
|
| 112 |
+
descriptor_name = mesh_term.find(".//DescriptorName")
|
| 113 |
+
if descriptor_name is not None:
|
| 114 |
+
mesh_terms_info.append(descriptor_name.text)
|
| 115 |
+
meta_info['MeshTerms'] = ', '.join(filter(None, mesh_terms_info)) if mesh_terms_info else None
|
| 116 |
+
|
| 117 |
+
# Extract Keywords
|
| 118 |
+
keywords = article.findall(".//KeywordList/Keyword")
|
| 119 |
+
keyword_info = []
|
| 120 |
+
for keyword in keywords:
|
| 121 |
+
keyword_info.append(keyword.text)
|
| 122 |
+
meta_info['Keywords'] = ', '.join(filter(None, keyword_info)) if keyword_info else None
|
| 123 |
+
|
| 124 |
+
# Append the metadata for this article to the list
|
| 125 |
+
meta_info_list.append(meta_info)
|
| 126 |
+
|
| 127 |
+
return meta_info_list
|
| 128 |
+
|
| 129 |
+
def extract(input_dir, output_csv):
|
| 130 |
+
# Create a temporary directory to store individual CSVs
|
| 131 |
+
temp_dir = os.path.join(os.path.dirname(output_csv), 'temp')
|
| 132 |
+
os.makedirs(temp_dir, exist_ok=True)
|
| 133 |
+
|
| 134 |
+
# Iterate over all .gz files in the directory
|
| 135 |
+
for filename in tqdm.tqdm(os.listdir(input_dir)):
|
| 136 |
+
if filename.endswith('.xml.gz'):
|
| 137 |
+
file_path = os.path.join(input_dir, filename)
|
| 138 |
+
|
| 139 |
+
# Decompress and read the XML content
|
| 140 |
+
with gzip.open(file_path, 'rb') as f:
|
| 141 |
+
xml_content = f.read()
|
| 142 |
+
|
| 143 |
+
# Extract meta information
|
| 144 |
+
meta_info_list = extract_meta_info(xml_content)
|
| 145 |
+
|
| 146 |
+
# Save meta information to a temporary CSV file
|
| 147 |
+
temp_csv_path = os.path.join(temp_dir, f"{os.path.splitext(filename)[0]}.csv")
|
| 148 |
+
|
| 149 |
+
# Create a DataFrame from the list of dictionaries (each dict represents an article's metadata)
|
| 150 |
+
df = pd.DataFrame(meta_info_list)
|
| 151 |
+
|
| 152 |
+
# Save the DataFrame to a CSV file
|
| 153 |
+
df.to_csv(temp_csv_path, index=False)
|
| 154 |
+
|
| 155 |
+
# Combine all temporary CSVs into a single large CSV file
|
| 156 |
+
all_csv_files = glob.glob(os.path.join(temp_dir, '*.csv'))
|
| 157 |
+
combined_df = pd.concat((pd.read_csv(f) for f in all_csv_files), ignore_index=True)
|
| 158 |
+
combined_df.to_csv(output_csv, index=False)
|
| 159 |
+
|
| 160 |
+
# Optionally, delete the temporary files
|
| 161 |
+
# for f in all_csv_files:
|
| 162 |
+
# os.remove(f)
|
| 163 |
+
# os.rmdir(temp_dir)
|
| 164 |
+
|
| 165 |
+
print(f"Meta information extracted and saved to {output_csv}")
|
| 166 |
+
|
| 167 |
+
if __name__ == "__main__":
|
| 168 |
+
# Define the input directory
|
| 169 |
+
input_dir = './pubmed_data' # Replace with actual path
|
| 170 |
+
output_csv = './2025/meta_info_2025_0327.csv' # Output CSV file path
|
| 171 |
+
extract(input_dir=input_dir, output_csv=output_csv)
|
readme.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 1. origin source
|
| 2 |
+
https://ftp.ncbi.nlm.nih.gov/pubmed/baseline/
|
| 3 |
+
|
| 4 |
+
# 2. 2023 data sources
|
| 5 |
+
https://github.com/jacobvsdanniel/pubmedkb_web
|
| 6 |
+
*We processed all 35M PubMed citations dumped on 2023/02/17.
|
| 7 |
+
https://drive.google.com/file/d/17AUaMe0w3xJq3rr0Njs1tok2y3RS5tQ2/view
|
| 8 |
+
|
| 9 |
+
# 3. 2025 data sources
|
| 10 |
+
|
| 11 |
+
https://www.nmdc.cn/datadownload
|
| 12 |
+
|
| 13 |
+
[download.py](download.py) : need monthly update
|
| 14 |
+
|
| 15 |
+
[process_meatadata.py](process_meatadata.py) : need process xml to csv
|