<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
Biopython developers;<br>
</div>
<div style="font-family: Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<br>
</div>
<div style="font-family: Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
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.</div>
<div style="font-family: Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<br>
</div>
<div style="font-family: Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<span>File "/HOME/venv/lib/python3.7/site-packages/Bio/AlignIO/__init__.py", line 233, in write<br>
</span>
<div>    "objects, got: %r" % alignment<br>
</div>
<span>TypeError: Expect a list or iterator of MultipleSeqAlignment objects, got: <Bio.Align.PairwiseAlignment object at HEX_ADDRESS></span></div>
<div style="font-family: Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<span><br>
</span></div>
<div style="font-family: Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<span>It will write out empty files, named appropriately, but not with the pairwise alignment in each file as desired.</span><br>
</div>
<div style="font-family: Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<br>
</div>
<div style="font-family: Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
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.</div>
<div style="font-family: Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<br>
</div>
<div style="font-family: Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
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.<br>
</div>
<div style="font-family: Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<br>
</div>
<div style="font-family: Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
Using BioPython v1.76</div>
<div style="font-family: Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
Python 3.7.7</div>
<div style="font-family: Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
MacOS 10.14.6</div>
<div style="font-family: Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
Example code below:</div>
<div style="font-family: Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
------------------------------------------<br>
</div>
<div style="font-family: Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<span>import os<br>
</span>
<div>import sys<br>
</div>
<div>import glob<br>
</div>
<div>from Bio import SeqIO<br>
</div>
<div>from Bio import Align<br>
</div>
<div>from Bio.Align import substitution_matrices<br>
</div>
<span>from Bio import AlignIO</span></div>
<div style="font-family: Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<span></span><br>
</div>
<div style="font-family: Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255);">
<span>base_path = "SOME_PATH/test/"<br>
</span>
<div>index_ref = "123456.gp"<br>
</div>
<div>seq1 = SeqIO.read(os.path.join(base_path, index_ref), "genbank")</div>
<div><br>
</div>
<div>for gp_file in glob.glob(os.path.join(base_path, "*.gp")):<br>
</div>
<div>    seq2 = SeqIO.read(open(gp_file, "r"), "genbank")<br>
</div>
<div>    aligner = Align.PairwiseAligner()<br>
</div>
<div>    aligner.open_gap_score = -10<br>
</div>
<div>    aligner.extend_gap_score = -1<br>
</div>
<div>    aligner.substitution_matrix = substitution_matrices.load("BLOSUM62")<br>
</div>
<div>    pairwise = aligner.align(seq1.seq, seq2.seq)<br>
</div>
<div>    file_out = (seq1.id + "_" + seq2.id + "_" + aligner.algorithm + "_" + aligner.mode)<br>
</div>
<div>    pair_out = open(file_out + ".mfa", "w")<br>
</div>
<div>    AlignIO.write(pairwise, pair_out, "fasta")<br>
</div>
<span>    pair_out.close()</span><br>
</div>
<div>
<div style="font-family: Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
------------------------------------------</div>
<div style="font-family: Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
I did some more digging and not sure if it is related to <a href="https://github.com/biopython/biopython/issues/2632">
https://github.com/biopython/biopython/issues/2632</a></div>
<div style="font-family: Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Any assistance to get this working or alternative methods would be greatly appreciated.<br>
</div>
<div style="font-family: Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div id="Signature">
<div>
<div></div>
<div id="divtagdefaultwrapper" dir="ltr" style="font-size: 12pt; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); font-family: Calibri, Arial, Helvetica, sans-serif;">
<p style="margin-top:0px; margin-bottom:0px"><span id="ms-rterangepaste-start"></span></p>
<div>
<p style="margin-top:0px; margin-bottom:0px"><span style="font-family:Arial,Helvetica,sans-serif">Best Regards,</span></p>
<span style="font-family:Arial,Helvetica,sans-serif"></span><span style="font-family:Arial,Helvetica,sans-serif">asleicht@wisc.edu</span></div>
<span style="font-family:Arial,Helvetica,sans-serif"></span><span id="ms-rterangepaste-end"></span><br>
<p style="margin-top:0px; margin-bottom:0px"></p>
</div>
</div>
</div>
</div>
</body>
</html>