<div dir="ltr"><div>Hi Peter, <br></div><div><br></div><div>Thank you for getting back to me! <br></div><div><br></div><div>Overall I am trying to concatenate all the sequences in a XXX.fasta file and write them to a new file called XXX_brig.fasta file. <br></div><div><br></div><div>For the fa_seq list, originally I had the same though, I believed appending the Seq objects to a list would convert them to strings and I would need to call the Seq(str) when writing the file, however it turns out that it just makes a list of Seq objects and I get an error when calling SeqRecord(Seq(fa_list)) basically saying it was already a Seq object so I removed the Seq call. <br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Feb 17, 2023 at 6:47 AM Peter Cock <<a href="mailto:p.j.a.cock@googlemail.com">p.j.a.cock@googlemail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Your variable fa_seq is a list, but the first argument to SeqRecord should be a Seq object.<div><br></div><div>Are you trying to concatenate all the sequences in each XXX_brig.fasta file?</div><div><br></div><div>Peter</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Feb 13, 2023 at 3:09 PM Sean Brimer <<a href="mailto:skbrimer@gmail.com" target="_blank">skbrimer@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Hello biopython group, </div><div><br></div><div>I'm using biopython 1.78 on a Ubuntu 18.04 LTS system with python 3.6.9 and I am trying to reformat a spades mutli-fasta output file (contigs) so I can then use BRIG. BRIG is expecting only one header per fasta so I'm attempting to concatenate all of the Seq records under one header and write it to a new file. From the traceback I think it is telling me that it doesn't like the new fasta header name however I don't know why.</div><div> </div><div>Any help would be appreciated, thank you.</div><div><br></div><div>Sean Brimer</div><div><br></div>This is my Code:<div><br><div><i>import glob<br>from Bio.SeqRecord import SeqRecord<br>from Bio.Seq import Seq<br>from Bio import SeqIO<br><br>## Looking for fasta files <br><br>fa_list = [i for i in glob.glob("*.fasta")]<br><br>## New file for the contigs for BRIG<br><br>for i in fa_list:<br>    handle = i.rpartition(".")[0]+"_brig.fasta"<br>    with open(handle,"w"):<br>    fa_seq = []<br>    new_head = i.rpartition(".")[0]<br>        for record in SeqIO.parse(i,"fasta"):<br>             fa_seq.append(record.seq)<br>             new_rec = SeqRecord(fa_seq, id = new_head, description = "")</i></div><div><i>SeqIO.write(new_rec, handle, "fasta")</i><br><div><br></div><div><br></div><div>This is the Error(s) I am getting:</div><div><br></div><div><i>Traceback (most recent call last):<br>  File "/home/sean/.local/lib/python3.6/site-packages/Bio/File.py", line 73, in as_handle<br>    yield fp<br>  File "/home/sean/.local/lib/python3.6/site-packages/Bio/SeqIO/__init__.py", line 524, in write<br>    fp.write(format_function(record))<br>  File "/home/sean/.local/lib/python3.6/site-packages/Bio/SeqIO/FastaIO.py", line 389, in as_fasta<br>    data = _get_seq_string(record)  # Catches sequence being None<br>  File "/home/sean/.local/lib/python3.6/site-packages/Bio/SeqIO/Interfaces.py", line 109, in _get_seq_string<br>    raise TypeError("SeqRecord (id=%s) has an invalid sequence." % <a href="http://record.id" target="_blank">record.id</a>)<br>TypeError: SeqRecord (id=LS22-4780-2.4) has an invalid sequence.<br><br>During handling of the above exception, another exception occurred:<br><br>Traceback (most recent call last):<br>  File "brig_fa_formatter.py", line 24, in <module><br>    SeqIO.write(new_rec, handle, "fasta")<br>  File "/home/sean/.local/lib/python3.6/site-packages/Bio/SeqIO/__init__.py", line 525, in write<br>    count += 1<br>  File "/usr/lib/python3.6/contextlib.py", line 126, in __exit__<br>    raise RuntimeError("generator didn't stop after throw()")<br>RuntimeError: generator didn't stop after throw()</i><br></div></div></div></div>
_______________________________________________<br>
Biopython mailing list  -  <a href="mailto:Biopython@biopython.org" target="_blank">Biopython@biopython.org</a><br>
<a href="https://mailman.open-bio.org/mailman/listinfo/biopython" rel="noreferrer" target="_blank">https://mailman.open-bio.org/mailman/listinfo/biopython</a><br>
</blockquote></div>
</blockquote></div>