Skip to content

Implement pairwise Fst #199

Closed
Closed

Description

@KLohse

Having thought some more about the two alternative Fst definitions, we definitely want to general definition of Fst in terms of expected pairwise coalescence times:

Fst= (Tt-Tw)/(Tt)

Where Tt is the average for a pairwise sample taken at random. For the case of two populations we assume that we are equally likely to sample from within and between species, i.e.
Tt=(Tb + Tw)/2

Substituting gives:

Fst= (Tb-Tw)/(Tb+Tw)

@GertjanBisschop wrote a simple implementation of this using BranchStat.divergence_matrix:

def Fst(div_entry):
A = np.mean((div_entry.diagonal()))
B = div_entry[1,0]
return (B-A)/(A+B)

def calculate_Fst(ts, samplesets, function=Fst):
winlen = [0,ts.sequence_length]
BranchStat = tskit.BranchLengthStatCalculator(ts)
div_matrix = BranchStat.divergence_matrix(samplesets,winlen)
Fst_result = list(map(function, div_matrix))
return Fst_result

Hopefully this can be implemented in tskit to return a matrix of pairwise fst values for arbitrary sets of populations.

Activity

  1. added this to the Python 0.1.6 milestone on Jun 11, 2019
  2. jeromekelleher commented on Jun 12, 2019

    @jeromekelleher
    Member

    @KLohse, can you take a look at the definition of Fst that we've just merged here please? Do we need to add an option to cover the two-population special case? What do you think the right behaviour is?

  3. petrelharp commented on Jun 12, 2019

    @petrelharp
    Contributor

    Ah! I implemented only pairwise Fst (but I think as you have described). We should extend it to be able to do Fst with an arbitrary number of populations. Would either of you, @GertjanBisschop or @KLohse, want to take a stab at this? To see what the indexes argument does, check out the documentation - it'd be great to have someone else see if it explains things well enough.

  4. GertjanBisschop commented on Jun 12, 2019

    @GertjanBisschop
    Member
  5. petrelharp commented on Jun 12, 2019

    @petrelharp
    Contributor

    The only thing though is that at the moment Fst cannot be calculated if no indexes are specified.

    Good point - the default should be to compute Fst between all the groups, i.e., a default of indexes=[list(range(len(sample_sets)))]? (once the ability to do this non-pairwise is added)

  6. jeromekelleher commented on Aug 13, 2019

    @jeromekelleher
    Member

    This has been implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions