Many thanks for posting the solution, however does it extract the exact coding sequence for a particular protein?
For example, if we look at this protein. This is the exact coding sequence for that protein. But when I run your script, changing "protein_ID" to 635010873 (the GI number for the protein), it returns this, the full mRNA sequence for this region, but not the coding sequence for the protein of interest?
Basically, my aim is to obtain the longest canonical transcript for each gene. I can obtain a list of proteins and their lengths, and then I was thinking of extracting the longest protein's coding sequence to give me the longest canonical transcript. I've also asked similar questions here and here; if you could shed any light on the topic!