This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Musclecommandline Not Writing File

I'm trying to work through the Biopython tutorial on multiple sequence alignment and get an error whenever I try to use subprocess:

child = subprocess.Popen(str(cline),
         stdout = subprocess.PIPE,
         stderr = subprocess.PIPE,
         shell = (sys.platform!="win32"))

I get this error:

    Traceback (most recent call last):
  File "<pyshell#36>", line 2, in <module>
    stdout = subprocess.PIPE)
  File "C:\Python27\lib\subprocess.py", line 672, in __init__
    errread, errwrite)
  File "C:\Python27\lib\subprocess.py", line 882, in _execute_child
    startupinfo)
WindowsError: [Error 2] The system cannot find the file specified

I've gone so far as to copy and paste the tutorial into the interpreter and no luck. Neither ClustalW nor Muscle are writing the alignment files (I tried the depreciated MultipleAlignCL as well with no luck).

I'm using Python v2.7 and Biopython v1.55 and have tried reinstalling both. Any advice?

biopython alignment

What system are you using?

Can you put code you have written above child=subprocess.Popen(str(cline)

Wow, it wasn't installed. How embarrassing. It's working now, thanks!

Also on recent Biopython you can just do child() rather than calling subprocess yourself.

Thank you for explaining us the solution to your problem. However, you should use the 'Mark this answer as the correct one' function instead of writing an answer as you did here.

subprocess is not a BioPython library. Which tutorial are you following?

2 answers

subprocess is giving you a generic error message that it can't find the executables you want to run. Do you have ClustalW and Muscle installed on your Windows machine? Are they directly callable from the command-line?

The best way to test this is to add:

print str(cline)

to your Python code, and then try to run the command-line that is printed from a terminal. What errors does this give?

Feel free to edit your initial question with this additional information.

You are using Windows so my guess is that MUSCLE.exe is not in system PATH. So what I suggest you define first MUSCLE command line wrapper in the system PATH. How? Under Windows either you have to give complete PATH or set PATH. I think setting PATH will ease your problem. Else everything must work fine.

import sys,os, subprocess
from Bio import AlignIO
from Bio.Align.Applications import MuscleCommandline
out_file = "opuntia.aln"
cline = MuscleCommandline(input="opuntia.fasta", out=out_file)
child= subprocess.Popen(str(cline),
                         stdout = subprocess.PIPE,
                         stderr=subprocess.PIPE,
                        shell=(sys.platform!="win32"))

Or you can test directly from Windows command prompt to validate whether MUSCLE is working by:

C:\MyPrograms\Muscle\muscle.exe -in opuntia.fa -out opuntia.aln

Further Suggestion, put

C:Python27lib; C:Python27;C:Python27Scripts

too in the System Variable PATH.

Hope this helps, if not comment further so I can again edit my answer precisely

Log in to answer this question.