gpt4 book ai didi

python - 错误:函数 Input_stream::Input_stream(const string&, bool) 第 63 行。打开文件 @HWI-M02942_file1.fasta 时出错

转载 作者:太空宇宙 更新时间:2023-11-03 17:45:55 24 4
gpt4 key购买 nike

我正在编写一个 Python 脚本,通过使用 BLAST 程序 DIAMOND 自动执行 BLAST。该脚本在Ubuntu 14.04的终端中执行命令。

我的Python脚本是:

import subprocess

data_location = "/home/markschuurman/Desktop/Onderzoek_BioCentre/data_course_4/"
input_fasta_file = "@HWI-M02942_file1.fasta"
diamond_temp_dir = "/home/markschuurman/Desktop/DIAMOND_temp_dir/"
diamond_blast_database_location = "/home/markschuurman/Desktop/Onderzoek_BioCentre/BLAST_with_DIAMOND/DIAMOND_BLAST_databases/"
diamond_blast_output_file_directory = "/home/markschuurman/Desktop/Onderzoek_BioCentre/BLAST_with_DIAMOND/output_files/"
diamond_blast_output_filemame_daa = "matches.daa"
diamond_blast_output_filemame_tsv = "matches.tsv"

max_hits_per_read = "5"
max_evalue = "10"

commands = ["cd " + data_location,
"diamond blastx -d " + diamond_blast_database_location + "tcdb -q " + input_fasta_file + " -a " + diamond_blast_output_file_directory + diamond_blast_output_filemame_daa + " -t " + diamond_temp_dir + " -k " + max_hits_per_read + " -e " + max_evalue,
"diamond view -a " + diamond_blast_output_file_directory + diamond_blast_output_filemame_daa + " -o " + diamond_blast_output_file_directory + diamond_blast_output_filemame_tsv]

for command in commands:

print "Command : " + command
p = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True)

p_status = p.wait()

print "Command finished"

脚本在将正确的文件路径和文件名分配给变量后创建要执行的命令。

当我尝试运行此脚本时,出现以下错误:

/usr/bin/python2.7 /home/markschuurman/Desktop/Onderzoek_BioCentre/BLAST_with_DIAMOND/scripts_to_parse_DIAMOND_output/execute_DIAMOND_BLAST.py
Command : cd /home/markschuurman/Desktop/Onderzoek_BioCentre/data_course_4/
Command finished
Command : diamond blastx -d /home/markschuurman/Desktop/Onderzoek_BioCentre/BLAST_with_DIAMOND/DIAMOND_BLAST_databases/tcdb -q @HWI-M02942_file1.fasta -a /home/markschuurman/Desktop/Onderzoek_BioCentre/BLAST_with_DIAMOND/output_files/matches.daa -t /home/markschuurman/Desktop/DIAMOND_temp_dir/ -k 5 -e 10
Error: function Input_stream::Input_stream(const string&, bool) line 63. Error opening file @HWI-M02942_file1.fasta
Command finished
Command : diamond view -a /home/markschuurman/Desktop/Onderzoek_BioCentre/BLAST_with_DIAMOND/output_files/matches.daa -o /home/markschuurman/Desktop/Onderzoek_BioCentre/BLAST_with_DIAMOND/output_files/matches.tsv
Error: function Input_stream::Input_stream(const string&, bool) line 75. Error opening file /home/markschuurman/Desktop/Onderzoek_BioCentre/BLAST_with_DIAMOND/output_files/matches.daa
Command finished

我确信命令是正确的,因为当我在终端中单独执行第 20 行中打印的命令时,没有错误,并且 BLAST 应用程序的输出是正确的。

为什么在执行此 Python 脚本中的命令时而不是在终端中单独执行命令时会出现此错误?如何解决此错误?

最佳答案

这里的问题是 subprocess.Popen() 在单独的进程中运行命令,该进程在命令完成运行后退出。 cd 命令和 diamond 命令在单独的进程中运行。

这意味着 diamond 正在您运行命令的目录中查找 @HWI-M02942_file1.fasta

在这里简单使用绝对路径的解决方案可能是最简单的。

关于python - 错误:函数 Input_stream::Input_stream(const string&, bool) 第 63 行。打开文件 @HWI-M02942_file1.fasta 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29797851/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com