def compute_heterozygosity(in_prefix, nb_samples):
    """Computes the heterozygosity ratio of samples (from tped)."""
    tped_name = in_prefix + ".tped"
    tfam_name = in_prefix + ".tfam"

    # The function we want to use
    check_heterozygosity = np.vectorize(is_heterozygous)

    # The autosomes
    autosomes = {str(i) for i in xrange(1, 23)}

    # The tfam
    samples = None
    with open(tfam_name, 'rb') as input_file:
        samples = input_file.readlines()
        samples = [tuple(i.rstrip("\r\n").split("\t")[:2]) for i in samples]

    heterozygosity = np.zeros(nb_samples, dtype=int)
    nb_markers = np.zeros(nb_samples, dtype=int)
    with open(tped_name, 'rb') as input_file:
        # There is no header
        for line in input_file:
            row = np.array(line.rstrip("\r\n").split("\t"))

            chromosome = row[0]
            if chromosome not in autosomes:
                # This is not an autosome, so we skip
                continue

            # Getting the genotypes
            genotypes = row[4:]

            # Finding the heterozygous genotypes
            heterozygosity += check_heterozygosity(genotypes)

            # Adding to number of markers for each samples (excluding no calls)
            nb_markers += genotypes != "0 0"

    return np.true_divide(heterozygosity, nb_markers), samples