Skip to content
Snippets Groups Projects
Commit 5b3d4e29 authored by Le, Mia's avatar Le, Mia
Browse files

added debug option to algorithms

parent 023f772d
No related branches found
No related tags found
No related merge requests found
...@@ -38,10 +38,10 @@ class AlgorithmWrapper(object): ...@@ -38,10 +38,10 @@ class AlgorithmWrapper(object):
def create_tmp_output_dir(self, tmp_dir): def create_tmp_output_dir(self, tmp_dir):
out_dir = os.path.join(tmp_dir, self.name) out_dir = os.path.join(tmp_dir, self.name)
print(tmp_dir) #print(tmp_dir)
if not os.path.exists(out_dir): if not os.path.exists(out_dir):
os.mkdir(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 self.output_dir = out_dir
def name_file(self, kind, ending='txt'): def name_file(self, kind, ending='txt'):
......
...@@ -42,7 +42,7 @@ class DiamondWrapper(AlgorithmWrapper): ...@@ -42,7 +42,7 @@ class DiamondWrapper(AlgorithmWrapper):
command = f'{diamond} "{ppi}" "{seeds}" {nof_predictions} {self.alpha} "{algo_output}"' command = f'{diamond} "{ppi}" "{seeds}" {nof_predictions} {self.alpha} "{algo_output}"'
subprocess.call(command, shell=True, stdout=subprocess.PIPE) subprocess.call(command, shell=True, stdout=subprocess.PIPE)
assert os.path.exists(algo_output), f'DIAMOnD failed to save output to {algo_output}' 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) return self.extract_output(algo_output)
def prepare_input(self): def prepare_input(self):
......
...@@ -54,7 +54,7 @@ class DominoWrapper(AlgorithmWrapper): ...@@ -54,7 +54,7 @@ class DominoWrapper(AlgorithmWrapper):
command = f'mv "{algo_output}" "{os.path.join(self.output_dir, outputfilename)}"' command = f'mv "{algo_output}" "{os.path.join(self.output_dir, outputfilename)}"'
subprocess.call(command, shell=True, stdout=subprocess.PIPE) subprocess.call(command, shell=True, stdout=subprocess.PIPE)
algo_output = os.path.join(self.output_dir, outputfilename) 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) return self.extract_output(algo_output)
...@@ -64,8 +64,7 @@ class DominoWrapper(AlgorithmWrapper): ...@@ -64,8 +64,7 @@ class DominoWrapper(AlgorithmWrapper):
""" """
inputparams = [] inputparams = []
# prepare inputfiles # prepare inputfiles
if self.debug: if self.debug: print(f'creating {self.name} input files in {self.output_dir}')
print(f'creating {self.name} input files in {self.output_dir}')
ppi_filename = self.name_file('ppi', 'sif') ppi_filename = self.name_file('ppi', 'sif')
ppi_file = os.path.join(self.output_dir, ppi_filename) ppi_file = os.path.join(self.output_dir, ppi_filename)
...@@ -81,26 +80,23 @@ class DominoWrapper(AlgorithmWrapper): ...@@ -81,26 +80,23 @@ class DominoWrapper(AlgorithmWrapper):
file.write(f"{str(edge.source()) + '_'}\tppi\t{str(edge.target()) + '_'}\n") 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 # the nodes need to be appended by '_' so that pandas recognizes the vertices as strings
inputparams.append(ppi_file) 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: with open(seed_file, "w") as file:
file.write('#node\n') file.write('#node\n')
for seed in self.seeds: for seed in self.seeds:
file.write(f"{seed}_\n") file.write(f"{seed}_\n")
inputparams.append(seed_file) inputparams.append(seed_file)
if self.debug: if self.debug: print(f'{self.name} seeds are saved in {seed_file}')
print(f'{self.name} seeds are saved in {seed_file}')
slices_filename = self.name_file('slices') slices_filename = self.name_file('slices')
slices_output = os.path.join(self.output_dir, slices_filename) slices_output = os.path.join(self.output_dir, slices_filename)
if not os.path.exists(slices_output): if not os.path.exists(slices_output):
if self.debug: if self.debug: print('creating domino slices_file...')
print('creating domino slices_file...')
command = f'slicer --network_file "{ppi_file}" --output_file "{slices_output}"' command = f'slicer --network_file "{ppi_file}" --output_file "{slices_output}"'
subprocess.call(command, shell=True, stdout=subprocess.PIPE) subprocess.call(command, shell=True, stdout=subprocess.PIPE)
if self.debug: if self.debug: print(f'{self.name} slices are saved in {slices_output}')
print(f'{self.name} slices are saved in {slices_output}')
inputparams.append(slices_output) inputparams.append(slices_output)
return inputparams return inputparams
......
...@@ -58,7 +58,7 @@ class RobustWrapper(AlgorithmWrapper): ...@@ -58,7 +58,7 @@ class RobustWrapper(AlgorithmWrapper):
{self.initialFraction} {self.reductionFactor} \ {self.initialFraction} {self.reductionFactor} \
{self.numberSteinerTrees} {self.threshold}' {self.numberSteinerTrees} {self.threshold}'
subprocess.call(command, shell=True, stdout=subprocess.PIPE) 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) return self.extract_output(algo_output)
# inputparams = [] # inputparams = []
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment