So I'm trying to actively learn how to use Biopython, and python for that matter. I made a script that extracts the Genbank accession number and the country from a .gb (genbank) file and puts the accession number and country in a text file. Here is my script:
from Bio import SeqIO gb_file = "denv1.gb" for gb_record in SeqIO.parse(open(gb_file,"r"), "genbank") : printgb_record.name), for feat in gb_record.features: if feat.type == 'source': source = gb_record.features for qualifiers in source.qualifiers: if qualifiers == 'country': country = source.qualifiers['country'] print(country)
Now the output text file, every accession number with a country is listed perfectly, but when a country is not present for a particular sequence in the genbank file, it does this:
Instead I would like it to be blank where the name of the country would go. Hopefully this makes sense and isn't too confusing. Can anyone help me out? As I said I'm trying to learn, so pointers or links to help would be greatly appreciated!