[Biopython] Issues writing Pairwise Alignment to file with BioPython

ANDREW LEICHT asleicht at wisc.edu
Tue Jun 16 03:17:46 UTC 2020


Biopython developers;

I am having some issues after following examples from all over the web to write Pairwise Alignment to files.  I am using the exact same syntax, but not sure what I am doing wrong as I am getting errors.

File "/HOME/venv/lib/python3.7/site-packages/Bio/AlignIO/__init__.py", line 233, in write
    "objects, got: %r" % alignment
TypeError: Expect a list or iterator of MultipleSeqAlignment objects, got: <Bio.Align.PairwiseAlignment object at HEX_ADDRESS>

It will write out empty files, named appropriately, but not with the pairwise alignment in each file as desired.

My code takes genpept files (genbank standard) each with a single protein record inside each ~1500AAs, and input reads them as sequence objects.  Then it does a sequence pairwise comparison between a reference file and all other .gp files in a folder, and should output them as individual multi-fasta alignment files.

I have tired many iterations of code tweaking: AlignIO.write --> SeqIO.write, set pairwise --> pairwise[0], tried .parse instead of .read, tried using Bio.pairwise2 instead.  All these created other errors which did not get me any closer to the desired outcome.

Using BioPython v1.76
Python 3.7.7
MacOS 10.14.6
Example code below:
------------------------------------------
import os
import sys
import glob
from Bio import SeqIO
from Bio import Align
from Bio.Align import substitution_matrices
from Bio import AlignIO

base_path = "SOME_PATH/test/"
index_ref = "123456.gp"
seq1 = SeqIO.read(os.path.join(base_path, index_ref), "genbank")

for gp_file in glob.glob(os.path.join(base_path, "*.gp")):
    seq2 = SeqIO.read(open(gp_file, "r"), "genbank")
    aligner = Align.PairwiseAligner()
    aligner.open_gap_score = -10
    aligner.extend_gap_score = -1
    aligner.substitution_matrix = substitution_matrices.load("BLOSUM62")
    pairwise = aligner.align(seq1.seq, seq2.seq)
    file_out = (seq1.id + "_" + seq2.id + "_" + aligner.algorithm + "_" + aligner.mode)
    pair_out = open(file_out + ".mfa", "w")
    AlignIO.write(pairwise, pair_out, "fasta")
    pair_out.close()
------------------------------------------

I did some more digging and not sure if it is related to https://github.com/biopython/biopython/issues/2632

Any assistance to get this working or alternative methods would be greatly appreciated.



Best Regards,

asleicht at wisc.edu

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.open-bio.org/pipermail/biopython/attachments/20200616/bc79e76f/attachment.htm>


More information about the Biopython mailing list