diff --git a/mapknowledge/competency/__init__.py b/mapknowledge/competency/__init__.py index a3e90ee..3e3d80e 100644 --- a/mapknowledge/competency/__init__.py +++ b/mapknowledge/competency/__init__.py @@ -133,6 +133,7 @@ def __delete_source_from_tables(self, cursor, source: KnowledgeSource): cursor.execute('DELETE FROM path_node_types WHERE source_id=%s', (source_id, )) cursor.execute('DELETE FROM path_phenotypes WHERE source_id=%s', (source_id, )) cursor.execute('DELETE FROM path_properties WHERE source_id=%s', (source_id, )) + cursor.execute('DELETE FROM path_node_mappings WHERE source_id=%s', (source_id, )) cursor.execute('DELETE FROM path_nodes WHERE source_id=%s', (source_id, )) cursor.execute('DELETE FROM feature_types WHERE source_id=%s', (source_id, )) cursor.execute('DELETE FROM feature_terms WHERE source_id=%s', (source_id, )) @@ -231,6 +232,12 @@ def __update_connectivity(self, cursor, knowledge: KnowledgeList, show_progress= cursor.execute('INSERT INTO path_properties (source_id, path_id, biological_sex, alert, disconnected) VALUES (%s, %s, %s, %s, %s)', (source_id, path_id, record.get('biologicalSex'), record.get('alert'), record.get('pathDisconnected', False))) + # Node mappings + node_mappings = [ (source_id, path_id, json.dumps(node), knowledge.source.sckan_id, json.dumps(sckan_node)) + for (node, sckan_node) in record.get('node-mappings', []) ] + cursor.executemany('INSERT INTO path_node_mappings (source_id, path_id, node_id, sckan_id, sckan_node_id) VALUES (%s, %s, %s, %s, %s) ON CONFLICT DO NOTHING', + node_mappings) + if progress_bar is not None: progress_bar.update(1) if progress_bar is not None: diff --git a/sql/map-knowledge.schema.sql b/sql/map-knowledge.schema.sql index 870475f..bad6ca1 100644 --- a/sql/map-knowledge.schema.sql +++ b/sql/map-knowledge.schema.sql @@ -157,6 +157,15 @@ CREATE TABLE public.taxons ( ); ALTER TABLE public.taxons OWNER TO abi; +CREATE TABLE public.path_node_mappings ( + source_id character varying NOT NULL, + path_id character varying NOT NULL, + node_id character varying NOT NULL, + sckan_id character varying, + sckan_node_id character varying +); +ALTER TABLE public.path_node_mappings OWNER TO abi; + -------------------------------------------------------------- ALTER TABLE ONLY public.anatomical_types @@ -287,4 +296,17 @@ ALTER TABLE ONLY public.feature_types ALTER TABLE ONLY public.feature_types ADD CONSTRAINT type_constraint FOREIGN KEY (type_id) REFERENCES public.anatomical_types(type_id); +ALTER TABLE ONLY public.path_node_mappings + ADD CONSTRAINT source_constraint FOREIGN KEY (source_id) REFERENCES public.knowledge_sources(source_id); +ALTER TABLE ONLY public.path_node_mappings + ADD CONSTRAINT path_constraint FOREIGN KEY (source_id, path_id) REFERENCES public.feature_terms(source_id, term_id); +ALTER TABLE ONLY public.path_node_mappings + ADD CONSTRAINT node_constraint FOREIGN KEY (source_id, path_id, node_id) REFERENCES public.path_nodes(source_id, path_id, node_id); +ALTER TABLE ONLY public.path_node_mappings + ADD CONSTRAINT sckan_constraint FOREIGN KEY (sckan_id) REFERENCES public.knowledge_sources(source_id); +ALTER TABLE ONLY public.path_node_mappings + ADD CONSTRAINT sckan_path_constraint FOREIGN KEY (sckan_id, path_id) REFERENCES public.feature_terms(source_id, term_id); +ALTER TABLE ONLY public.path_node_mappings + ADD CONSTRAINT sckan_node_constraint FOREIGN KEY (sckan_id, path_id, node_id) REFERENCES public.path_nodes(source_id, path_id, node_id); + --------------------------------------------------------------