This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Pairwise2 Index Error

Hi,

why does this python script always give an index out of range error, when pairwise2 is supposed to output a 5 element tuple? e.g. (seqA, seqB, score, begin, end)

Thanks,

Theo

code:

from Bio import pairwise2

a = 'AGCTGTA'
b = 'GCTCTA'

c = pairwise2.align.localxx(a,b)

print c[2]
biopython

2 answers

If you just print out C by itself, you get:

[('AGCTGTA', '-GCTCTA', 5.0, 1, 7)]

So it looks like it's outputting an array of possible alignments. Each alignment is a tuple of the data you described. In this case, just one alignment.

So to get that one alignment you would need to:

print c[0][2]

Or if there are multiple alignments:

for alignment in c:
   #do stuff

Brilliant, thanks, that solved it.

All of the documentation and examples for pairwise2 (not very many I could find) show the output as a tuple only and show code like c[3], don't know what's gone wrong there!

Thanks again,

Theo

If you liked Dk's answer, could you mark it as accepted?

Regarding misleading documentation, got any links/specifics?

Log in to answer this question.