From d732a52f6a4ad30c0c56040d69d94c6583b06e42 Mon Sep 17 00:00:00 2001 From: deeenes Date: Fri, 23 Jun 2023 16:28:23 +0200 Subject: [PATCH] `server`: filter by dorothea levels or methods only records that are included in the result solely based on dorothea evidences --- pypath/omnipath/server/run.py | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/pypath/omnipath/server/run.py b/pypath/omnipath/server/run.py index 6dfd2ff03..8d4d5508d 100644 --- a/pypath/omnipath/server/run.py +++ b/pypath/omnipath/server/run.py @@ -2120,23 +2120,32 @@ def interactions( return self._serve_dataframe(tbl, req) - @staticmethod - def _dorothea_dataset_filter(tbl, args): + @classmethod + def _dataset_included(cls, dataset: str, args: dict) -> bool: + + return ( + dataset in args['datasets'] | + ( + not args['datasets'] and + cls.dataset2type.get(dataset, None) in args['types'] + ) + ) + + + @classmethod + def _dorothea_dataset_filter(cls, tbl: pd.DataFrame, args: dict): return ( - np.logical_not(tbl.dorothea) | ( # if the tf_target dataset is requested # we need to serve it including the parts which # don't fit the filters below - ( - ('tf_target' in args['datasets']) | - ( - (not args['datasets']) & - ('transcriptional' in args['types']) - ) - ) & + cls._dataset_included('tf_target', args) & tbl.tf_target + ) | + ( + cls._dataset_included('collectri', args) & + tbl.collectri ) )