Thank you very much for the quick response Philipp!
Unfortunately, to date my experience has been in the shell and R programming. So I'm currently unfamiliar with Python. Although shell is very easy and quick, once the pattern gets complex it appears you should use Python rather than bashing your head against the wall to come up with a solution using pure shell.
Biopython looks like an amazing resource for bioinformatics, so thank you for the suggestion - I will be taking this opportunity to learn it.
I tried to get my feet-wet by opening the python interpreter on AWS EC2 Ubuntu 14 and running this script (both interactively and as a .py script). There were no errors (I'm using Python2) but the output didn't have the KOG terms attached to the FASTA.
>Transcript_122 len=312
GGGGATATAATTATTTATTGATCTATATGAGCATTTTCTCTTGTGATCTAATTGTCTGAATTTATGAGTGGCAAGATAGCAAATCACTCGTCTGCAAGGTGGCAGTTGTGCAAATGCAGCACTGTTTTATATACTATAGCACTTTGTTGTTCAATTTGTTGTTTTGTGTTTATACATTGATCATTCTCATTGTTTTTTTGTTGTTGTTGATATTCTTTTCTTTCCTTCTTTCTTTCTTTTGTTCTATAATCTTCATAGGAGACACCTCAAAGTAAAATATTGTGTGGGATATTTTCATAAATTTATTAAAG
I'm not sure where the problem lies. However, one potential future issue I see is assert gene_name not in kogs_dict # sanity check: we should have only one kog result per gene, I guess?
From a cursory view of my KOG results I noticed that there may be some genes with multiple KOG results (see Transcript_506 in KOG file)
I've attached test-files for anyone willing to tackle this: 1) Fasta: http://www.filedropper.com/fasta 2) KOG: http://www.filedropper.com/kog