1

I work with a Mac. I have been trying to make a multiple sequence alignment in Python using Muscle. This is the code I have been running:

from Bio.Align.Applications import MuscleCommandline
cline = MuscleCommandline(input="testunaligned.fasta", out="testunaligned.aln", clwstrict=True)
print(cline)
from Bio import AlignIO
align = AlignIO.read(open("testunaligned.aln"), "clustal")
print(align)

I keep getting the following error:

FileNotFoundError: [Errno 2] No such file or directory: 'testunaligned.aln'

Does anyone know how I could fix this? I am very new to Python and computer science in general, and I am totally at a loss. Thanks!

kelsey
  • 11
  • 1
  • Have you installed MUSCLE? you aren't giving its path to MuscleCommandline – Jan Wilamowski Jun 25 '21 at 04:57
  • I have installed MUSCLE. How do I give its path? – kelsey Jun 25 '21 at 13:42
  • 2
    You aren't running MUSCLE, just printing out the command line text. No alignment file exists when you run open("testunaligned.aln"). You should be able to use cline() to run MUSCLE (provided the executable is in your environment path or you give the full path to the executable). – Ghoti Jun 25 '21 at 20:26

1 Answers1

1

cline in your code is an instance of MuscleCommandline object that you initialized with all the parameters. After the initialization, this instance can run muscle, but it will only do that if you call it. That means you have to invoke cline()

When you simply print the cline object, it will return a string that corresponds to the command you can manually run on the command line to get the same result as when you invoke cline().

And here the working code:

from Bio.Align.Applications import MuscleCommandline
cline = MuscleCommandline(
    input="testunaligned.fasta", 
    out="testunaligned.aln", 
    clwstrict=True
)
print(cline)
cline() # this is where mucle runs
from Bio import AlignIO
align = AlignIO.read(open("testunaligned.aln"), "clustal")
print(align)
fabianegli
  • 2,056
  • 1
  • 18
  • 35