Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions mapknowledge/competency/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, ))
Expand Down Expand Up @@ -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:
Expand Down
22 changes: 22 additions & 0 deletions sql/map-knowledge.schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);

--------------------------------------------------------------