How can I calculate gene_length for RPKM calculation from counts data? I have read counts data and I want to convert them into RPKM values. For this conversion I need the gene length. 

Does the gene length need to be calculated based on the sum of coding exonic lengths? Or are there any different ways for that? 

I know that gene length can be taken from the Gencode GTF v19 file. Could you please tell me how that Gene_length is calculated?

The Data I'm having is RNA-Seq data. I don't have any idea whether I need to include UTR's in this calculation or only exons?

In Github I have seen RPKM calculation from Counts data with the Gene_length from Gencode GTF file. Do you think this is the right way of calculation?

And why RPKM is - Its not for differential analysis. For TNBC subtyping they use microarray data. I would like to give a try with RNA-Seq data. So for this I'm trying out different and the right way.
Here you can find some example R code to compute the gene length given a GTF file (it computes GC content too, which you don't need). This uses one of a number of ways of computing gene length, in this case the length of the "union gene model". In this method, the non-duplicated exons for each gene are simply summed up ("non-duplicated" in that no genomic base is double counted). This is a very simple way of getting a gene length.

There are alternative methods that you should be aware of, among which are:


Median transcript length: That is, the exonic lengths in each transcript are summed and the median across transcripts is used. This is probably a little more valid than the code that I linked to.
Per-sample effective gene lengths: the optimal method, though it requires using something like RSEM, which will give you an effective gene length.
Using the length of the "major isoform" in your tissue of interest. This isn't as good as method 2, but is more accurate than all of the others.


At the end of the day, you're just coming up with a scale factor for each gene, so unless you intend to compare values across genes (this is problematic to begin with) then it's questionable if using some of the more correct but also more time-involved methods are really getting you anything.

Edit: Note that if you want to plug these values into some sort of subtyping tool (TNBC in your case), you should first start with some samples for which you know the subtype. Then you can at least see if you're getting reasonable results. After that, do read up on how the method works and see if there's anything about RNAseq that makes it incompatible.