def calculateTPM(countsfile):
    """Calculates the TPM values for a sample
    TPM = rate/sum(rate) * 10^6
    rate = nreads/cluster_length (kb)
    parameters
    ----------
    counts_file
        file containing the counts
    core
        bool, skip housekeeping genes
    returns
    ----------
    TPM = dictionary containing TPM counts per cluster
    """
    rates = {}
    ratesum = 0
    with open(countsfile, "r") as f:
        for line in f:
            if "*" not in line:
                line = line.strip()
                cluster, length, nreads, nnoreads = line.split("\t")
                try:
                    rate = float(nreads) / float(length)
                    rates[cluster] = rate
                    ratesum += rate
                except(ZeroDivisionError):
                    print('Unable to calculate TPM counts')
                    pass
    TPM = {}
    for key in rates:
        try:
            TPM[key] = rates[key] / ratesum
        except(ZeroDivisionError):
            TPM[key] = 0
    return (TPM)