错误:函数Input_stream::Input_stream(const string&,bool)第63行。打开文件时出错@HWIM02942\u file1.fas

2024-06-08 16:34:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在编写一个Python脚本,使用BLAST程序DIAMOND自动执行BLAST。该脚本在ubuntu14.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脚本中的命令时会发生这个错误,而不是在terminal中单独发生,以及如何解决这个错误?你知道吗


Tags: 脚本homeoutputwithcommandfileblastdesktop
1条回答
网友
1楼 · 发布于 2024-06-08 16:34:29

问题是子流程.Popen()在单独的进程中运行命令,该进程在命令完成运行后退出。cd命令和diamond命令在不同的进程中运行。你知道吗

这意味着diamond正在运行命令的目录中查找@HWI-M02942_file1.fasta。你知道吗

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

相关问题 更多 >