@abi-software/map-utilities 1.6.1-beta.6 → 1.6.1-beta.8
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/dist/map-utilities.js +5245 -5132
- package/dist/map-utilities.umd.cjs +57 -57
- package/package.json +1 -1
- package/src/components/CompetencyQueries/CompetencyQueries.js +0 -6
- package/src/components/CompetencyQueries/flatmapQueries.js +37 -0
- package/src/components/CompetencyQueries/knowledgeQueries.js +151 -0
- package/src/components/index.js +2 -0
package/package.json
CHANGED
|
@@ -272,17 +272,14 @@ async function queryPathsByRoute({ flatmapAPI, knowledgeSource, origins, destina
|
|
|
272
272
|
{
|
|
273
273
|
column: 'source_feature_id',
|
|
274
274
|
value: originFeatureIds,
|
|
275
|
-
...(originFeatureIds.length === 0 && { negate: true })
|
|
276
275
|
},
|
|
277
276
|
{
|
|
278
277
|
column: 'via_feature_id',
|
|
279
278
|
value: viaFeatureIds,
|
|
280
|
-
...(viaFeatureIds.length === 0 && { negate: true })
|
|
281
279
|
},
|
|
282
280
|
{
|
|
283
281
|
column: 'dest_feature_id',
|
|
284
282
|
value: destinationFeatureIds,
|
|
285
|
-
...(destinationFeatureIds.length === 0 && { negate: true })
|
|
286
283
|
}
|
|
287
284
|
];
|
|
288
285
|
|
|
@@ -290,17 +287,14 @@ async function queryPathsByRoute({ flatmapAPI, knowledgeSource, origins, destina
|
|
|
290
287
|
{
|
|
291
288
|
column: 'source_node_id',
|
|
292
289
|
value: origins,
|
|
293
|
-
...(origins.length === 0 && { negate: true })
|
|
294
290
|
},
|
|
295
291
|
{
|
|
296
292
|
column: 'via_node_id',
|
|
297
293
|
value: vias,
|
|
298
|
-
...(vias.length === 0 && { negate: true })
|
|
299
294
|
},
|
|
300
295
|
{
|
|
301
296
|
column: 'dest_node_id',
|
|
302
297
|
value: destinations,
|
|
303
|
-
...(destinations.length === 0 && { negate: true })
|
|
304
298
|
}
|
|
305
299
|
];
|
|
306
300
|
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const CachedTaxonLabels = [];
|
|
2
|
+
|
|
3
|
+
async function findTaxonomyLabels (mapImp, taxonomies) {
|
|
4
|
+
const intersectionTaxonomies = taxonomies.filter((taxonomy) =>
|
|
5
|
+
CachedTaxonLabels.some((obj) => obj.taxon === taxonomy)
|
|
6
|
+
);
|
|
7
|
+
|
|
8
|
+
const foundCachedTaxonLabels = CachedTaxonLabels.filter((obj) =>
|
|
9
|
+
intersectionTaxonomies.includes(obj.taxon)
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
const leftoverTaxonomies = taxonomies.filter((taxonomy) =>
|
|
13
|
+
!intersectionTaxonomies.includes(taxonomy)
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
if (!leftoverTaxonomies.length) {
|
|
17
|
+
return foundCachedTaxonLabels;
|
|
18
|
+
} else {
|
|
19
|
+
const entityLabels = await mapImp.queryLabels(leftoverTaxonomies);
|
|
20
|
+
if (entityLabels.length) {
|
|
21
|
+
entityLabels.forEach((entityLabel) => {
|
|
22
|
+
let { entity: taxon, label } = entityLabel;
|
|
23
|
+
if (label === 'Mammalia') {
|
|
24
|
+
label = 'Mammalia not otherwise specified'
|
|
25
|
+
}
|
|
26
|
+
const item = { taxon, label };
|
|
27
|
+
foundCachedTaxonLabels.push(item);
|
|
28
|
+
CachedTaxonLabels.push(item);
|
|
29
|
+
});
|
|
30
|
+
return foundCachedTaxonLabels;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export {
|
|
36
|
+
findTaxonomyLabels,
|
|
37
|
+
}
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
// destinations = ilxtr:hasAxonPresynapticElementIn, ilxtr:hasAxonSensorySubcellularElementIn
|
|
3
3
|
// via = ilxtr:hasAxonLeadingToSensorySubcellularElementIn, ilxtr:hasAxonLocatedIn
|
|
4
4
|
|
|
5
|
+
import { findTaxonomyLabels } from "./flatmapQueries";
|
|
6
|
+
|
|
5
7
|
async function query(flatmapAPI, sql, params) {
|
|
6
8
|
const url = `${flatmapAPI}knowledge/query/`;
|
|
7
9
|
const query = { sql, params };
|
|
@@ -242,6 +244,154 @@ async function queryPathsByRouteFromKnowledge({ knowledge, origins, destinations
|
|
|
242
244
|
return results;
|
|
243
245
|
}
|
|
244
246
|
|
|
247
|
+
async function getFlatmapFilterOptions (flatmapAPI, mapImp, providedKnowledge, providedPathways) {
|
|
248
|
+
let filterOptions = [];
|
|
249
|
+
const connectionFilters = [];
|
|
250
|
+
|
|
251
|
+
if (mapImp) {
|
|
252
|
+
// get flatmap filters
|
|
253
|
+
if (mapImp && typeof mapImp.featureFilterRanges === 'function') {
|
|
254
|
+
const filterRanges = mapImp.featureFilterRanges();
|
|
255
|
+
for (const [key, value] of Object.entries(filterRanges)) {
|
|
256
|
+
let main = {
|
|
257
|
+
key: `flatmap.connectivity.${key}`,
|
|
258
|
+
label: "",
|
|
259
|
+
children: []
|
|
260
|
+
}
|
|
261
|
+
let children = []
|
|
262
|
+
if (key === "kind") {
|
|
263
|
+
main.label = "Pathways"
|
|
264
|
+
for (const facet of value) {
|
|
265
|
+
const pathway = providedPathways.find(path => path.type === facet)
|
|
266
|
+
if (pathway) {
|
|
267
|
+
children.push({
|
|
268
|
+
key: `${main.key}.${facet}`,
|
|
269
|
+
label: pathway.label,
|
|
270
|
+
colour: pathway.colour,
|
|
271
|
+
colourStyle: 'line',
|
|
272
|
+
dashed: pathway.dashed,
|
|
273
|
+
})
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
} else if (key === "taxons") {
|
|
277
|
+
main.label = "Studied in"
|
|
278
|
+
const entityLabels = await findTaxonomyLabels(mapImp, mapImp.taxonIdentifiers)
|
|
279
|
+
if (entityLabels.length) {
|
|
280
|
+
for (const facet of value) {
|
|
281
|
+
const taxon = entityLabels.find(p => p.taxon === facet)
|
|
282
|
+
if (taxon) {
|
|
283
|
+
children.push({
|
|
284
|
+
key: `${main.key}.${facet}`,
|
|
285
|
+
// space added at the end of label to make sure the display name will not be updated
|
|
286
|
+
// prevent sidebar searchfilter convertReadableLabel
|
|
287
|
+
label: `${taxon.label} `
|
|
288
|
+
})
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
} else if (key === "alert") {
|
|
293
|
+
main.label = "Alert"
|
|
294
|
+
for (const facet of ["with", "without"]) {
|
|
295
|
+
children.push({
|
|
296
|
+
key: `${main.key}.${facet}`,
|
|
297
|
+
label: `${facet} alerts`
|
|
298
|
+
})
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
main.children = children.sort((a, b) => a.label.localeCompare(b.label));
|
|
302
|
+
if (main.label && main.children.length) {
|
|
303
|
+
filterOptions.push(main)
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
const mapKnowledge = mapImp.pathways.paths;
|
|
309
|
+
const flatmapKnowledge = providedKnowledge.reduce((arr, knowledge) => {
|
|
310
|
+
const id = knowledge.id;
|
|
311
|
+
if (id) {
|
|
312
|
+
const mapKnowledgeObj = mapKnowledge[id];
|
|
313
|
+
if (mapKnowledgeObj && mapKnowledgeObj.connectivity && mapKnowledgeObj['node-phenotypes']) {
|
|
314
|
+
const mapConnectivity = mapKnowledgeObj.connectivity;
|
|
315
|
+
const mapNodePhenotypes = mapKnowledgeObj['node-phenotypes'];
|
|
316
|
+
// take only map connectivity
|
|
317
|
+
knowledge.connectivity = [...mapConnectivity];
|
|
318
|
+
for (let key in knowledge['node-phenotypes']) {
|
|
319
|
+
if (mapNodePhenotypes[key]) {
|
|
320
|
+
// take only map node-phenotypes
|
|
321
|
+
knowledge['node-phenotypes'][key] = [...mapNodePhenotypes[key]];
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
// to avoid mutation
|
|
325
|
+
arr.push(JSON.parse(JSON.stringify(knowledge)));
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
return arr;
|
|
329
|
+
}, []);
|
|
330
|
+
const knowledgeSource = mapImp.knowledgeSource;
|
|
331
|
+
const originItems = await extractOriginItems(flatmapAPI, knowledgeSource, flatmapKnowledge);
|
|
332
|
+
const viaItems = await extractViaItems(flatmapAPI, knowledgeSource, flatmapKnowledge);
|
|
333
|
+
const destinationItems = await extractDestinationItems(flatmapAPI, knowledgeSource, flatmapKnowledge);
|
|
334
|
+
|
|
335
|
+
const transformItem = (facet, item) => {
|
|
336
|
+
const key = JSON.stringify(item.key);
|
|
337
|
+
return {
|
|
338
|
+
key: `flatmap.connectivity.source.${facet}.${key}`,
|
|
339
|
+
label: item.label || key
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
for (const facet of ["origin", "via", "destination", "all"]) {
|
|
344
|
+
let childrenList = []
|
|
345
|
+
if (facet === 'origin') {
|
|
346
|
+
childrenList = originItems.map((item) => transformItem(facet, item));
|
|
347
|
+
} else if (facet === 'via') {
|
|
348
|
+
childrenList = viaItems.map((item) => transformItem(facet, item));
|
|
349
|
+
} else if (facet === 'destination') {
|
|
350
|
+
childrenList = destinationItems.map((item) => transformItem(facet, item));
|
|
351
|
+
} else {
|
|
352
|
+
// All is the combination of origin, via, destination
|
|
353
|
+
const allList = [
|
|
354
|
+
...originItems.map((item) => transformItem(facet, item)),
|
|
355
|
+
...viaItems.map((item) => transformItem(facet, item)),
|
|
356
|
+
...destinationItems.map((item) => transformItem(facet, item))
|
|
357
|
+
];
|
|
358
|
+
// Generate unique list since the same feature can be in origin, via, and destination
|
|
359
|
+
const seenKeys = new Set();
|
|
360
|
+
childrenList = allList.filter(item => {
|
|
361
|
+
if (seenKeys.has(item.key)) return false;
|
|
362
|
+
seenKeys.add(item.key);
|
|
363
|
+
return true;
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// Those without label but key should be below
|
|
368
|
+
childrenList = childrenList.sort((a, b) => {
|
|
369
|
+
const isAlpha = (str) => /^[a-zA-Z]/.test(str);
|
|
370
|
+
const aAlpha = isAlpha(a.label);
|
|
371
|
+
const bAlpha = isAlpha(b.label);
|
|
372
|
+
|
|
373
|
+
if (aAlpha && !bAlpha) return -1;
|
|
374
|
+
if (!aAlpha && bAlpha) return 1;
|
|
375
|
+
|
|
376
|
+
return a.label.localeCompare(b.label);
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
if (childrenList.length) {
|
|
380
|
+
connectionFilters.push({
|
|
381
|
+
key: `flatmap.connectivity.source.${facet}`,
|
|
382
|
+
label: facet,
|
|
383
|
+
children: childrenList,
|
|
384
|
+
})
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
if (connectionFilters.length) {
|
|
389
|
+
filterOptions.push(...connectionFilters)
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
return filterOptions;
|
|
393
|
+
}
|
|
394
|
+
|
|
245
395
|
export {
|
|
246
396
|
filterOrigins,
|
|
247
397
|
filterDestinations,
|
|
@@ -254,4 +404,5 @@ export {
|
|
|
254
404
|
findPathsByViaItem,
|
|
255
405
|
queryPathsByRouteFromKnowledge,
|
|
256
406
|
fetchLabels,
|
|
407
|
+
getFlatmapFilterOptions,
|
|
257
408
|
}
|
package/src/components/index.js
CHANGED
|
@@ -29,6 +29,7 @@ import {
|
|
|
29
29
|
findPathsByViaItem,
|
|
30
30
|
queryPathsByRouteFromKnowledge,
|
|
31
31
|
fetchLabels,
|
|
32
|
+
getFlatmapFilterOptions,
|
|
32
33
|
} from "./CompetencyQueries/knowledgeQueries.js";
|
|
33
34
|
|
|
34
35
|
export {
|
|
@@ -60,4 +61,5 @@ export {
|
|
|
60
61
|
findPathsByViaItem,
|
|
61
62
|
queryPathsByRouteFromKnowledge,
|
|
62
63
|
fetchLabels,
|
|
64
|
+
getFlatmapFilterOptions,
|
|
63
65
|
};
|