[Biopython] Issues writing Pairwise Alignment to file with BioPython

Michiel de Hoon mjldehoon at yahoo.com
Sun Jul 12 13:57:13 UTC 2020


 Daer Andrew,
Where did you find the example you are following?See section 6.5.2 in the Biopython documentation for examples how to print the alignment.
Best,-Michiel

    On Tuesday, June 16, 2020, 12:23:26 PM GMT+9, ANDREW LEICHT <asleicht at wisc.edu> wrote:  
 
  #yiv4035967378 P {margin-top:0;margin-bottom:0;}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.76Python 3.7.7MacOS 10.14.6Example 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


_______________________________________________
Biopython mailing list  -  Biopython at mailman.open-bio.org
https://mailman.open-bio.org/mailman/listinfo/biopython  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.open-bio.org/pipermail/biopython/attachments/20200712/fce83552/attachment.htm>


More information about the Biopython mailing list