I am aware of this similar question. But the accepted answer there answers how to calculate TPM given a mapping from gene name to gene length.
My question is, given an annotation file of genes (for example from Ensembl here), how do you calculate gene length for the purpose of calculating TPM on a gene count matrix coming from RNA seq data. That is, I understand the actualy calculation of TPM given gene lengths, but I do not understand what the gene lengths are.
From what I understand, to calculate gene lengths from annotation file for RNA seq data, you only consider the exons of each gene, but even so, many exons overlap. What is the standard method of dealing with this?
For example, I have read that using the length of the union of all exons of the gene is acceptable, but from what I understand TPM is meant to represent the "expected number of reads coming from gene X when randomly selecting 1e6 transcripts". So taking the union of all exons will be an estimate of this but it might under-estimate this.
EDIT: From what I can tell this question is not a duplicate of RNASeq: Normalization, stabilization, gene length and rlog That question does discuss how to perform normalization that takes gene length into account, but it does not ask "what is gene length? How does one determine the length of each gene?" Possible answers could be like what I already mentioned: length of the union of all exons in the gene, or another possible answer is one from the linked question "length of the longest transcript isoform" but I feel that it is not really discussed in that answer/question.