Skip to content

Commit bcc441c

Browse files
committed
Add Query 27 to retrieve node mappings from SCKAN to map nodes (#42).
1 parent c9fbef6 commit bcc441c

1 file changed

Lines changed: 144 additions & 0 deletions

File tree

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
queries:
2+
- id: 27
3+
label: Node mapping from sckan to map
4+
sql: >
5+
WITH node_mappings AS (
6+
SELECT DISTINCT
7+
sckan.sckan_id,
8+
sckan.path_id,
9+
sckan.sckan_node_id,
10+
map.source_id,
11+
map.node_id
12+
FROM (
13+
SELECT
14+
source_id AS sckan_id,
15+
path_id,
16+
node_id AS sckan_node_id
17+
FROM path_nodes
18+
WHERE source_id IN (
19+
SELECT sckan_id
20+
FROM path_node_mappings
21+
WHERE %CONDITION_1%
22+
)
23+
AND %CONDITION_0%
24+
) AS sckan
25+
LEFT JOIN (
26+
SELECT
27+
source_id,
28+
path_id,
29+
node_id,
30+
sckan_id,
31+
sckan_node_id
32+
FROM path_node_mappings
33+
WHERE %CONDITION_1%
34+
AND %CONDITION_0%
35+
) AS map
36+
ON sckan.path_id = map.path_id
37+
AND sckan.sckan_node_id = map.sckan_node_id
38+
),
39+
40+
sckan_labels AS (
41+
SELECT
42+
nm.sckan_id,
43+
nm.sckan_node_id,
44+
string_agg(pt.label, ', ' ORDER BY seq.pos) AS sckan_label
45+
FROM node_mappings nm
46+
JOIN path_node_features pnf
47+
ON nm.sckan_id = pnf.source_id
48+
AND nm.path_id = pnf.path_id
49+
AND nm.sckan_node_id = pnf.node_id
50+
JOIN feature_terms pt
51+
ON pnf.source_id = pt.source_id
52+
AND pnf.feature_id = pt.term_id
53+
CROSS JOIN LATERAL (
54+
SELECT pos
55+
FROM (
56+
SELECT pnf.node_id::jsonb->>0 AS value, 1 AS pos
57+
UNION ALL
58+
SELECT value, ordinality + 1 AS pos
59+
FROM jsonb_array_elements_text(pnf.node_id::jsonb->1) WITH ORDINALITY
60+
) s
61+
WHERE s.value = pt.term_id
62+
) AS seq
63+
GROUP BY nm.sckan_id, nm.sckan_node_id
64+
),
65+
66+
map_labels AS (
67+
SELECT
68+
nm.source_id,
69+
nm.node_id,
70+
string_agg(pt.label, ', ' ORDER BY seq.pos) AS node_label
71+
FROM node_mappings nm
72+
JOIN path_node_features pnf
73+
ON nm.source_id = pnf.source_id
74+
AND nm.path_id = pnf.path_id
75+
AND nm.node_id = pnf.node_id
76+
JOIN feature_terms pt
77+
ON pnf.source_id = pt.source_id
78+
AND pnf.feature_id = pt.term_id
79+
CROSS JOIN LATERAL (
80+
SELECT pos
81+
FROM (
82+
SELECT pnf.node_id::jsonb->>0 AS value, 1 AS pos
83+
UNION ALL
84+
SELECT value, ordinality + 1 AS pos
85+
FROM jsonb_array_elements_text(pnf.node_id::jsonb->1) WITH ORDINALITY
86+
) s
87+
WHERE s.value = pt.term_id
88+
) AS seq
89+
GROUP BY nm.source_id, nm.node_id
90+
)
91+
92+
SELECT
93+
nm.sckan_id,
94+
nm.path_id,
95+
nm.sckan_node_id,
96+
sl.sckan_label,
97+
COALESCE(nm.source_id, '') AS source_id,
98+
COALESCE(nm.node_id, '') AS node_id,
99+
COALESCE(ml.node_label, '') AS node_label
100+
FROM node_mappings nm
101+
NATURAL JOIN sckan_labels sl
102+
LEFT JOIN map_labels ml
103+
ON nm.source_id = ml.source_id
104+
AND nm.node_id = ml.node_id;
105+
parameters:
106+
- id: path_id
107+
column: path_id
108+
label: Neuron population
109+
type: string
110+
multiple: true
111+
condition: CONDITION_0
112+
- id: source_id
113+
column: source_id
114+
label: Knowledge source
115+
type: string
116+
multiple: true
117+
condition: CONDITION_1
118+
default_msg: the latest source is used
119+
default_sql: >
120+
select source_id from knowledge_sources where source_id like 'sckan%'
121+
order by source_id desc limit 1
122+
order: ''
123+
results:
124+
- key: sckan_id
125+
label: SKCAN Knowledge source
126+
type: string
127+
- key: path_id
128+
label: Neuron population
129+
type: string
130+
- key: sckan_node_id
131+
label: SKCAN Node ID
132+
type: string
133+
- key: sckan_label
134+
label: SKCAN Node Label
135+
type: string
136+
- key: source_id
137+
label: Knowledge source
138+
type: string
139+
- key: node_id
140+
label: Map Node ID
141+
type: string
142+
- key: node_label
143+
label: Map Node Label
144+
type: string

0 commit comments

Comments
 (0)