This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Muscle and clustal alignment using biopython

HI all,

I'm trying to learn biopython and am learning from the tutorial book, however when i try to do muscle or clustal alignment, i keep getting errors. How can i get past this? Is it because of the version of my windows is not compatible? i'm using 64bit.

hoping you could help, Thanks~

biopython clustal muscle

1 answer

What is the error you're getting? There's a good chance that you don't have MUSCLE or Clustal installed on your computer, or Biopython cannot find the executables.

You can tell Biopython where to find these executables, from the help:

  >>> from Bio.Align.Applications import MuscleCommandline
  >>> muscle_exe = r"C:\Program Files\Aligments\muscle3.8.31_i86win32.exe"
  >>> in_file = r"C:\My Documents\unaligned.fasta"
  >>> out_file = r"C:\My Documents\aligned.fasta"
  >>> muscle_cline = MuscleCommandline(muscle_exe, input=in_file, out=out_file)
  >>> print(muscle_cline)
  "C:\Program Files\Aligments\muscle3.8.31_i86win32.exe" -in "C:\My Documents\unaligned.fasta" -out "C:\My Documents\aligned.fasta"

It works the same for clustalw:

  >>> clustalw_cline = ClustalwCommandline(r"C:\Program Files\Aligments\clustalw2", infile=in_file)

Of course you'd have to adjust the path.

Hi, thank you for your response, I get this

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\Bio\AlignIO\__init__.py", line 425, in read
    first = next(iterator)
  File "C:\Python27\lib\site-packages\Bio\AlignIO\__init__.py", line 372, in parse
    for a in i:
  File "C:\Python27\lib\site-packages\Bio\AlignIO\ClustalIO.py", line 109, in __next__
    ", ".join(known_headers)))
ValueError: >gi|6273291|gb|AF191665.1|AF191665 is not a known CLUSTAL header: CLUSTAL, PROBCONS, MUSCLE, MSAPROBS, Kalign

If I don't have the executables, do you know where can i get them? and which path should I install?

I added markup to your post for increased readability. You can do this by selecting the text and clicking the 101010 button. When you compose or edit a post that button is in your toolbar, see image below:

101010 Button

Thank you so much for that, next time i post something similar I'll be sure to use it

I see! The code you're trying to run expects output from Clsutal, but you're trying to give it a FASTA file. You have to align the sequences in the FASTA file using Clustal first to get the format your code wants.

Ah I see, but how do I make alignments using the fasta file? Thank you so much~ when try to input I get this

from Bio.Align.Applications import ClustalwCommandline cline = ClustalwCommandline("clustalw2", infile="opuntia.fasta") print(cline) clustalw2 -infile=opuntia.fasta import os from Bio.Align.Applications import ClustalwCommandline clustalw_exe = r"C:\Program Files\new clustal\clustalw2.exe" clustalw_cline = ClustalwCommandline(clustalw_exe, infile="opuntia.fasta") assert os.path.isfile(clustalw_exe), "Clustal W executable missing" Traceback (most recent call last): File "<stdin>", line 1, in <module> AssertionError: Clustal W executable missing

I get this... sorry, I'm a real newbie at biopython

When you run the code like that, Windows assumes that your 'clustalw2' executable is in the current folder you're running it in.

You'll have to download clustalw2 (if you haven't done so already) and use the full path to make this error message go away:

ClustalwCommandline("C:\Downloads\clustalw2", infile="opuntia.fasta")

replace the C:\Downloads path with wherever you downloaded clustalw2 to

I see, then i need an executable file for clustal and muscle in the same folder as my fasta file? Do you know where I can get it? and Thank you again~

You can get them from google :)

Their path doesn't matter as long as you explicitly set both, they can be in different folders.

Got it~ Thanks so much~ :) I'll try getting first the executables and run it.

Log in to answer this question.