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

标签 python bioinformatics blast

我正在编写一个 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/

相关文章:

java - 在 Java 中查找简单序列重复的有效方法

c++ - 从 van 文件中的第 m 个染色体中获取第 n 个读数

python - 使用 NcbiblastxCommandline 自定义 blast 数据库

bioinformatics - 是否可以将字符串变量而不是文件传递给 BLAST 搜索?

python - 如何在 SQLAlchemy 查询中获取列名?

Python 多处理池 : maxtasksperchild

python - PyCharm 中的垂直线是什么?

python - 我可以将 Json 反序列化为 Python 中的 C# Newtonsoft 类吗

python - 高效存储的字典。这个数据结构是否存在,它叫什么?

hadoop - getLocalCacheArchives 方法有什么作用?