Skip to content

Commit

Permalink
service.legacy: new arg for _request: extra_where; enzsub cal…
Browse files Browse the repository at this point in the history
…ls `_request`
  • Loading branch information
deeenes committed Feb 4, 2025
1 parent 3317c5c commit ffec2bd
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions omnipath_server/service/_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
import contextlib
import collections

from libpasteurize.fixes.fix_future_builtins import expression
from sqlalchemy import any_, or_, and_
from sqlalchemy import or_, and_, any_
from pypath_common import _misc, _settings
from pypath_common import _constants as _const
from sqlalchemy.orm import Query
Expand Down Expand Up @@ -120,7 +119,7 @@ class LegacyService:
'where_partners': {
'sides': ('enzyme', 'substrate'),
'operator': 'enzyme_substrate',
}
},
},
}
query_types = {
Expand Down Expand Up @@ -1544,6 +1543,7 @@ def _request(
self,
args: dict,
query_type: str,
extra_where: Iterable | None = None,
format: FORMATS | None = None,
header: bool | None = None,
postprocess: Callable[[tuple], tuple] | None = None,
Expand Down Expand Up @@ -1594,6 +1594,10 @@ def _request(

if query:

if extra_where:

query = query.filter(*extra_where)

result = self._execute(query, args)
colnames = [c.name for c in query.statement.selected_columns]

Expand Down Expand Up @@ -2057,20 +2061,23 @@ def enzsub(
args = locals()
args = self._clean_args(args)
args = self._array_args(args, 'enzsub')
query, bad_req = self._query(args, 'enzsub')
extra_where = self._where_partners('enzsub', args)

if expression := self._where_partners('enzsub', args):
query.filter(expression)
yield from self._request(
args,
query_type = 'enzsub',
extra_where = extra_where,
**kwargs,
)

# TODO: Query over enz/subs partners done, pending rest of arguments


def _where_partners(self, query_type, args):
'''
"""
Function to deal with filtering interactions by partners.
e.g. when source/target or enz/subs are provided in the query
'''
"""

sides = self.query_param[query_type]['where_partners']['sides']
query_op = self.query_param[query_type]['where_partners']['operator']
Expand Down

0 comments on commit ffec2bd

Please sign in to comment.