Skip to content

Commit b980e20

Browse files
authored
🌎 Download PMC data from doi/pmid input (#64)
1 parent 15cd57e commit b980e20

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'jats-fetch': patch
3+
---
4+
5+
Download PMC data from doi/pmid input

packages/jats-fetch/src/download.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import type { ISession } from 'myst-cli-utils';
55
import { isUrl, tic } from 'myst-cli-utils';
66
import {
77
constructJatsUrlFromPubMedCentral,
8+
convertDOI2PMCID,
9+
convertPMID2PMCID,
810
getListingsFile,
911
getPubMedJatsFromData,
1012
getPubMedJatsFromS3,
@@ -191,6 +193,21 @@ export async function jatsFetch(
191193
output = foldername;
192194
}
193195
}
196+
if (input.match(/^[0-9]+$/)) {
197+
// If input is a number, assume it is PMID and try to resolve PMC ID
198+
const pmcid = await convertPMID2PMCID(session, input);
199+
if (pmcid) {
200+
session.log.debug(`Resolved input ${input} to PMC ID: ${pmcid}`);
201+
input = pmcid;
202+
}
203+
}
204+
if (doi.validate(input)) {
205+
const pmcid = await convertDOI2PMCID(session, input);
206+
if (pmcid) {
207+
session.log.debug(`Resolved input ${input} to PMC ID: ${pmcid}`);
208+
input = pmcid;
209+
}
210+
}
194211
if (!output) output = opts.data ? `${input}` : '.';
195212
if (!path.extname(output)) {
196213
filename = filename ?? (input.startsWith('PMC') ? `${input}.xml` : 'jats.xml');

packages/jats-fetch/src/pubmed.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ export async function convertPMCID2DOI(session: ISession, pmcid: string, opts?:
140140
return pmDoi;
141141
}
142142

143+
export async function convertDOI2PMCID(session: ISession, input: string, opts?: ResolutionOptions) {
144+
const pmDoi = await convertId(session, input, 'doi', 'pmcid', opts);
145+
return pmDoi;
146+
}
147+
143148
/**
144149
* Query NIH APIs for single DOI from PubMed ID
145150
*/

0 commit comments

Comments
 (0)