def populations_to_index(pop1, pop2, npop):
    """Get the index of the column of a pair of populations in the fst file from
    popoolation2.

    Columns in the fst file are
    chromosome, center of the window, number of snps, covered fraction,
    coverage, fst 1:2, fst 1:3, ..., fst 1:n, fst 2:3, ..., fst 2:n, ...,
    fst  n-1:n

    Got from here: https://stackoverflow.com/a/27088560/4730336

    >>> populations_to_index(1, 2, 2)
    1
    >>> populations_to_index(1, 2, 22)
    1
    >>> populations_to_index(2, 3, 22)
    22
    >>> populations_to_index(21, 22, 22)
    231
    """
    pop1 = pop1 - 1
    pop2 = pop2 - 1
    big_triangle = int(npop * (npop - 1) / 2)
    small_triangle = int((npop - pop1) * (npop - pop1 - 1) / 2)
    k = big_triangle - small_triangle + pop2 - pop1
    return k