Great about the script for Shannon.
Just browsing through. In line 212, what about using
r['phylum_reg'] if r['phylum_reg'] else 'p__',
I can't tell if you need to script in the retrieval of the taxonomic hierarchy, but I have some scripts using the Entrez API which can do that. Let me know.