This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Splitting Gbff files

Hi there, There are any easy way (or hard) to split a multi Gbff file (7815) in single gbk files? I appreciate any help! Paulo

gbff

1 answer

You could use BioPython like so:

from Bio import SeqIO

# Parse GenBank with multiple records
stream = SeqIO.parse("genomes.gb", format="genbank")

# Write each record as a separate file
for rec in stream:
    SeqIO.write(rec, f"{rec.id}.gb", "genbank")

@Istvan Albert To be real honest I tried but I maybe messed up because in my code it was reading like a unique file 8(. I will check it out. Thank you for your time. Paulo

The code is really simple. The parsing step reads the original multi-genbank file, then the loop writes into a filename that uses the record id in the name. Change it to

from Bio import SeqIO

# Parse GenBank with multiple records
stream = SeqIO.parse("genomes.gb", format="genbank")

# Print the id of each record
for rec in stream:
    print(rec.id)

to see each record id in your file, perhaps it is reusing the ids

Log in to answer this question.