Muscle alignment in python

2024/7/8 7:27:56

I have a problem with printing my output from muscle aligning in python. My code is:

from Bio.Align.Applications import MuscleCommandline
from StringIO import StringIO
from Bio import AlignIOdef align_v1 (Fasta): muscle_cline = MuscleCommandline(input="hiv_protease_sequences_w_wt.fasta")stdout, stderr = muscle_cline()MultipleSeqAlignment = AlignIO.read(StringIO(stdout), "fasta") print MultipleSeqAlignment 

Any help?

Answer

It would be nice to know what error you received, but the following should solve your problem:

from Bio.Align.Applications import MuscleCommandline
from StringIO import StringIO
from Bio import AlignIOmuscle_exe = r"C:\muscle3.8.31_i86win32.exe" #specify the location of your muscle exe fileinput_sequences = "hiv_protease_sequences_w_wt.fasta"
output_alignment = "output_alignment.fasta"def align_v1 (Fasta): muscle_cline = MuscleCommandline(muscle_exe, input=Fasta, out=output_alignment)stdout, stderr = muscle_cline()MultipleSeqAlignment = AlignIO.read(output_alignment, "fasta") print MultipleSeqAlignmentalign_v1(input_sequences)

In my case I received a ValueError:

>>> AlignIO.read(StringIO(stdout), "fasta") 
Traceback (most recent call last):File "<stdin>", line 1, in <module>File "C:\WinPython-64bit-3.3.2.3\python-3.3.2.amd64\lib\site-packages\Bio\AlignIO\__init__.py", line 427, in readraise ValueError("No records found in handle")
ValueError: No records found in handle

This could be avoided by saving the output and reopening with AlignIO.read.

I also received a FileNotFoundError that could be avoided by specifying the location of the muscle exe file. eg:

muscle_exe = r"C:\muscle3.8.31_i86win32.exe" 

The instructions for this are shown in help(MuscleCommandline), but this is not currently in the Biopython tutorial page.

Finally, I am assuming you want to run the command using different input sequences, so I modifed the function to the format “function_name(input_file).”

I used python 3.3. Hopefully the code above is for python 2.x as in your original post. For python 3.x, change "from StringIO import StringIO" to "from io import StringIO" and of course “print MultipleSeqAlignment” to “print(MultipleSeqAlignment)”.

https://en.xdnf.cn/q/120594.html

Related Q&A

why does my function is returning data type None??: Python datatype None

This is my python code for printing an absolute number. My function is returning type None. I am not getting what I have done wrong. Please help me. def n(num):if num<0:return (num*-1)no = input(&qu…

np.sum Not returning total counts

I am trying this code but it does not return total count for zero[x][y], in this case it should return 5 but all it displays 255 five time. THIS CODE IS FOR CONNECTED COMPONENTS AND ZERO IS ONE COMPONE…

Python Printing Dictionary Key and Value side by side

I want a program that prints Key and Value side by side for the following code:This is a Dictionary:d = {M: [Name1, Name2, Name3], F: [Name1,Name2,Name3]}I want the a program that prints in the followi…

can i use rusts match in python? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.This question does not appear to be about programming within the scope defined in the help center.Cl…

Consolidating Elements of a List [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.Want to improve this question? Update the question so it focuses on one problem only by editing this post.Closed 6…

html textarea via python using post function

<div><textarea cols="25" rows="12" name="box" id="box" tabindex="2">TEXT GOES HERE </textarea></div><div><p class=&quo…

Fibonacci in Python - Simple solution [duplicate]

This question already has answers here:How to write the Fibonacci Sequence?(67 answers)Closed 6 years ago.n1 = 1 n2 = 1 n3 = n1 + n2 for i in range(10):n1 + n2print(n3)n1 = n2n2 = n3According to what …

snake game: snake colliding with itself

Hi I am currently writing a snake game code and I am nearly finished however I am having difficulty writing a code which will cause the game to end if the head of the snake collides with its body, I th…

python3 function not defined even though it is

when I try to call the changeProfile function, I keep getting the error "getAuthCode is not defined" even though it is clearly defined. Why do I keep getting this error? What am I doing wron…

Python maximum and minimum

Im supposed to write a function max_and_min that accepts a tuple containing integer elements as an argument and returns the largest and smallest integer within the tuple. The return value should be a t…