This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Adding Sequence Names to Pairwise2 output?

I have a the following script utilizing pairwise2 from Biopython. It takes 2 Fasta files as input. I would like to add the sequence names to the output from these files if possible.

from Bio.Blast import NCBIXML

from Bio import pairwise2

from Bio.SubsMat import MatrixInfo as mat list

from math import log, exp

from Bio import SeqIO

from itertools import product

from Bio.pairwise2

import format_alignment

seq1=SeqIO.to_dict(SeqIO.parse(open('less.fasta'), 'fasta'))

seq2=SeqIO.to_dict(SeqIO.parse(open('out.fasta'), 'fasta'))

with open("align.txt", "w") as out:

    for s1, s2 in product(seq1, seq2):        

            for a in pairwise2.align.localds(str(seq1[s1].seq), str(seq2[s2].seq), matlist.blosum62, -11, -1):            

                    out.write(format_alignment(*a))

Current output:

KMLEENTNILK

||

TMVGFGDFV--

Score=6

KMLEENTNILK

   |||

-FTHDLINLL-

Score=12

KMLEENTNILK

  |||

LQVWSVTEV--

Score=8

KMLEENTNILK-----

    ||

-------VIMVGSAGV

Score=6

alignment

Please fix the formatting in your code, and ideally mock up an example of what you would like as output.

0 answers

No answers yet.

Log in to answer this question.