Skip to content

Commit

Permalink
populated identifier table
Browse files Browse the repository at this point in the history
  • Loading branch information
for-hyde committed Oct 11, 2024
1 parent 5037f6d commit 3e85baf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
23 changes: 20 additions & 3 deletions omnipath_metabo/schema/_main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import collections
from sqlalchemy import text, select
from sqlalchemy.dialects.postgresql import insert

Expand Down Expand Up @@ -86,9 +87,25 @@ def load(self):
self.update_mol_column()

select_str_ids = text('SELECT id, smiles FROM structures')
self.session.execute(select_str_ids)

insert_ids = insert(_structure.Identifier).values(
strids = {
id[1]: id[0]
for id in self.session.execute(select_str_ids)
}

select_res_ids = text('SELECT id, name FROM resources')
resid= {
id[1]: id[0]
for id in self.session.execute(select_res_ids)
}
resource_key = resid[self.resource.name]
insert_ids = insert(_structure.Identifier).values([
{'identifier':id, 'structure_id': strids[smiles], 'resource_id': resource_key}
for smiles, _ids in ids.items()
for id in _ids
])
self.session.execute(insert_ids)
self.session.commit()


#self.indexer()

Expand Down
2 changes: 1 addition & 1 deletion omnipath_metabo/schema/_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Identifier(Base):
class Resource(Base):
__tablename__ = 'resources'
id = Column(Integer, primary_key=True)
name = Column(String)
name = Column(String, unique = True, nullable = False)
identifier = relationship('Identifier', backref='resource')


Expand Down

0 comments on commit 3e85baf

Please sign in to comment.