diff --git a/tests/__pycache__/testReadInput.cpython-310.pyc b/tests/__pycache__/testReadInput.cpython-310.pyc index c11c469..c92a459 100644 Binary files a/tests/__pycache__/testReadInput.cpython-310.pyc and b/tests/__pycache__/testReadInput.cpython-310.pyc differ diff --git a/tests/testReadInput.py b/tests/testReadInput.py index 6ff9cc1..3d57629 100644 --- a/tests/testReadInput.py +++ b/tests/testReadInput.py @@ -209,8 +209,8 @@ def test_process_filenames(self): tree_name = "tests/testFiles/test_tree" #Test process with new directories, no backup, ensure folders created - processed_output = self.input_reader.process_filenames(tree_name + ".txt", False) - correct_output = (self.test_file_path + "/slimScripts/test_tree", self.test_file_path + "/test_tree", None) + processed_output = self.input_reader.process_filenames(tree_name + ".txt", False, False) + correct_output = [self.test_file_path + "/slimScripts/test_tree", self.test_file_path + "/test_tree", None, None] self.assertTrue(processed_output == correct_output) self.assertTrue(os.path.exists(self.test_file_path + "/slimScripts/")) self.assertTrue(os.path.exists(self.test_file_path + "/aa_FASTA/")) @@ -219,9 +219,9 @@ def test_process_filenames(self): #Test process with existing directories, no backup with mock.patch.object(builtins, 'input', lambda _: 'y'): with redirect_stdout(io.StringIO()) as sout: - processed_output2 = self.input_reader.process_filenames(tree_name + ".txt", False) + processed_output2 = self.input_reader.process_filenames(tree_name + ".txt", False, False) - sout_correct = sout.getvalue() == "using the same nuc_FASTA folder\nusing the same aa_FASTA folder\n" + sout_correct = sout.getvalue() == "using the same nuc_FASTA folder\nusing the same aa_FASTA folder\n" sout.close() correct = processed_output2 == correct_output and sout_correct assert correct @@ -233,8 +233,8 @@ def test_process_filenames(self): os.rmdir(self.test_file_path + "/nuc_FASTA/") #Test process with new directories, include backup, ensure folders created - processed_output3 = self.input_reader.process_filenames(tree_name + ".txt", True) - correct_output2 = (self.test_file_path + "/slimScripts/test_tree", self.test_file_path + "/test_tree", self.test_file_path + "/backupFiles") + processed_output3 = self.input_reader.process_filenames(tree_name + ".txt", True, False) + correct_output2 = [self.test_file_path + "/slimScripts/test_tree", self.test_file_path + "/test_tree", self.test_file_path + "/backupFiles", None] self.assertTrue(processed_output3 == correct_output2) self.assertTrue(os.path.exists(self.test_file_path + "/slimScripts/")) self.assertTrue(os.path.exists(self.test_file_path + "/aa_FASTA/")) @@ -242,15 +242,32 @@ def test_process_filenames(self): self.assertTrue(os.path.exists(self.test_file_path + "/backupFiles/")) + # Remove directories to test with a backup + os.rmdir(self.test_file_path + "/slimScripts/") + os.rmdir(self.test_file_path + "/aa_FASTA/") + os.rmdir(self.test_file_path + "/nuc_FASTA/") + # os.rmdir(self.test_file_path + "/backupFiles/") + + # Test process with new directories, include hpc, ensure folders created + processed_output5 = self.input_reader.process_filenames(tree_name + ".txt", False, True) + correct_output6 = [self.test_file_path + "/slimScripts/test_tree", self.test_file_path + "/test_tree", None, self.test_file_path + "/slurmOutput"] + self.assertTrue(processed_output3 == correct_output2) + self.assertTrue(os.path.exists(self.test_file_path + "/slimScripts/")) + self.assertTrue(os.path.exists(self.test_file_path + "/aa_FASTA/")) + self.assertTrue(os.path.exists(self.test_file_path + "/nuc_FASTA/")) + self.assertTrue(os.path.exists(self.test_file_path + "/slurmOutput/")) + + # Test process with existing directories, no backup with mock.patch.object(builtins, 'input', lambda _: 'y'): with redirect_stdout(io.StringIO()) as sout: - processed_output4 = self.input_reader.process_filenames(tree_name + ".txt", True) + processed_output4 = self.input_reader.process_filenames(tree_name + ".txt", True, True) - sout_correct = sout.getvalue() == "using the same nuc_FASTA folder\nusing the same aa_FASTA folder\nusing same backup folder\n" + sout_correct = sout.getvalue() == "using the same nuc_FASTA folder\nusing the same aa_FASTA folder\nusing same backup folder\nusing same slurm folder\n" sout_val = sout.getvalue() sout.close() - correct = processed_output4 == correct_output2 and sout_correct + correct = processed_output4 == [self.test_file_path + "/slimScripts/test_tree", + self.test_file_path + "/test_tree", self.test_file_path + "/backupFiles", self.test_file_path + "/slurmOutput"] and sout_correct assert correct # Remove directories @@ -258,6 +275,7 @@ def test_process_filenames(self): os.rmdir(self.test_file_path + "/aa_FASTA/") os.rmdir(self.test_file_path + "/nuc_FASTA/") os.rmdir(self.test_file_path + "/backupFiles/") + os.rmdir(self.test_file_path + "/slurmOutput/") def test_make_param_dict(self): @@ -300,7 +318,7 @@ def test_make_param_dict(self): def test_save_input(self): #Make parameter dict and file outputs - already tested param_dict = self.input_reader.make_param_dict(self.arguments) - param_dict["filenames"] = self.input_reader.process_filenames("tests/testFiles/test_tree.txt", False) + param_dict["filenames"] = self.input_reader.process_filenames("tests/testFiles/test_tree.txt", False, False) #Test default self.input_reader.save_input(param_dict) diff --git a/utils/__pycache__/readInput.cpython-310.pyc b/utils/__pycache__/readInput.cpython-310.pyc index e50d0d2..e6cca8d 100644 Binary files a/utils/__pycache__/readInput.cpython-310.pyc and b/utils/__pycache__/readInput.cpython-310.pyc differ diff --git a/utils/__pycache__/writeSLiMHPC.cpython-310.pyc b/utils/__pycache__/writeSLiMHPC.cpython-310.pyc index aa05fba..9fc5868 100644 Binary files a/utils/__pycache__/writeSLiMHPC.cpython-310.pyc and b/utils/__pycache__/writeSLiMHPC.cpython-310.pyc differ diff --git a/utils/readInput.py b/utils/readInput.py index 1849686..ed6bb17 100644 --- a/utils/readInput.py +++ b/utils/readInput.py @@ -14,7 +14,7 @@ def process_input(self): sys.exit(0) self.param_dict = self.make_param_dict(args) - self.param_dict["filenames"] = self.process_filenames(args.input_tree, args.backup) + self.param_dict["filenames"] = self.process_filenames(args.input_tree, args.backup, args.high_performance_computing) @@ -169,7 +169,7 @@ def check_arguments (self, arguments): #Read input tree to make output file names - def process_filenames(self, tree_name, backup): + def process_filenames(self, tree_name, backup, hpc): # Find where data needs to be output to, set up documents and folders accordingly accordingly output_file_start = os.getcwd() + '/' + tree_name.split('.')[0] @@ -202,12 +202,13 @@ def process_filenames(self, tree_name, backup): try: os.mkdir(aa_FASTA_files_directory) except OSError: - print("using the same aa_FASTA folder") + print("using the same aa_FASTA folder") #Set up where files will be output to output_filename = output_files_directory + "/" + split_starting_output[-1] + filenames = [output_filename, output_file_start, None, None] #Make backup folder if(backup): @@ -217,9 +218,19 @@ def process_filenames(self, tree_name, backup): except OSError: print("using same backup folder") - return((output_filename, output_file_start, backup_files_directory)) - else: - return((output_filename, output_file_start, None)) + filenames [2] = backup_files_directory + + #Make folder for output and err files + if(hpc): + slurm_directiory = "/".join(split_starting_output[0:(len(split_starting_output)-1)]) + "/slurmOutput" + try: + os.mkdir(slurm_directiory) + except OSError: + print("using same slurm folder") + filenames [3] = slurm_directiory + + + return filenames diff --git a/utils/writeSLiMHPC.py b/utils/writeSLiMHPC.py index 508ac8b..af12d58 100644 --- a/utils/writeSLiMHPC.py +++ b/utils/writeSLiMHPC.py @@ -61,8 +61,9 @@ def create_scripts(self, population_parameters): #Write out batch file to run slim script batch_file = open(self.start_params["filenames"][0] + "_" + pop_name + ".sh", "w") batch_file.write("#!/bin/sh\n\n#SBATCH -J SLiM_Simulation_" + pop_name + "\n#SBATCH -t " + population_parameters["time"] + - "\n#SBATCH -p " + population_parameters["partition"] + "\n#SBATCH -o " + pop_name + ".out\n#SBATCH -e " + pop_name + - ".err\n#SBATCH -n 1" + "\n\nslim \'" + self.start_params["filenames"][0] + "_" + pop_name +".slim\'") + "\n#SBATCH -p " + population_parameters["partition"] + "\n#SBATCH -o " + self.start_params["filenames"][3] + "/" + pop_name + ".out" + + "\n#SBATCH -e " + self.start_params["filenames"][3] + "/" + pop_name + ".err" + + "\n#SBATCH -n 1" + "\n\nslim \'" + self.start_params["filenames"][0] + "_" + pop_name +".slim\'") batch_file.close() #Open slim script