The TPI measure represents the weighted arithmetic mean (expression levels as
weights) for the synonymous vs non-synonymous polymorphism ratios.
$$TPI_s = \sum (e_is * P_N/N / ((P_S + 1) / S)) / \sum e_is$$
where TPI_s denotes the TPI value in developmental stage s, e_is denotes the gene expression level of gene i in stage s, n denotes the number of genes, PN and PS denote the numbers of non-synonymous and synonymous polymorphisms, and N and S are the numbers of nonsynonymous and synonymous sites, respectively.
Internally the function is written in C++ to speed up TPI computations.