SWORD2 icon indicating copy to clipboard operation
SWORD2 copied to clipboard

Adjust the tmp file directory in the script

Open conchaeloko opened this issue 2 years ago • 0 comments

Hi all,

Thanks for the tool, I find it very helpful for my research. I may have a question though. I tried running the program in parallel using multiprocess in python but it does not work well, I assume because of the tmp files (file_ca_coo.pdb ,file_proba_contact.mat,file_matrix_pu_contact.mtx and file_pu_delineation.mtx ) overwriting themselves and not allowing a single thread to go through. I have not looked into the script deeply yet but how simple would it be to add the option --tmp that would indicate where the tmp files would be created ?

In case my question is unclear, here is the script I submit on a cluster :

import os 
import subprocess
from multiprocessing.pool import ThreadPool

path_work = "/home/user/"
path_pdb = f"{path_work}/ficheros_28032023/out_minibatch"
path_out = f"{path_work}/ficheros_28032023/sword2_Minibatch"


def sword2_pred(pdb_file) :
    """
    This function makes a sword prediction from a pdb_file.
    It takes as an input a pdb file, and outputs swords2 files.     
    The path_out is to be adjusted to the context.
    """
    with open(f"{path_out}/sword2.log" ,"a+") as outfile :
        path_sword = "/home/user/software/SWORD2"
        name = pdb_file.split("/")[-1].split(".pdb")[0]
        sword_command = f" {path_sword}/SWORD2.py -i {pdb_file} -o {path_out}/{name} -x 5"
        sword_subprocess = subprocess.Popen (sword_command , shell = True, stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
        hmm_out, hmm_err = sword_subprocess.communicate()
        print(hmm_out)
        outfile.write(f"{name} is done.")
    
paths = [f"{path_pdb}/{file}" for file in os.listdir(path_pdb) if os.path.isdir(f"{path_out}/{file.split('.pdb')[0]}")==False]
    
if __name__ == '__main__':
    with ThreadPool(8) as p:
        p.map(sword2_pred, paths)

Thanks again ! Best

conchaeloko avatar May 03 '23 14:05 conchaeloko