From b12c2993673168aa3deda3e21ebd20f64b251b1f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Al=C3=A1n=20Mu=C3=B1oz?= <amuoz@ed.ac.uk>
Date: Tue, 3 Aug 2021 13:45:38 +0100
Subject: [PATCH] add multisignal prefixing

Former-commit-id: f281c871f4219d00f03a7476755e642f108b69bb
---
 core/processor.py | 33 +++++++++++++++++++++++++--------
 1 file changed, 25 insertions(+), 8 deletions(-)

diff --git a/core/processor.py b/core/processor.py
index 6673d60c..9c9dd0fc 100644
--- a/core/processor.py
+++ b/core/processor.py
@@ -67,9 +67,8 @@ class PostProcessor:
     @staticmethod
     def get_process(process):
         """
-        Get process from  folder ./processes
+        Dynamically import a process class from the 'processes' folder.
         """
-        print(__file__)
         return locate("postprocessor.core.processes." + process + "." + process)
 
     def run(self):
@@ -77,12 +76,30 @@ class PostProcessor:
         for name, ids in new_ids.items():
             self._writer.write(ids, "/postprocessing/cell_info/" + name)
         picks = self.picker.run(self._signal[self.processes["picker"][0]])
-        return picks
-        # for process, dataset, outpath in zip(
-        #     self.processes, self.datasets["processes"], self.outpaths
-        # ):
-        #     processed_result = process.run(self._signals.get_dataset(dataset))
-        #     self.writer.write(processed_result, dataset, outpath)
+        for process, datasets in self.processes.values():
+            for dataset in datasets:
+                if isinstance(dataset, list):  # multisignal process
+                    result = self.processes["process"].run(
+                        [self._signal[d] for d in dataset]
+                    )
+                    prefix = "".join(
+                        prefix + c[0]
+                        for c in takewhile(
+                            lambda x: all(x[0] == y for y in x), zip(*dataset)
+                        )
+                    )
+                    outpath = (
+                        prefix
+                        + "_".join(  # TODO check that it always finishes in '/'
+                            [d[len(prefix) :].replace("/", "_") for d in dataset]
+                        )
+                    )
+                elif isinstance(dataset, str):
+                    result = self.processes["process"].run(self._signal[dataset])
+                    outpath = dataset[1:].replace("/", "_")
+                else:
+                    raise ("Not appropiate dataset")
+                self.writer.write(result, "/postprocessing/" + process + "/" + outpath)
 
 
 def _if_dict(item):
-- 
GitLab