|
| 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_node_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 | + UPPER(SUBSTRING(sl.sckan_node_label, 1, 1)) || |
| 97 | + SUBSTRING(sl.sckan_node_label, 2) AS sckan_node_label, |
| 98 | + COALESCE(nm.source_id, '') AS source_id, |
| 99 | + COALESCE(nm.node_id, '') AS node_id, |
| 100 | + COALESCE(UPPER(SUBSTRING(ml.node_label, 1, 1)) || |
| 101 | + SUBSTRING(ml.node_label, 2), '') AS node_label |
| 102 | + FROM node_mappings nm |
| 103 | + NATURAL JOIN sckan_labels sl |
| 104 | + LEFT JOIN map_labels ml |
| 105 | + ON nm.source_id = ml.source_id |
| 106 | + AND nm.node_id = ml.node_id; |
| 107 | + parameters: |
| 108 | + - id: path_id |
| 109 | + column: path_id |
| 110 | + label: Neuron population |
| 111 | + type: string |
| 112 | + multiple: true |
| 113 | + condition: CONDITION_0 |
| 114 | + - id: source_id |
| 115 | + column: source_id |
| 116 | + label: Knowledge source |
| 117 | + type: string |
| 118 | + multiple: true |
| 119 | + condition: CONDITION_1 |
| 120 | + default_msg: the latest source is used |
| 121 | + default_sql: > |
| 122 | + select source_id from knowledge_sources where source_id like 'sckan%' |
| 123 | + order by source_id desc limit 1 |
| 124 | + order: '' |
| 125 | + results: |
| 126 | + - key: sckan_id |
| 127 | + label: SKCAN Knowledge source |
| 128 | + type: string |
| 129 | + - key: path_id |
| 130 | + label: Neuron population |
| 131 | + type: string |
| 132 | + - key: sckan_node_id |
| 133 | + label: SKCAN Node ID |
| 134 | + type: string |
| 135 | + - key: sckan_node_label |
| 136 | + label: SKCAN Node Label |
| 137 | + type: string |
| 138 | + - key: source_id |
| 139 | + label: Knowledge source |
| 140 | + type: string |
| 141 | + - key: node_id |
| 142 | + label: Map Node ID |
| 143 | + type: string |
| 144 | + - key: node_label |
| 145 | + label: Map Node Label |
| 146 | + type: string |
0 commit comments