This is a test version of Biostars. For the public version, visit https://www.biostars.org.
alignment using needleman wunsch in biopython

I want to align two sequnces in bipython using needleman wunsch algorithm

file1.faa:

>seq_1
gagtcccagctgtgcctgactaaccgtgtttctcttgtatctaggagtgctcccaccccagcccgttgctgcccagctgtttaattgagttgtcatatgttaataacggtatattggaacactgtataacaccaacacactcgagtctttcaagactgcagataagaagctccttttggaacaagcagcaaatgaggttagctg

file2.faa:

>seq_2
GAGTCCCAGCTGTGCCTGACTAACCGTGTTTCTCTTGTATCTAGGAGTGCTCCCACCCCAGCCCGTTGCTGCCCAGCTGTTTAATTGAGTTGTCATATGTTAATAACGGTATTGGAACACTGTATAACACCAACACACTCGAGTCTTTCAAGACTGCAGATAAGAAGCTCCTTTTGGAACAAGCAGCAAATGAGGTTAGCTGAGATCGGAAGAGCACACGTCTGAACTCCAGTCACTAGCGTTCTCATCT

I have tried

from Bio.Emboss.Applications import NeedleCommandline
from Bio import AlignIO

needle_cline = NeedleCommandline(asequence="file1.faa", bsequence="file2.faa",gapopen=10, gapextend=0.5, outfile="needle.txt")

But the output file needle.txt does not get written. Can you help?

alignment

1 answer

It seems you only created the wrapper object for the function call. Assuming you have the EMBOSS toolkit installed, this means you still have to call the actual function to make Biopython execute the command. So after creating the wrapper object like this:

needle_cline = NeedleCommandline(asequence="file1.faa", bsequence="file2.faa",gapopen=10, gapextend=0.5, outfile="needle.txt")

you need to actually execute the function like this:

stdout, stderr = needle_cline()

This will create the output file and save any output of the command to the stderr and stdout streams to the respective variables.

I did the above but I get an error

Bio.Application.ApplicationError: Non-zero return code 127 from 'needle -outfile=needle.txt -asequence=file1.faa -bsequence=file2.faa -gapopen=10 -gapextend=0.5', message '/bin/sh: needle: command not found'

I have installed emboss, so I guess it is a path problem. Can you suggest a fix?

If you are using a Linux operating system, you can append the EMBOSS executables to your path by creating a file entitled EMBOSS.sh (name doesn't matter, but it has to be .sh) in /etc/profile.d/

Make the contents of the file the following:

PATH=$PATH:/path/to/your/EMBOSS/executables
export PATH

Then save the file and restart the terminal you are using python from. For other operating systems I unfortunately don't know how to append things to the PATH, but is should be easy to find out by a simple google search.

Log in to answer this question.