@abi-software/map-utilities 1.2.2-beta.4 → 1.2.2-beta.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abi-software/map-utilities",
3
- "version": "1.2.2-beta.4",
3
+ "version": "1.2.2-beta.5",
4
4
  "files": [
5
5
  "dist/*",
6
6
  "src/*",
@@ -337,7 +337,7 @@ class CytoscapeGraph extends EventTarget
337
337
  },
338
338
  directed: true,
339
339
  style: GRAPH_STYLE,
340
- minZoom: 0.5,
340
+ minZoom: 0.1,
341
341
  maxZoom: 10,
342
342
  wheelSensitivity: 0.4,
343
343
  }).on('mouseover', 'node', this.overNode.bind(this))
@@ -3,7 +3,7 @@
3
3
  <div class="attribute-title-container">
4
4
  <div class="attribute-title">References</div>
5
5
  </div>
6
- <div class="citation-tabs">
6
+ <div class="citation-tabs" v-if="referencesWithDOI">
7
7
  <el-button
8
8
  link
9
9
  v-for="citationOption of citationOptions"
@@ -16,7 +16,7 @@
16
16
  </div>
17
17
  <ul class="citation-list">
18
18
  <li
19
- v-for="reference of references"
19
+ v-for="reference of pubMedReferences"
20
20
  :key="reference.id"
21
21
  :class="{'loading': reference.citation && reference.citation[citationType] === ''}"
22
22
  >
@@ -32,7 +32,7 @@
32
32
  </li>
33
33
 
34
34
  <li v-for="reference of isbnDBReferences">
35
- <a :href="reference.url">{{ reference.url }}</a>
35
+ <a :href="reference.url" target="_blank">{{ reference.url }}</a>
36
36
  <CopyToClipboard :content="reference.url" />
37
37
  </li>
38
38
  </ul>
@@ -73,7 +73,6 @@ export default {
73
73
  },
