Skip to content

Commit 84b1edc

Browse files
committed
Add ePMC publication URL handling and remove unused DOI DbType branch
1 parent 6dda94c commit 84b1edc

File tree

2 files changed

+51
-11
lines changed

2 files changed

+51
-11
lines changed

ddbj_search_converter/jsonl/bp.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,17 @@ def parse_publication(project: dict[str, Any], accession: str = "") -> list[Publ
185185
id_ = item.get("id")
186186
dbtype = item.get("DbType")
187187
publication_url = None
188-
if dbtype in ("DOI", "eDOI"):
188+
if dbtype == "eDOI":
189189
publication_url = f"https://doi.org/{id_}"
190190
elif dbtype == "ePubmed":
191191
publication_url = f"https://pubmed.ncbi.nlm.nih.gov/{id_}/"
192+
elif dbtype == "ePMC":
193+
if id_ is not None and id_.startswith("PMC"):
194+
publication_url = f"https://www.ncbi.nlm.nih.gov/pmc/articles/{id_}/"
195+
elif id_ is not None and id_.isdigit():
196+
publication_url = f"https://www.ncbi.nlm.nih.gov/pmc/articles/PMC{id_}/"
197+
elif id_ is not None and id_.startswith("10."):
198+
publication_url = f"https://doi.org/{id_}"
192199
elif dbtype is not None and dbtype.isdigit():
193200
dbtype = "ePubmed"
194201
publication_url = f"https://pubmed.ncbi.nlm.nih.gov/{id_}/"

tests/py_tests/jsonl/test_bp.py

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -205,27 +205,60 @@ def test_single_publication(self) -> None:
205205
assert pubs[0].url is not None
206206
assert "pubmed" in pubs[0].url
207207

208-
def test_publication_doi(self) -> None:
208+
def test_publication_edoi(self) -> None:
209+
"""DbType が eDOI の場合、doi.org の URL を生成する。"""
209210
project = _make_project()
210211
project["Project"]["ProjectDescr"]["Publication"] = {
211-
"id": "10.1234/test",
212-
"DbType": "DOI",
212+
"id": "10.1271/bbb.60419",
213+
"DbType": "eDOI",
213214
}
214215
pubs = parse_publication(project)
215216
assert len(pubs) == 1
216-
assert pubs[0].url is not None
217-
assert "doi.org" in pubs[0].url
217+
assert pubs[0].url == "https://doi.org/10.1271/bbb.60419"
218218

219-
def test_publication_edoi(self) -> None:
220-
"""DbType が eDOI の場合、doi.org の URL を生成する。"""
219+
def test_publication_epmc_with_prefix(self) -> None:
220+
"""DbType が ePMC で PMC プレフィックス付き ID の場合。"""
221221
project = _make_project()
222222
project["Project"]["ProjectDescr"]["Publication"] = {
223-
"id": "10.1271/bbb.60419",
224-
"DbType": "eDOI",
223+
"id": "PMC3564981",
224+
"DbType": "ePMC",
225225
}
226226
pubs = parse_publication(project)
227227
assert len(pubs) == 1
228-
assert pubs[0].url == "https://doi.org/10.1271/bbb.60419"
228+
assert pubs[0].url == "https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3564981/"
229+
230+
def test_publication_epmc_numeric(self) -> None:
231+
"""DbType が ePMC で数字のみの ID の場合、PMC プレフィックスを付与する。"""
232+
project = _make_project()
233+
project["Project"]["ProjectDescr"]["Publication"] = {
234+
"id": "3594186",
235+
"DbType": "ePMC",
236+
}
237+
pubs = parse_publication(project)
238+
assert len(pubs) == 1
239+
assert pubs[0].url == "https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3594186/"
240+
241+
def test_publication_epmc_doi_format(self) -> None:
242+
"""DbType が ePMC だが ID が DOI 形式の場合、DOI としてリンクする。"""
243+
project = _make_project()
244+
project["Project"]["ProjectDescr"]["Publication"] = {
245+
"id": "10.1007/s10531-014-0684-8",
246+
"DbType": "ePMC",
247+
}
248+
pubs = parse_publication(project)
249+
assert len(pubs) == 1
250+
assert pubs[0].url == "https://doi.org/10.1007/s10531-014-0684-8"
251+
252+
def test_publication_not_available(self) -> None:
253+
"""DbType が eNotAvailable の場合、url は None。"""
254+
project = _make_project()
255+
project["Project"]["ProjectDescr"]["Publication"] = {
256+
"id": "unpublished",
257+
"DbType": "eNotAvailable",
258+
}
259+
pubs = parse_publication(project)
260+
assert len(pubs) == 1
261+
assert pubs[0].url is None
229262

230263
def test_publication_numeric_dbtype(self) -> None:
231264
"""DbType が数字の場合、ePubmed として扱う。"""

0 commit comments

Comments
 (0)