skip to Main Content

I’m working in a project that requires the use 4 software’s. 1 call PRIME that use MixMHCpred and the other 3 netMHCpan, nectchop and netMCHstab.
I run the terminal command for each of then (I’m working in Linux) and the program’s run with no problems. But now I’m traying to run them from a python script (I’m using visual code studio) and it doesn’t work, i trait with os.system and subprocess and it doesn’t work, I’ve trait to run a bash script with just the command and it just work in the terminal, not from the python script. The only output i get is "x command doesn’t exist", the software’s were install in the base env and using path, I’m using the python 3.11.8 kernel.
I’m working pandas, pysam and other python libraries, so changing the code to bash doesn’t sound appealing to me.

I used os.system and subprocess to run the commands, again this ones work fine in the terminal or from bash commands. Im expecting that the command run okay and give the output file to get data i need
Heres what im traying to do:

def netMHC(seqs:list[str], haplotypes:list[str]):
    haplotypes_str = ",".join(haplotypes)
    input_path = make_input_file(seqs, "NetMHCpan")
    
    xls_path = '../test/NetMHCpan_out.xls'  # Reemplaza esto con la ruta correcta
    os.system(f"netMHCpan -p {input_path} -a {haplotypes_str} -BA -inptype 1 -xls -xlsfile {xls_path}")

the warning
../test/net.sh: línea 3: netMHCpan: orden no encontrada.
"orden no encontrada" means order doesn’t found

And when I’m traying to use subprocess:

import subprocess
def net_chop(neo_ext, len_mer):
    input_path = make_input_file(neo_ext, "chop")
    command = f"netchop ../test/{input_path} > ../test/chop.txt"
    subprocess.run(command, shell=True)
    with open("../test/chop.txt", "r") as f:
        for l in f.readlines():
            if l.split("t")[0] == (len_mer):
                return float(l.split("t")[3])
    print("file vacio")

the warning
línea 1: netchop: orden no encontrada

2

Answers


  1. oren no encontrad: this means the COMMAND not found, hence netchop: netMHCpan: were not found to execute… perhaps the envioment context is different whe issuing the command fro python and runnig from the terminal??

    Login or Signup to reply.
  2. As you are using relative paths, you should be sure the command is executed from where you think it should be, other than using absolute path for the command

    command = ["/path/to/netchop", f"../test/{input_path}"]
    p = subprocess.run(command, cwd="/the/dir/i/want", capture_output=True)
    p.stdout # contains the output, save it
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search