Thank you very much ! It works:)
Hi !
I'm new in Bioinformatics, and my question may be basic to you all, but I could not find a solution on the internet....
Genom of my bacteria was sequenced and annotated a few times and I need to make a table with old and new gene names so:
The thing I want to do is to extract from all gene features locus tag and old local tag, I wrote simple lines:
from Bio import SeqIO
record = SeqIO.read('My_genome.gb', 'genbank')
for feature in record.features:
if feature.type == 'gene':
print ('Locus tag:', feature.qualifiers['locus_tag'])
print ('Old Locus tag:', feature.qualifiers['old_locus_tag'])
but the problem is that sometimes, there is a new gene in My_genome and it has no old locus tag... and it stops.
What would you advise me to do, so I can obtain all of them listed?
Thank you all in advance!
1 answer
You can first check if the gene has the old_locus_tag qualifier. If it doesn't, you can assign it the default value (e.g., NA). This code should do the job:
from Bio import SeqIO
record = SeqIO.read('My_genome.gb', 'genbank')
for feature in record.features:
if feature.type == 'gene':
locus = feature.qualifiers.get('locus_tag', 'NA')
locus_old = feature.qualifiers.get('old_locus_tag', 'NA')
print('Locus tag:', locus)
print('Old Locus tag:', locus_old)
Log in to answer this question.