@abi-software/flatmapvuer 1.6.2 → 1.7.0

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.
@@ -83,6 +83,7 @@
83
83
  :displayMinimap="displayMinimap"
84
84
  :showStarInLegend="showStarInLegend"
85
85
  style="height: 100%"
86
+ :mapManager="mapManagerRef"
86
87
  :flatmapAPI="flatmapAPI"
87
88
  :sparcAPI="sparcAPI"
88
89
  />
@@ -124,6 +125,9 @@ export default {
124
125
  Popover,
125
126
  FlatmapVuer,
126
127
  },
128
+ created: function () {
129
+ this.loadMapManager();
130
+ },
127
131
  mounted: function () {
128
132
  this.initialise()
129
133
  EventBus.on('onActionClick', (action) => {
@@ -219,6 +223,23 @@ export default {
219
223
  }
220
224
  })
221
225
  },
226
+ /**
227
+ * Function to load `mapManager` to create flatmap.
228
+ */
229
+ loadMapManager: function () {
230
+ if (!this.mapManagerRef) {
231
+ if (this.mapManager) {
232
+ this.mapManagerRef = this.mapManager;
233
+ } else {
234
+ this.mapManagerRef = markRaw(new flatmap.MapManager(this.flatmapAPI));
235
+ /**
236
+ * The event emitted after a new mapManager is loaded.
237
+ * This mapManager can be used to create new flatmaps.
238
+ */
239
+ this.$emit('mapmanager-loaded', this.mapManagerRef);
240
+ }
241
+ }
242
+ },
222
243
  /**
223
244
  * @public
224
245
  * Function to emit ``resource-selected`` event with provided ``resource``.
@@ -410,12 +431,11 @@ export default {
410
431
  //uuid is in the state but should be checked if it is the latest map
411
432
  //for that taxon
412
433
  return new Promise(() => {
413
- const mapManager = new flatmap.MapManager(this.flatmapAPI)
414
434
  //mapManager.findMap_ is an async function so we need to wrap this with a promise
415
435
  const identifier = { taxon: mapState.entry }
416
436
  if (mapState.biologicalSex)
417
437
  identifier['biologicalSex'] = mapState.biologicalSex
418
- mapManager
438
+ this.mapManagerRef
419
439
  .findMap_(identifier)
420
440
  .then((map) => {
421
441
  if (map.uuid !== mapState.uuid) {
@@ -461,6 +481,9 @@ export default {
461
481
  */
