@Juke-34 - Many thanks for your suggestion. However, I figured a way out to overcome this problem using the following link (https://libraries.io/github/YeoLab/gffutils, scroll to "Longest protein for this gene") and some addition of code. In my opinion, following should do the trick -
transcript = {}
for item in db.children(gene, featuretype="mRNA"):
if db[gene].strand == item.strand:
transcripts[item.id]= sum(len(sub_item) for sub_item in db.children(item, featuretype="CDS"))
Above, I access all possible mRNA transcripts for a given gene, and I store the "sum" (read concatenate) of all CDS for every transcript in transcript dictionary
trans = (sorted(transcripts.items(), key=lambda x: x[1], reverse=True)[0])[0]
trans_length = (sorted(transcripts.items(), key=lambda x: x[1], reverse=True)[0])[1]
I sort the items in the transcript dictionary in an descending order of the length of the transcript, and access the 0th entry (aka the 1st entry, which will contain the longest transcript). Here, trans contains the id of the longest transcript (which I use later for accessing all CDS in that transcript) and trans_length contains the length of this transcript.
for item in db.children(trans_element, featuretype="CDS"):
print(item.start)
Finally, you can access the CDS (or any other feature of interest, like exons, UTRs etc) like above.
@genomax - thanks for suggesting to attach code, apologies for not doing so in the first place