Skip to content

Commit

Permalink
Loader: retrieving inserted records from identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
deeenes committed Nov 1, 2024
1 parent 238bbe5 commit 51fcead
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
18 changes: 17 additions & 1 deletion omnipath_metabo/schema/_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ def load(self):
INSERT INTO structures (name, smiles) VALUES %s ON CONFLICT (smiles) DO nothing;
"""
_log("loading insert statments for structures table")
cached_resource = Tee(self.resource, struct = lambda x: x)
cached_resource = Tee(
self.resource,
struct = lambda x: x,
)
psycopg2.extras.execute_values(cursor, query, cached_resource, page_size = 1000)


Expand Down Expand Up @@ -155,6 +158,19 @@ def load(self):

raw_con.commit()
_log('identifiers inserted.')

_log("structures have been inserted, creating mol column")
return_ids = text(
"SELECT id, structure_id, identifier, resource_id, id_type "
f"FROM identifiers WHERE resource_id = {resid}")
strid_to_smile = {reversed(it) for it in strids.items()}
identifier_ids = {
rest: id
for id, *rest in self.session.execute(return_ids)
}
inserted_str = {
(strid_to_smile[s[1]], s[2], s[3], s[4])
for s in cached_resource.cached['struct'])
#self.indexer()
_log(f'Finished loading {self.resource.name}.', level = -1)

Expand Down
10 changes: 9 additions & 1 deletion omnipath_metabo/schema/_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,15 @@ class Identifier(Base):
)
authoritative = Column(Boolean)
id_type = Column(Integer, ForeignKey('resources.id'), nullable = False)
__table_args__ = (Index('identifers_unique','identifier', 'structure_id', 'resource_id', 'id_type', unique = True),)
__table_args__ = (
Index(
name = 'identifers_unique','identifier',
'structure_id',
'resource_id',
'id_type',
unique = True,
),
)



Expand Down

0 comments on commit 51fcead

Please sign in to comment.