From 5b3d4e29e1b8428ed7485bdcbfbf70a5efadab44 Mon Sep 17 00:00:00 2001
From: bay9355 <mia.le@studium.uni-hamburg.de>
Date: Thu, 16 Mar 2023 22:27:20 +0100
Subject: [PATCH] added debug option to algorithms

---
 cami_src/algorithms/AlgorithmWrapper.py |  4 ++--
 cami_src/algorithms/DiamondWrapper.py   |  2 +-
 cami_src/algorithms/DominoWrapper.py    | 16 ++++++----------
 cami_src/algorithms/RobustWrapper.py    |  2 +-
 4 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/cami_src/algorithms/AlgorithmWrapper.py b/cami_src/algorithms/AlgorithmWrapper.py
index 6378fad..17de832 100644
--- a/cami_src/algorithms/AlgorithmWrapper.py
+++ b/cami_src/algorithms/AlgorithmWrapper.py
@@ -38,10 +38,10 @@ class AlgorithmWrapper(object):
 
     def create_tmp_output_dir(self, tmp_dir):
         out_dir = os.path.join(tmp_dir, self.name)
-        print(tmp_dir)
+        #print(tmp_dir)
         if not os.path.exists(out_dir):
             os.mkdir(out_dir)
-            print(f"created temporary directory for {self.name} named {out_dir}...")
+            if self.debug: print(f"created temporary directory for {self.name} named {out_dir}...")
         self.output_dir = out_dir
 
     def name_file(self, kind, ending='txt'):
diff --git a/cami_src/algorithms/DiamondWrapper.py b/cami_src/algorithms/DiamondWrapper.py
index 93ca932..ee61636 100644
--- a/cami_src/algorithms/DiamondWrapper.py
+++ b/cami_src/algorithms/DiamondWrapper.py
@@ -42,7 +42,7 @@ class DiamondWrapper(AlgorithmWrapper):
         command = f'{diamond} "{ppi}" "{seeds}" {nof_predictions} {self.alpha} "{algo_output}"'
         subprocess.call(command, shell=True, stdout=subprocess.PIPE)
         assert os.path.exists(algo_output), f'DIAMOnD failed to save output to {algo_output}'
-        print(f"DIAMOnD results saved in {algo_output}")
+        if self.debug: print(f"DIAMOnD results saved in {algo_output}")
         return self.extract_output(algo_output)
 
     def prepare_input(self):
diff --git a/cami_src/algorithms/DominoWrapper.py b/cami_src/algorithms/DominoWrapper.py
index d642ecf..34953a3 100644
--- a/cami_src/algorithms/DominoWrapper.py
+++ b/cami_src/algorithms/DominoWrapper.py
@@ -54,7 +54,7 @@ class DominoWrapper(AlgorithmWrapper):
         command = f'mv "{algo_output}" "{os.path.join(self.output_dir, outputfilename)}"'
         subprocess.call(command, shell=True, stdout=subprocess.PIPE)
         algo_output = os.path.join(self.output_dir, outputfilename)
-        print(f"{self.name} results saved in {algo_output}")
+        if self.debug: print(f"{self.name} results saved in {algo_output}")
 
         return self.extract_output(algo_output)
 
@@ -64,8 +64,7 @@ class DominoWrapper(AlgorithmWrapper):
         """
         inputparams = []
         # prepare inputfiles
-        if self.debug:
-            print(f'creating {self.name} input files in {self.output_dir}')
+        if self.debug: print(f'creating {self.name} input files in {self.output_dir}')
 
         ppi_filename = self.name_file('ppi', 'sif')
         ppi_file = os.path.join(self.output_dir, ppi_filename)
@@ -81,26 +80,23 @@ class DominoWrapper(AlgorithmWrapper):
                 file.write(f"{str(edge.source()) + '_'}\tppi\t{str(edge.target()) + '_'}\n")
                 # the nodes need to be appended by '_' so that pandas recognizes the vertices as strings
         inputparams.append(ppi_file)
-        print(f'{self.name} ppi is saved in {ppi_file}')
+        if self.debug: print(f'{self.name} ppi is saved in {ppi_file}')
 
         with open(seed_file, "w") as file:
             file.write('#node\n')
             for seed in self.seeds:
                 file.write(f"{seed}_\n")
         inputparams.append(seed_file)
-        if self.debug:
-            print(f'{self.name} seeds are saved in {seed_file}')
+        if self.debug: print(f'{self.name} seeds are saved in {seed_file}')
 
         slices_filename = self.name_file('slices')
         slices_output = os.path.join(self.output_dir, slices_filename)
 
         if not os.path.exists(slices_output):
-            if self.debug:
-                print('creating domino slices_file...')
+            if self.debug: print('creating domino slices_file...')
             command = f'slicer --network_file "{ppi_file}" --output_file "{slices_output}"'
             subprocess.call(command, shell=True, stdout=subprocess.PIPE)
-        if self.debug:
-            print(f'{self.name} slices are saved in {slices_output}')
+        if self.debug: print(f'{self.name} slices are saved in {slices_output}')
         inputparams.append(slices_output)
         return inputparams
 
diff --git a/cami_src/algorithms/RobustWrapper.py b/cami_src/algorithms/RobustWrapper.py
index 84d00ef..fb89b20 100755
--- a/cami_src/algorithms/RobustWrapper.py
+++ b/cami_src/algorithms/RobustWrapper.py
@@ -58,7 +58,7 @@ class RobustWrapper(AlgorithmWrapper):
             {self.initialFraction} {self.reductionFactor} \
             {self.numberSteinerTrees} {self.threshold}'
         subprocess.call(command, shell=True, stdout=subprocess.PIPE)
-        print(f"Robust results saved in {algo_output}")
+        if self.debug: print(f"Robust results saved in {algo_output}")
         return self.extract_output(algo_output)
 
         # inputparams = []
-- 
GitLab