462
482
  setState: function (state) {
463
483
  if (state) {
484
+ // Update undefined mapManagerRef for setState happens before created event
485
+ this.loadMapManager();
486
+
464
487
  //Update state if required
465
488
  this.updateState(state).then((currentState) => {
466
489
  this.initialise().then(() => {
@@ -696,6 +719,14 @@ export default {
696
719
  type: Object,
697
720
  default: undefined,
698
721
  },
722
+ /**
723
+ * Flatmap's Map Manager to use as single Map Manager
724
+ * when the value is provided.
725
+ */
726
+ mapManager: {
727
+ type: Object,
728
+ default: undefined,
729
+ },
699
730
  /**
700
731
  * Specify the endpoint of the flatmap server.
701
732
  */
@@ -739,6 +770,7 @@ export default {
739
770
  requireInitialisation: true,
740
771
  resolveList: markRaw([]),
741
772
  initialised: false,
773
+ mapManagerRef: undefined,
742
774
  }
743
775
  },
744
776
  watch: {
@@ -81,7 +81,7 @@ let FlatmapQueries = function () {
81
81
  this.destinations = []
82
82
  this.origins = []
83
83
  this.components = []
84
- this.urls = []
84
+ this.rawURLs = []
85
85
  this.controller = undefined
86
86
  this.uberons = []
87
87
  this.lookUp = []
@@ -95,7 +95,7 @@ let FlatmapQueries = function () {
95
95
  ) {
96
96
  hyperlinks = eventData.feature.hyperlinks
97
97
  } else {
98
- hyperlinks = this.urls.map((url) => ({ url: url, id: 'pubmed' }))
98
+ hyperlinks = this.rawURLs;
99
99
  }
100
100
  let taxonomyLabel = undefined
101
101
  if (eventData.provenanceTaxonomy) {
@@ -245,11 +245,10 @@ let FlatmapQueries = function () {
245
245
  this.destinations = []
246
246
  this.origins = []
247
247
  this.components = []
248
- this.urls = []
248
+ this.rawURLs = []
249
249
  if (!keastIds || keastIds.length == 0 || !keastIds[0]) return
250
250
 
251
251
  let prom1 = this.queryForConnectivityNew(mapImp, keastIds, signal) // This on returns a promise so dont need 'await'
252
- // let prom2 = await this.pubmedQueryOnIds(eventData)
253
252
  let results = await Promise.all([prom1])
254
253
  return results
255
254
  }
@@ -264,14 +263,9 @@ let FlatmapQueries = function () {
264
263
  this.processConnectivity(mapImp, connectivity).then((processedConnectivity) => {
265
264
  // response.references is publication urls
266
265
  if (response.references) {
267
- // with publications
268
- this.getURLsForPubMed(response.references).then((urls) => {
269
- // TODO: if empty urls array is returned,
270
- // the urls are not on PubMed.
271
- // Those urls, response.references, will be shown in another way.
272
- this.urls = urls;
273
- resolve(processedConnectivity)
274
- })
266
+ // with publications from both PubMed and Others
267
+ this.rawURLs = [...response.references];
268
+ resolve(processedConnectivity)
275
269
  } else {
276
270
  // without publications
277
271
  resolve(processedConnectivity)
@@ -469,132 +463,6 @@ let FlatmapQueries = function () {
469
463
  return found.flat()
470
464
  }
471
465
 
472
- this.stripPMIDPrefix = function (pubmedId) {
473
- return pubmedId.split(':')[1]
474
- }
475
-
476
- this.getPMID = function(idsList) {
477
- return new Promise((resolve) => {
478
- if (idsList.length > 0) {
479
- //Muliple term search does not work well,
480
- //DOIs term get splitted unexpectedly
481
- //
482
- const promises = []
483
- const results = []
484
- idsList.forEach((id) => {
485
- const wrapped = '"' + id + '"'
486
- const params = new URLSearchParams({
487
- db: 'pubmed',
488
- term: wrapped,
489
- format: 'json'
490
- })
491
- const promise = fetch(`https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?${params}`, {
492
- method: 'GET',
493
- })
494
- .then((response) => response.json())
495
- .then((data) => {
496
- const newIds = data.esearchresult ? data.esearchresult.idlist : []
497
- results.push(...newIds)
498
- })
499
- promises.push(promise)
500
- })
501
-
502
- Promise.all(promises).then(() => {
503
- resolve(results)
504
- }).catch(() => {
505
- resolve(results)
506
- })
507
- } else {
508
- resolve([])
509
- }
510
- })
511
- }
512
-
513
- this.convertPublicationIds = function (ids) {
514
- return new Promise((resolve) => {
515
- const pmids = []
516
- const toBeConverted = []
517
- ids.forEach((id) => {
518
- if (id.type === "pmid") {
519
- pmids.push(id.id)
520
- } else if (id.type === "doi" || id.type === "pmc") {
521
- toBeConverted.push(id.id)
522
- }
523
- })
524
- this.getPMID(toBeConverted).then((idList) => {
525
- pmids.push(...idList)
526
- resolve(pmids)
527
- })
528
- .catch(() => {
529
- resolve(pmids)
530
- })
531
- })
532
- }
533
-
534
- this.extractPublicationIdFromURLString = function (urlStr) {
535
- if (!urlStr) return
536
-
537
- const str = decodeURIComponent(urlStr)
538
-
539
- let term = {id: '', type: ''}
540
-
541
- const names = [
542
- 'doi.org/',
543
- 'nih.gov/pubmed/',
544
- 'pmc/articles/',
545
- 'pubmed.ncbi.nlm.nih.gov/',
546
- ]
547
-
548
- names.forEach((name) => {
549
- const lastIndex = str.lastIndexOf(name)
550
- if (lastIndex !== -1) {
551
- term.id = str.slice(lastIndex + name.length)
552
- if (name === 'doi.org/') {
553
- term.type = "doi"
554
- } else if (name === 'pmc/articles/') {
555
- term.type = "pmc"
556
- } else {
557
- term.type = "pmid"
558
- }
559
- }
560
- })
561
-
562
- //Backward compatability with doi: and PMID:
563
- if (term.id === '') {
564
- if (urlStr.includes("doi:")) {
565
- term.id = this.stripPMIDPrefix(urlStr)
566
- term.type = "doi"
567
- } else if (urlStr.includes("PMID:")) {
568
- term.id = this.stripPMIDPrefix(urlStr)
569
- term.type = "pmid"
570
- }
571
- }
572
-
573
- if (term.id.endsWith('/')) {
574
- term.id = term.id.slice(0, -1)
575
- }
576
-
577
- return term
578
- }
579
-
580
- this.getURLsForPubMed = function (data) {
581
- return new Promise((resolve) => {
582
- const ids = data.map((id) =>
583
- (typeof id === 'object') ?
584
- this.extractPublicationIdFromURLString(id[0]) :
585
- this.extractPublicationIdFromURLString(id)
586
- )
587
- this.convertPublicationIds(ids).then((pmids) => {
588
- if (pmids.length > 0) {
589
- const transformedIDs = pmids.join()
590
- resolve([this.pubmedSearchUrl(transformedIDs)])
591
- } else {
592
- resolve([])
593
- }
594
- })
595
- })
596
- }
597
-
598
466
  this.buildPubmedSqlStatement = function (keastIds) {
599
467
  let sql = 'select distinct publication from publications where entity in ('
600
468
  if (keastIds.length === 1) {
@@ -625,64 +493,6 @@ let FlatmapQueries = function () {
625
493
  console.error('Error:', error)
626
494
  })
627
495
  }
628
- // Note that this functin WILL run to the end, as it doesn not catch the second level of promises
629
- this.pubmedQueryOnIds = function (eventData) {
630
- return new Promise((resolve) => {
631
- const keastIds = eventData.resource
632
- const source = eventData.feature.source
633
- if (!keastIds || keastIds.length === 0) return
634
- const sql = this.buildPubmedSqlStatement(keastIds)
635
- this.flatmapQuery(sql).then((data) => {
636
- // Create pubmed url on paths if we have them
637
- if (data.values.length > 0) {
638
- this.getURLsForPubMed(data.values).then((urls) => {
639
- this.urls = urls
640
- if (urls.length) {
641
- resolve(true)
642
- } else {
643
- resolve(false)
644
- }
645
- })
646
- .catch(() => {
647
- this.urls = []
648
- resolve(false)
649
- })
650
- } else {
651
- // Create pubmed url on models
652
- this.pubmedQueryOnModels(source).then((result) => {
653
- resolve(result)
654
- })
655
- }
656
- })
657
- })
658
- }
659
-
660
- this.pubmedQueryOnModels = function (source) {
661
- return this.flatmapQuery(
662
- this.buildPubmedSqlStatementForModels(source)
663
- ).then((data) => {
664
- if (Array.isArray(data.values) && data.values.length > 0) {
665
- this.getURLsForPubMed(data.values).then((urls) => {
666
- this.urls = urls
667
- return true
668
- })
669
- .catch(() => {
670
- this.urls = []
671
- return false
672
- })
673
- } else {
674
- this.urls = [] // Clears the pubmed search button
675
- }
676
- return false
677
- })
678
- }
679
-
680
- this.pubmedSearchUrl = function (ids) {
681
- let url = 'https://pubmed.ncbi.nlm.nih.gov/?'
682
- let params = new URLSearchParams()
683
- params.append('term', ids)
684
- return url + params.toString()
685
- }
686
496
  }
687
497
 
688
498
  export { FlatmapQueries, findTaxonomyLabel, findTaxonomyLabels }