74
74
  data: function () {
75
75
  return {
76
- references: [],
77
76
  pubMedReferences: [],
78
77
  openLibReferences: [],
79
78
  isbnDBReferences: [],
@@ -84,7 +83,13 @@ export default {
84
83
  watch: {
85
84
  resources: function (_resources) {
86
85
  this.formatReferences([..._resources]);
87
- }
86
+ },
87
+ },
88
+ computed: {
89
+ referencesWithDOI: function () {
90
+ const withDOI = this.pubMedReferences.filter((reference) => reference.type === 'doi' || reference.doi);
91
+ return withDOI.length;
92
+ },
88
93
  },
89
94
  mounted: function () {
90
95
  this.formatReferences([...this.resources]);
@@ -101,16 +106,26 @@ export default {
101
106
  this.extractPublicationIdFromURLString(reference)
102
107
  );
103
108
 
109
+ // pmc to pmid
110
+ this.pubMedReferences.forEach((reference) => {
111
+ if (reference.type === 'pmc') {
112
+ const pmcId = reference.id;
113
+ this.searchPMID(pmcId).then((data) => {
114
+ if (data && data.esearchresult) {
115
+ const idList = data.esearchresult.idlist || [];
116
+ reference.id = idList[0];
117
+ reference.type = 'pmid';
118
+ }
119
+ });
120
+ }
121
+ });
122
+
104
123
  this.formatNonPubMedReferences(nonPubMedReferences).then((responses) => {
105
124
  this.openLibReferences = responses.filter((response) => response.type === 'openlib');
106
125
  this.isbnDBReferences = responses.filter((response) => response.type === 'isbndb');
107
126
 
108
127
  this.formatOpenLibReferences();
109
128
  });
110
-
111
- this.references = [
112
- ...this.pubMedReferences,
113
- ];
114
129
  },
115
130
  extractNonPubMedReferences: function (references) {
116
131
  const extractedReferences = [];
@@ -141,8 +156,7 @@ export default {
141
156
  const failedIDs = isbnIDs.slice();
142
157
 
143
158
  const openlibAPI = `https://openlibrary.org/api/books?bibkeys=${isbnIDsKey}&format=json`;
144
- const response = await fetch(openlibAPI);
145
- const data = await response.json();
159
+ const data = await this.fetchData(openlibAPI);
146
160
 
147
161
  for (const key in data) {
148
162
  const successKeyIndex = failedIDs.indexOf(key);
@@ -175,29 +189,6 @@ export default {
175
189
 
176
190
  return transformedReferences;
177
191
  },
178
- getURLsForPubMed: function (data) {
179
- return new Promise((resolve) => {
180
- const ids = data.map((id) =>
181
- (typeof id === 'object') ?
182
- this.extractPublicationIdFromURLString(id[0]) :
183
- this.extractPublicationIdFromURLString(id)
184
- )
185
- this.convertPublicationIds(ids).then((pmids) => {
186
- if (pmids.length > 0) {
187
- const transformedIDs = [];
188
- pmids.forEach(pmid => {
189
- transformedIDs.push({
190
- id: pmid,
191
- link: this.pubmedSearchUrl(pmid),
192
- })
193
- })
194
- resolve(transformedIDs)
195
- } else {
196
- resolve([])
197
- }
198
- })
199
- })
200
- },
201
192
  extractPublicationIdFromURLString: function (urlStr) {
202
193
  if (!urlStr) return
203
194
 
@@ -248,79 +239,15 @@ export default {
248
239
 
249
240
  return names;
250
241
  },
251
- convertPublicationIds: function (ids) {
252
- return new Promise((resolve) => {
253
- const pmids = []
254
- const toBeConverted = []
255
- ids.forEach((id) => {
256
- if (id.type === "pmid") {
257
- pmids.push(id.id)
258
- } else if (id.type === "doi" || id.type === "pmc") {
259
- toBeConverted.push(id.id)
260
- }
261
- })
262
- this.getPMID(toBeConverted).then((idList) => {
263
- pmids.push(...idList)
264
- resolve(pmids)
265
- })
266
- .catch(() => {
267
- resolve(pmids)
268
- })
269
- })
270
- },
271
- pubmedSearchUrl: function (ids) {
272
- let url = 'https://pubmed.ncbi.nlm.nih.gov/?'
273
- let params = new URLSearchParams()
274
- params.append('term', ids)
275
- return url + params.toString()
276
- },
277
242
  stripPMIDPrefix: function (pubmedId) {
278
243
  return pubmedId.split(':')[1]
279
244
  },
280
- getPMID: function(idsList) {
281
- return new Promise((resolve) => {
282
- if (idsList.length > 0) {
283
- //Muliple term search does not work well,
284
- //DOIs term get splitted unexpectedly
285
- //
286
- const promises = []
287
- const results = []
288
- let wrapped = ''
289
- idsList.forEach((id, i) => {
290
- wrapped += i > 0 ? 'OR"' + id + '"' : '"' + id + '"'
291
- })
292
-
293
- const params = new URLSearchParams({
294
- db: 'pubmed',
295
- term: wrapped,
296
- format: 'json'
297
- })
298
- const promise = fetch(`https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?${params}`, {
299
- method: 'GET',
300
- })
301
- .then((response) => response.json())
302
- .then((data) => {
303
- const newIds = data.esearchresult ? data.esearchresult.idlist : []
304
- results.push(...newIds)
305
- })
306
- promises.push(promise)
307
-
308
- Promise.all(promises).then(() => {
309
- resolve(results)
310
- }).catch(() => {
311
- resolve(results)
312
- })
313
- } else {
314
- resolve([])
315
- }
316
- })
317
- },
318
245
  onCitationFormatChange: function(citationType) {
319
246
  this.citationType = citationType;
320
247
  this.getCitationText(citationType);
321
248
  },
322
249
  getCitationText: function(citationType) {
323
- this.references.forEach((reference) => {
250
+ this.pubMedReferences.forEach((reference) => {
324
251
  const { id, type, doi } = reference;
325
252
 
326
253
  if (
@@ -331,31 +258,71 @@ export default {
331
258
 
332
259
  if (type === 'doi' || doi) {
333
260
  const doiID = type === 'doi' ? id : doi;
334
-
335
- this.getCitationTextByDOI(doiID)
336
- .then((text) => {
337
- reference.citation[citationType] = this.replaceLinkInText(text);
338
- });
261
+ this.getCitationTextByDOI(doiID).then((text) => {
262
+ const formattedText = this.replaceLinkInText(text);
263
+ reference.citation[citationType] = formattedText;
264
+ this.updateCopyContents();
265
+ });
339
266
  } else if (type === 'pmid') {
340
- this.getDOIFromPubMedID(id)
341
- .then((data) => {
342
- if (data?.result) {
343
- const resultObj = data.result[id];
344
- const articleIDs = resultObj?.articleids || [];
345
- const doiObj = articleIDs.find((item) => item.idtype === 'doi');
346
- const doiID = doiObj?.value;
267
+ this.getDOIFromPubMedID(id).then((data) => {
268
+ if (data?.result) {
269
+ const resultObj = data.result[id];
270
+ const articleIDs = resultObj?.articleids || [];
271
+ const doiObj = articleIDs.find((item) => item.idtype === 'doi');
272
+ const doiID = doiObj?.value;
273
+
274
+ if (doiID) {
347
275
  reference['doi'] = doiID;
348
-
349
- this.getCitationTextByDOI(doiID)
350
- .then((text) => {
351
- reference.citation[citationType] = this.replaceLinkInText(text);
352
- });
276
+ this.getCitationTextByDOI(doiID).then((text) => {
277
+ const formattedText = this.replaceLinkInText(text);
278
+ reference.citation[citationType] = formattedText;
279
+ this.updateCopyContents();
280
+ });
281
+ } else {
282
+ // If there has no doi in PubMed
283
+ const { title, pubdate, authors } = resultObj;
284
+ const authorNames = authors ? authors.map((author) => author.name) : [];
285
+ const formattedText = this.formatCopyReference({
286
+ title: title || '',
287
+ date: pubdate || '',
288
+ authors: authorNames,
289
+ url: `https://pubmed.ncbi.nlm.nih.gov/${id}`,
290
+ });
291
+ reference.citation[citationType] = formattedText;
292
+ this.updateCopyContents();
353
293
  }
354
- });
294
+ }
295
+ });
355
296
  }
356
297
  }
357
298
  });
358
299
  },
300
+ updateCopyContents: function () {
301
+ const citationTypeObj = this.citationOptions.find((item) => item.value === this.citationType);
302
+ let citationFormatStyle = '';
303
+ const values = [];
304
+
305
+ if (this.referencesWithDOI) {
306
+ citationFormatStyle = citationTypeObj?.label;
307
+ }
308
+
309
+ this.pubMedReferences.forEach((reference) => {
310
+ values.push(reference.citation[this.citationType]);
311
+ });
312
+
313
+ this.openLibReferences.forEach((reference) => {
314
+ values.push(this.formatCopyReference(reference));
315
+ });
316
+
317
+ this.isbnDBReferences.forEach((reference) => {
318
+ values.push(reference.url);
319
+ });
320
+
321
+ this.$emit('references-loaded', {
322
+ style: citationFormatStyle,
323
+ list: values
324
+ });
325
+ },
359
326
  replaceLinkInText: function (text) {
360
327
  const protocol = 'https://';
361
328
  let linkBody = text.split(protocol)[1];
@@ -376,87 +343,55 @@ export default {
376
343
 
377
344
  return text;
378
345
  },
346
+ searchPMID: async function (term) {
347
+ const esearchAPI = `https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&term=${term}&format=json`;
348
+ return await this.fetchData(esearchAPI);
349
+ },
379
350
  getCitationTextByDOI: async function (id) {
380
351
  const citationAPI = `${CROSSCITE_API_HOST}/format?doi=${id}&style=${this.citationType}&lang=en-US`;
381
- try {
382
- const response = await fetch(citationAPI);
383
- if (!response.ok) {
384
- throw new Error(`Response status: ${response.status}`);
385
- }
386
- const data = await response.text();
387
- return data;
388
- } catch (error) {
389
- console.error(`Fetch citation text error: ${error}`);
390
- }
352
+ return await this.fetchData(citationAPI, 'text');
391
353
  },
392
354
  getDOIFromPubMedID: async function (pubmedId) {
393
355
  const summaryAPI = `https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi?db=pubmed&id=${pubmedId}&format=json`;
394
- try {
395
- const response = await fetch(summaryAPI);
396
- if (!response.ok) {
397
- throw new Error(`Response status: ${response.status}`);
398
- }
399
- const data = await response.json();
400
- return data;
401
- } catch (error) {
402
- console.error(`Fetch article summary error: ${error}`);
403
- }
356
+ return await this.fetchData(summaryAPI);
404
357
  },
405
358
  formatOpenLibReferences: function () {
406
359
  this.openLibReferences.forEach((reference) => {
407
360
  const { bookId } = reference;
408
- this.getBookData(bookId)
409
- .then((data) => {
410
- const { title, authors, publish_date } = data;
411
- if (title) {
412
- reference['title'] = title;
413
- }
361
+ this.getBookData(bookId).then((data) => {
362
+ const { title, authors, publish_date } = data;
363
+ if (title) {
364
+ reference['title'] = title;
365
+ }
414
366
 
415
- if (publish_date) {
416
- reference['date'] = publish_date;
417
- }
367
+ if (publish_date) {
368
+ reference['date'] = publish_date;
369
+ }
418
370
 
419
- if (authors) {
420
- reference['authors'] = [];
371
+ if (authors) {
372
+ reference['authors'] = [];
421
373
 
422
- authors.forEach((author) => {
423
- this.getBookAuthor(author.key)
424
- .then((data) => {
425
- const { name } = data;
426
- if (name) {
427
- reference['authors'].push(name);
428
- }
429
- });
374
+ authors.forEach((author) => {
375
+ this.getBookAuthor(author.key).then((data) => {
376
+ const { name } = data;
377
+ if (name) {
378
+ reference['authors'].push(name);
379
+ this.updateCopyContents();
380
+ }
430
381
  });
431
- }
432
- });
382
+ });
383
+ }
384
+ this.updateCopyContents();
385
+ });
433
386
  });
434
387
  },
435
388
  getBookData: async function (bookId) {
436
389
  const apiURL = `https://openlibrary.org/books/${bookId}.json`;
437
- try {
438
- const response = await fetch(apiURL);
439
- if (!response.ok) {
440
- throw new Error(`Response status: ${response.status}`);
441
- }
442
- const data = await response.json();
443
- return data;
444
- } catch (error) {
445
- console.error(`Fetch book data error: ${error}`);
446
- }
390
+ return await this.fetchData(apiURL);
447
391
  },
448
392
  getBookAuthor: async function (key) {
449
393
  const apiURL = `https://openlibrary.org${key}.json`;
450
- try {
451
- const response = await fetch(apiURL);
452
- if (!response.ok) {
453
- throw new Error(`Response status: ${response.status}`);
454
- }
455
- const data = await response.json();
456
- return data;
457
- } catch (error) {
458
- console.error(`Fetch book author error: ${error}`);
459
- }
394
+ return await this.fetchData(apiURL);
460
395
  },
461
396
  formatCopyReference: function (reference) {
462
397
  const copyContents = [];
@@ -478,6 +413,22 @@ export default {
478
413
 
479
414
  return copyContents.join(' ');
480
415
  },
416
+ fetchData: async function (apiURL, format) {
417
+ try {
418
+ const response = await fetch(apiURL);
419
+ if (!response.ok) {
420
+ throw new Error(`Response status: ${response.status}`);
421
+ }
422
+
423
+ if (format === 'text') {
424
+ return await response.text();
425
+ } else {
426
+ return await response.json();
427
+ }
428
+ } catch (error) {
429
+ console.error(`Fetch data error: ${error}`);
430
+ }
431
+ },
481
432
  },
482
433
  }
483
434
  </script>