Skip to content

Commit

Permalink
load: getting ID types for foreign IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
deeenes committed Nov 14, 2024
1 parent 1c7b5d9 commit e975962
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
19 changes: 14 additions & 5 deletions omnipath_metabo/schema/_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from ._base import Base
from ._connection import Connection
from ..misc._tee import Tee
from .. import data as _data

_log("Hello from main module")

Expand Down Expand Up @@ -118,7 +119,7 @@ def __init__(self, resource, con):
self.session = con.session
self.con = con

def _set_resource(self, resource):
def _set_resource(self, resource: str | type):
if type(resource) is type:
resource = resource()
self.scheme = resource.scheme
Expand Down Expand Up @@ -146,9 +147,9 @@ def load(self):
with raw_con.cursor() as cursor:

query = """
INSERT INTO structures (name, smiles, inchi) VALUES %s
ON CONFLICT (smiles)
DO NOTHING;
INSERT INTO structures (name, smiles, inchi) VALUES %s
ON CONFLICT (smiles)
DO NOTHING;
"""
_log("loading insert statments for structures table")
cached_resource = Tee(
Expand Down Expand Up @@ -177,10 +178,11 @@ def load(self):
#vself.update_mol_column()

resource_key = resid[0][0]
self._resource_ids = resource_ids
_log('resource ids collected.')

insert_ids = (
(_id, strids[smiles], resource_key, i==0, _resource_id(resource_key, i-1))
(_id, strids[smiles], resource_key, i==0, self._id_type(resource_key, i-1))
for name, smiles, _ in (
r['structure'] for r in cached_resource.cached['struct']
)
Expand Down Expand Up @@ -255,3 +257,10 @@ def create(self) -> None:

create(self.con)


def _id_type(self, id_idx: int) -> int:

self.resource.name
self.resource.id_fields[id_idx]


2 changes: 1 addition & 1 deletion omnipath_metabo/schema/_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Identifier(Base):
ForeignKey('resources.id'),
nullable = False
)
authoritative = Column(Boolean)
authoritative = Column(Boolean)
id_type = Column(
Integer,
ForeignKey('resources.id'),
Expand Down

0 comments on commit e975962

Please sign in to comment.