Question

I want to use MafftCommandline to align my data, but i get following error:

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

my code is as following :

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")

i was using this tutorial as an example

Was it helpful?

Solution

As @willOEM has said, the script is looking for a file in a relative directory.

Your script assumes that its file is located in the same directory as your "dataToProcess" fasta file.

If you have moved your script or are trying to open a file located elsewhere then it will raise this error.

You'll need to change your dataToProcess, maffPath and alignedFile to refer to the absolute path.

OTHER TIPS

The problem was that i needed to escape slashes. And use maffPath = "..\\mafft-win\\mafft.bat" instead of maffPath = "..\mafft-win\mafft.bat"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top