用肌肉打电话或在管道中呼叫mafft时,子进程popen功能会锁定

发布于 2025-02-03 12:30:16 字数 820 浏览 3 评论 0原文

我正在尝试使用肌肉或MAFFT进行序列对齐,具体取决于用户在管道中。 为此,我正在使用subprocess软件包,但是有时,子过程永远不会终止,我的脚本不会继续。这是我调用子过程的方式:

child = subprocess.Popen(str(muscle_cline), stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
child.wait()

命令muscle_cline看起来像这样:

./tools/muscle/muscle5.1.win64.exe -align C:\Users\alexis\Desktop\git-repo\MitoSplitter\results\genes-fasta\12S_tmp.fasta -output C:\Users\alexis\Desktop\git-repo\MitoSplitter\results\alignement\12S_tmp_muscle_align.fasta

我在一个函数中调用此行,该函数仅创建命令行并调用子过程,并转换输出。

然后,我在循环的中调用此功能。

for file in getFastaFile(my_dir):
    alignSequenceWithMuscle(file)

问题是,出于未知原因,子过程永远不会完成并锁定...

我试图检查孩子的返回代码,或打印东西以查看它被锁定的位置,当我调用子过程时,它被锁定了。

有什么想法吗?

I'm trying to include sequence alignment using muscle or mafft, depending of the user in a pipeline.
To do so, i'm using the subprocess package, but sometimes, the subprocess never terminates and my script doesn't continue. Here is how I call the subprocess:

child = subprocess.Popen(str(muscle_cline), stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
child.wait()

The command muscle_cline looks like this:

./tools/muscle/muscle5.1.win64.exe -align C:\Users\alexis\Desktop\git-repo\MitoSplitter\results\genes-fasta\12S_tmp.fasta -output C:\Users\alexis\Desktop\git-repo\MitoSplitter\results\alignement\12S_tmp_muscle_align.fasta

I'm calling this line in a function that just creates the command line and calls the subprocess, and converts the output.

I'm then calling this function in a for loop

for file in getFastaFile(my_dir):
    alignSequenceWithMuscle(file)

The issue is that sometimes, for unknown reasons, the subprocess never finishes and get locked...

I tried to check the returncode of the child, or print stuff to see where it gets locked, and it's getting locked when I'm calling the subprocess.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

标点 2025-02-10 12:30:16

您通常希望避免popen,尤其是如果您对其要求没有很好的了解。这就是为什么Python为您提供subprocess.check_output和其他高级功能的原因,这些功能负责管理管理子过程的挑剔。

output = subprocess.check_output(
    ["./tools/muscle/muscle5.1.win64.exe",
     "-align", r"C:\Users\alexis\Desktop\git-repo\MitoSplitter\results\genes-fasta\12S_tmp.fasta",
     "-output", r"C:\Users\alexis\Desktop\git-repo\MitoSplitter\results\alignement\12S_tmp_muscle_align.fasta"],
    text=True)

还要注意RAW字符串r“ ...”避免必须加倍反弹,而text = true关键字参数指示python隐式解释字节您从子过程中收到。

You generally want to avoid bare Popen, especially if you don't have a good understanding of its requirements. This is precisely why Python offers you subprocess.check_output and other higher-level functions which take care of the nitty-gritty of managing a subprocess.

output = subprocess.check_output(
    ["./tools/muscle/muscle5.1.win64.exe",
     "-align", r"C:\Users\alexis\Desktop\git-repo\MitoSplitter\results\genes-fasta\12S_tmp.fasta",
     "-output", r"C:\Users\alexis\Desktop\git-repo\MitoSplitter\results\alignement\12S_tmp_muscle_align.fasta"],
    text=True)

Notice also the raw strings r"..." to avoid having to double the backslashes, and the text=True keyword argument to instruct Python to implicitly decode the bytes you receive from the subprocess.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文