@abi-software/flatmapvuer 1.5.4 → 1.5.6-beta.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abi-software/flatmapvuer",
3
- "version": "1.5.4",
3
+ "version": "1.5.6-beta.0",
4
4
  "license": "Apache-2.0",
5
5
  "files": [
6
6
  "dist/*",
@@ -43,8 +43,8 @@
43
43
  "./src/*": "./src/*"
44
44
  },
45
45
  "dependencies": {
46
- "@abi-software/flatmap-viewer": "3.1.9",
47
- "@abi-software/map-utilities": "^1.1.1",
46
+ "@abi-software/flatmap-viewer": "3.2.0",
47
+ "@abi-software/map-utilities": "^1.1.2",
48
48
  "@abi-software/sparc-annotation": "0.3.1",
49
49
  "@abi-software/svg-sprite": "^1.0.1",
50
50
  "@element-plus/icons-vue": "^2.3.1",
package/src/App.vue CHANGED
@@ -195,8 +195,12 @@ export default {
195
195
  .getCurrentFlatmap()
196
196
  .searchAndShowResult(this.searchText, true)
197
197
  },
198
- onFlatmapChanged: function () {
198
+ onFlatmapChanged: function (activeSpecies) {
199
199
  this.helpMode = false;
200
+ // Update current flatmapImp after changing species
201
+ if (this.$refs.multi.$refs[activeSpecies][0].mapImp) {
202
+ window.flatmapImp = this.$refs.multi.$refs[activeSpecies][0].mapImp;
203
+ }
200
204
  },
201
205
  onHelpModeShowNext: function () {
202
206
  this.helpModeActiveItem += 1;
@@ -658,7 +658,7 @@ import {
658
658
  import flatmapMarker from '../icons/flatmap-marker'
659
659
  import {
660
660
  FlatmapQueries,
661
- findTaxonomyLabel,
661
+ findTaxonomyLabels,
662
662
  } from '../services/flatmapQueries.js'
663
663
  import yellowstar from '../icons/yellowstar'
664
664
  import ResizeSensor from 'css-element-queries/src/ResizeSensor'
@@ -1179,12 +1179,13 @@ export default {
1179
1179
  */
1180
1180
  processTaxon: function (flatmapAPI, taxonIdentifiers) {
1181
1181
  this.taxonConnectivity.length = 0
1182
- taxonIdentifiers.forEach((taxon) => {
1183
- findTaxonomyLabel(flatmapAPI, taxon).then((value) => {
1184
- const item = { taxon, label: value }
1185
- this.taxonConnectivity.push(item)
1186
- })
1187
- })
1182
+ findTaxonomyLabels(this.mapImp, taxonIdentifiers).then((entityLabels) => {
1183
+ if (entityLabels.length) {
1184
+ entityLabels.forEach((entityLabel) => {
1185
+ this.taxonConnectivity.push(entityLabel);
1186
+ });
1187
+ }
1188
+ });
1188
1189
  },
1189
1190
  /**
1190
1191
  * @public
@@ -1270,7 +1271,7 @@ export default {
1270
1271
  * @arg {Object} `payload`
1271
1272
  */
1272
1273
  centreLinesSelected: function (payload) {
1273
- if (this.mapImp) {
1274
+ if (this.mapImp && this.mapImp.enableCentrelines) {
1274
1275
  this.mapImp.enableCentrelines(payload.value)
1275
1276
  }
1276
1277
  },
@@ -1314,7 +1315,7 @@ export default {
1314
1315
  let pathFeatures = paths.map((p) => this.mapImp.featureProperties(p))
1315
1316
 
1316
1317
  // Query the flatmap knowledge graph for connectivity, we use this to grab the origins
1317
- let connectivity = await this.flatmapQueries.queryForConnectivity(payload)
1318
+ let connectivity = await this.flatmapQueries.queryForConnectivityNew(this.mapImp, payload)
1318
1319
 
1319
1320
  // Check and flatten the origins node graph
1320
1321
  let originsFlat = connectivity?.ids?.dendrites?.flat().flat()
@@ -1758,7 +1759,7 @@ export default {
1758
1759
  }
1759
1760
  } else {
1760
1761
  let results =
1761
- await this.flatmapQueries.retrieveFlatmapKnowledgeForEvent(data)
1762
+ await this.flatmapQueries.retrieveFlatmapKnowledgeForEvent(this.mapImp, data)
1762
1763
  // The line below only creates the tooltip if some data was found on the path
1763
1764
  // result 0 is the connection, result 1 is the pubmed results from flatmap
1764
1765
  if (
@@ -1807,7 +1808,7 @@ export default {
1807
1808
  * @arg {Object} `data`
1808
1809
  */
1809
1810
  createTooltipFromNeuronCuration: async function (data) {
1810
- this.tooltipEntry = await this.flatmapQueries.createTooltipData(data)
1811
+ this.tooltipEntry = await this.flatmapQueries.createTooltipData(this.mapImp, data)
1811
1812
  this.displayTooltip(data.resource[0])
1812
1813
  },
1813
1814
  /**
@@ -2352,7 +2353,7 @@ export default {
2352
2353
  this.mapImp.setBackgroundOpacity(1)
2353
2354
  this.backgroundChangeCallback(this.currentBackground)
2354
2355
  this.pathways = this.mapImp.pathTypes()
2355
- if (!this.isCentreLine) {
2356
+ if (!this.isCentreLine && this.mapImp.enableCentrelines) {
2356
2357
  this.mapImp.enableCentrelines(false)
2357
2358
  }
2358
2359
  //Disable layers for now
@@ -8,6 +8,7 @@ const removeDuplicates = function (arrayOfAnything) {
8
8
  }
9
9
 
10
10
  const cachedLabels = {}
11
+ const cachedTaxonLabels = [];
11
12
 
12
13
  const findTaxonomyLabel = async function (flatmapAPI, taxonomy) {
13
14
  if (cachedLabels && cachedLabels.hasOwnProperty(taxonomy)) {
@@ -35,6 +36,38 @@ const findTaxonomyLabel = async function (flatmapAPI, taxonomy) {
35
36
  })
36
37
  }
37
38
 
39
+ const findTaxonomyLabels = async function (mapImp, taxonomies) {
40
+ const intersectionTaxonomies = taxonomies.filter((taxonomy) =>
41
+ cachedTaxonLabels.some((obj) => obj.taxon === taxonomy)
42
+ );
43
+
44
+ const foundCachedTaxonLabels = cachedTaxonLabels.filter((obj) =>
45
+ intersectionTaxonomies.includes(obj.taxon)
46
+ );
47
+
48
+ const leftoverTaxonomies = taxonomies.filter((taxonomy) =>
49
+ !intersectionTaxonomies.includes(taxonomy)
50
+ );
51
+
52
+ if (!leftoverTaxonomies.length) {
53
+ return foundCachedTaxonLabels;
54
+ } else {
55
+ const entityLabels = await mapImp.queryLabels(leftoverTaxonomies);
56
+ if (entityLabels.length) {
57
+ entityLabels.forEach((entityLabel) => {
58
+ let { entity: taxon, label } = entityLabel;
59
+ if (label === 'Mammalia') {
60
+ label = 'Mammalia not otherwise specified'
61
+ }
62
+ const item = { taxon, label };
63
+ foundCachedTaxonLabels.push(item);
64
+ cachedTaxonLabels.push(item);
65
+ });
66
+ return foundCachedTaxonLabels;
67
+ }
68
+ }
69
+ }
70
+
38
71
  const inArray = function (ar1, ar2) {
39
72
  if (!ar1 || !ar2) return false
40
73
  let as1 = JSON.stringify(ar1)
@@ -54,7 +87,7 @@ let FlatmapQueries = function () {
54
87
  this.lookUp = []
55
88
  }
56
89
 
57
- this.createTooltipData = async function (eventData) {
90
+ this.createTooltipData = async function (mapImp, eventData) {
58
91
  let hyperlinks = []
59
92
  if (
60
93
  eventData.feature.hyperlinks &&
@@ -67,13 +100,12 @@ let FlatmapQueries = function () {
67
100
  let taxonomyLabel = undefined
68
101
  if (eventData.provenanceTaxonomy) {
69
102
  taxonomyLabel = []
70
- for (let i = 0; eventData.provenanceTaxonomy.length > i; i++) {
71
- taxonomyLabel.push(
72
- await findTaxonomyLabel(
73
- this.flatmapAPI,
74
- eventData.provenanceTaxonomy[i]
75
- )
76
- )
103
+ const entityLabels = await findTaxonomyLabels(mapImp, eventData.provenanceTaxonomy);
104
+ if (entityLabels.length) {
105
+ entityLabels.forEach((entityLabel) => {
106
+ const { label } = entityLabel;
107
+ taxonomyLabel.push(label);
108
+ });
77
109
  }
78
110
  }
79
111
 
@@ -104,33 +136,22 @@ let FlatmapQueries = function () {
104
136
  return labelList
105
137
  }
106
138
 
107
- this.createLabelLookup = function (uberons) {
108
- return new Promise((resolve) => {
139
+ this.createLabelLookup = function (mapImp, uberons) {
140
+ return new Promise(async (resolve) => {
109
141
  let uberonMap = {}
110
142
  this.uberons = []
111
- const data = { sql: this.buildLabelSqlStatement(uberons) }
112
- fetch(`${this.flatmapApi}knowledge/query/`, {
113
- method: 'POST',
114
- headers: {
115
- 'Content-Type': 'application/json',
116
- },
117
- body: JSON.stringify(data),
118
- })
119
- .then((response) => response.json())
120
- .then((payload) => {
121
- const entity = payload.keys.indexOf('entity')
122
- const label = payload.keys.indexOf('label')
123
- if (entity > -1 && label > -1) {
124
- payload.values.forEach((pair) => {
125
- uberonMap[pair[entity]] = pair[label]
126
- this.uberons.push({
127
- id: pair[entity],
128
- name: pair[label],
129
- })
130
- })
131
- }
132
- resolve(uberonMap)
133
- })
143
+ const entityLabels = await findTaxonomyLabels(mapImp, uberons);
144
+ if (entityLabels.length) {
145
+ entityLabels.forEach((entityLabel) => {
146
+ const { taxon: entity, label } = entityLabel;
147
+ uberonMap[entity] = label;
148
+ this.uberons.push({
149
+ id: entity,
150
+ name: label,
151
+ })
152
+ });
153
+ resolve(uberonMap)
154
+ }
134
155
  })
135
156
  }
136
157
 
@@ -209,7 +230,7 @@ let FlatmapQueries = function () {
209
230
  return found
210
231
  }
211
232
 
212
- this.retrieveFlatmapKnowledgeForEvent = async function (eventData) {
233
+ this.retrieveFlatmapKnowledgeForEvent = async function (mapImp, eventData) {
213
234
  // check if there is an existing query
214
235
  if (this.controller) this.controller.abort()
215
236
 
@@ -221,15 +242,59 @@ let FlatmapQueries = function () {
221
242
  this.destinations = []
222
243
  this.origins = []
223
244
  this.components = []
245
+ this.urls = []
224
246
  if (!keastIds || keastIds.length == 0) return
225
247
 
226
- let prom1 = this.queryForConnectivity(keastIds, signal) // This on returns a promise so dont need 'await'
227
- let prom2 = await this.pubmedQueryOnIds(eventData)
228
- let results = await Promise.all([prom1, prom2])
248
+ let prom1 = this.queryForConnectivityNew(mapImp, keastIds, signal) // This on returns a promise so dont need 'await'
249
+ // let prom2 = await this.pubmedQueryOnIds(eventData)
250
+ let results = await Promise.all([prom1])
229
251
  return results
230
252
  }
231
253
 
232
- this.queryForConnectivity = function (keastIds, signal, processConnectivity=true) {
254
+ this.queryForConnectivityNew = function (mapImp, keastIds, signal, processConnectivity=true) {
255
+ return new Promise((resolve) => {
256
+ mapImp.queryKnowledge(keastIds[0])
257
+ .then((response) => {
258
+ if (this.checkConnectivityExists(response)) {
259
+ let connectivity = response;
260
+ if (processConnectivity) {
261
+ this.processConnectivity(mapImp, connectivity).then((processedConnectivity) => {
262
+ // response.references is publication urls
263
+ // same data as mapImp.queryPublications(keastIds[0]) method
264
+ if (response.references) {
265
+ // with publications
266
+ this.getURLsForPubMed(response.references).then((urls) => {
267
+ // TODO: if empty urls array is returned,
268
+ // the urls are not on PubMed.
269
+ // Those urls, response.references, will be shown in another way.
270
+ this.urls = urls;
271
+ resolve(processedConnectivity)
272
+ })
273
+ } else {
274
+ // without publications
275
+ resolve(processedConnectivity)
276
+ }
277
+ })
278
+ }
279
+ else resolve(connectivity)
280
+ } else {
281
+ resolve(false)
282
+ }
283
+ })
284
+ .catch((error) => {
285
+ if (error.name === 'AbortError') {
286
+ // This error is from AbortController's abort method.
287
+ } else {
288
+ // console.error('Error:', error)
289
+ // TODO: to update after queryKnowledge method update
290
+ console.warn(`Unable to get the knowledge for the entity ${keastIds[0]}.`)
291
+ }
292
+ resolve(false)
293
+ })
294
+ })
295
+ }
296
+
297
+ this.queryForConnectivity = function (mapImp, keastIds, signal, processConnectivity=true) {
233
298
  const data = { sql: this.buildConnectivitySqlStatement(keastIds) }
234
299
  const headers = {
235
300
  method: 'POST',
@@ -246,7 +311,7 @@ let FlatmapQueries = function () {
246
311
  if (this.connectivityExists(data)) {
247
312
  let connectivity = JSON.parse(data.values[0][0])
248
313
  if (processConnectivity) {
249
- this.processConnectivity(connectivity).then((processedConnectivity) => {
314
+ this.processConnectivity(mapImp, connectivity).then((processedConnectivity) => {
250
315
  resolve(processedConnectivity)
251
316
  })
252
317
  }
@@ -266,6 +331,10 @@ let FlatmapQueries = function () {
266
331
  })
267
332
  }
268
333
 
334
+ this.checkConnectivityExists = function (data) {
335
+ return data && data.connectivity?.length;
336
+ };
337
+
269
338
  this.connectivityExists = function (data) {
270
339
  if (
271
340
  data.values &&
@@ -336,7 +405,7 @@ let FlatmapQueries = function () {
336
405
  )
337
406
  }
338
407
 
339
- this.processConnectivity = function (connectivity) {
408
+ this.processConnectivity = function (mapImp, connectivity) {
340
409
  return new Promise((resolve) => {
341
410
  // Filter the origin and destinations from components
342
411
  let components = this.findComponents(connectivity)
@@ -349,7 +418,7 @@ let FlatmapQueries = function () {
349
418
  let conIds = this.findAllIdsFromConnectivity(connectivity)
350
419
 
351
420
  // Create readable labels from the nodes. Setting this to 'this.origins' updates the display
352
- this.createLabelLookup(conIds).then((lookUp) => {
421
+ this.createLabelLookup(mapImp, conIds).then((lookUp) => {
353
422
  this.destinations = axons.map((a) =>
354
423
  this.createLabelFromNeuralNode(a, lookUp)
355
424
  )
@@ -393,7 +462,7 @@ let FlatmapQueries = function () {
393
462
  this.stripPMIDPrefix = function (pubmedId) {
394
463
  return pubmedId.split(':')[1]
395
464
  }
396
-
465
+
397
466
  this.getPMID = function(idsList) {
398
467
  return new Promise((resolve) => {
399
468
  if (idsList.length > 0) {
@@ -419,7 +488,7 @@ let FlatmapQueries = function () {
419
488
  })
420
489
  promises.push(promise)
421
490
  })
422
-
491
+
423
492
  Promise.all(promises).then(() => {
424
493
  resolve(results)
425
494
  }).catch(() => {
@@ -450,7 +519,7 @@ let FlatmapQueries = function () {
450
519
  resolve(pmids)
451
520
  })
452
521
  })
453
- }
522
+ }
454
523
 
455
524
  this.extractPublicationIdFromURLString = function (urlStr) {
456
525
  if (!urlStr) return
@@ -500,11 +569,18 @@ let FlatmapQueries = function () {
500
569
 
501
570
  this.getURLsForPubMed = function (data) {
502
571
  return new Promise((resolve) => {
503
- const ids = data.values.map((id) => this.extractPublicationIdFromURLString(id[0]))
572
+ const ids = data.map((id) =>
573
+ (typeof id === 'object') ?
574
+ this.extractPublicationIdFromURLString(id[0]) :
575
+ this.extractPublicationIdFromURLString(id)
576
+ )
504
577
  this.convertPublicationIds(ids).then((pmids) => {
505
578
  if (pmids.length > 0) {
506
579
  const transformedIDs = pmids.join()
507
580
  resolve([this.pubmedSearchUrl(transformedIDs)])
581
+ } else {
582
+ // return empty array for non-pubmed urls
583
+ resolve(pmids)
508
584
  }
509
585
  })
510
586
  })
@@ -550,7 +626,7 @@ let FlatmapQueries = function () {
550
626
  this.flatmapQuery(sql).then((data) => {
551
627
  // Create pubmed url on paths if we have them
552
628
  if (data.values.length > 0) {
553
- this.getURLsForPubMed(data).then((urls) => {
629
+ this.getURLsForPubMed(data.values).then((urls) => {
554
630
  this.urls = urls
555
631
  resolve(true)
556
632
  })
@@ -573,7 +649,7 @@ let FlatmapQueries = function () {
573
649
  this.buildPubmedSqlStatementForModels(source)
574
650
  ).then((data) => {
575
651
  if (Array.isArray(data.values) && data.values.length > 0) {
576
- this.getURLsForPubMed(data).then((urls) => {
652
+ this.getURLsForPubMed(data.values).then((urls) => {
577
653
  this.urls = urls
578
654
  return true
579
655
  })
@@ -596,4 +672,4 @@ let FlatmapQueries = function () {
596
672
  }
597
673
  }
598
674
 
599
- export { FlatmapQueries, findTaxonomyLabel }
675
+ export { FlatmapQueries, findTaxonomyLabel, findTaxonomyLabels }