This is a test version of Biostars. For the public version, visit https://www.biostars.org.
sequence alignment BIOPYTHON

I am dealing with two fasta files and wanted to align them with clustal using biopython. I want these two files as two sequences in this code, i.e., ref_seq= fasta file 1 and target_seq=fasta file 2. Can anyone help?

>>from Bio.Seq import Seq
>>from Bio.SeqRecord import SeqRecord
>>from Bio.Alphabet import IUPAC
>>import Bio.SeqIO as SeqIO
>>from Bio.Align.Applications import ClustalOmegaCommandline
>>    
>>ref_seq = "ERVVIGSKPFNEQYILANMIAILLEENGYKA"
>>target_seq = "ERVVIGSKPFNEQYILANMINGYKA"
>>in_file = "unaligned.fasta"
>>out_file = "aligned.fasta"

>># Write my sequences to a fasta file
>>handle = open(in_file, 'w')
>>records = (SeqRecord(Seq(seq, IUPAC.protein), id=str(index), name="Test", description="Test") for index,seq in enumerate([ref_seq, target_seq]) )

>>with open(in_file, 'w') as handle:
    SeqIO.write(records, handle, "fasta")
>>handle.close()

>>clustalomega_cline = ClustalOmegaCommandline(infile=in_file, outfile=out_file, verbose=True, auto=True, force=True)
>>clustalomega_cline()
alignment sequencing gene snp

I added code 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

0 answers

No answers yet.

Log in to answer this question.