使用python发现文件未找到错误

时间:2013-11-12 18:28:52

标签: python bioinformatics biopython

我想使用MafftCommandline来对齐我的数据,但我收到以下错误:

Traceback (most recent call last):


 File "C:\Users\Rimvis\Desktop\asd\bioinformatika2_Working.py", line 35, in <mo
dule>
    stdout, stderr = mafftCline()  # Note that MAFFT will write the alignment to
 stdout, which you may want to save to a file and then parse
  File "C:\Python27\lib\site-packages\Bio\Application\__init__.py", line 475, in
 __call__
    shell=(sys.platform!="win32"))
  File "C:\Python27\lib\subprocess.py", line 679, in __init__
    errread, errwrite)
  File "C:\Python27\lib\subprocess.py", line 896, in _execute_child
    startupinfo)
WindowsError: [Error 2] The system cannot find the file specified

我的代码如下:

dataToProcess = "dataToProcess.fa"
file = open(dataToProcess, "w")

arrayOfSequences = []
for sequence in blast.alignments:
    if sequence.length > blast.alignments[0].length * 80 / 100:
        sequenceToAppend = SeqRecord(Seq(sequence.hsps[0].sbjct), id=sequence.title)
        arrayOfSequences.append(sequenceToAppend)
SeqIO.write(arrayOfSequences, file, "fasta")
file.close()

maffPath = "..\mafft-win\mafft.bat"     
mafftCline = MafftCommandline(maffPath, input=dataToProcess)
stdout, stderr = mafftCline()  # Note that MAFFT will write the alignment to stdout, which you may want to save to a file and then parse
alignedData = "aligned.fa"
alignedFile = open(alignedData, "w") 
alignedFile.write(stdout) 
alignedFile.close() 
aligned = AlignIO.read(alignedData, "fasta")

我使用this教程作为示例

2 个答案:

答案 0 :(得分:0)

正如@willOEM所说,脚本正在查找相对目录中的文件。

您的脚本假定其文件与“dataToProcess”fasta文件位于同一目录中。

如果您移动了脚本或尝试打开位于其他位置的文件,则会引发此错误。

您需要更改dataToProcessmaffPathalignedFile以引用绝对路径。

答案 1 :(得分:0)

问题是我需要逃避斜线。 并使用maffPath = "..\\mafft-win\\mafft.bat"代替maffPath = "..\mafft-win\mafft.bat"