Skip to content

Double Loop in RASCaltulator can be dramatically sped up #3

@stschiff

Description

@stschiff

One of the critical speed-bottlenecks in RASCalculator is arguably the double loop that happens for every site of the input file:

RAStools/RASCalculator.py

Lines 134 to 135 in a9c66c6

for Lftidx, leftPop in enumerate(LeftPops):
for Tstidx, testPop in enumerate(TestPops):

Effectively, this means that the algorithm scales quadratically with the number of populations (or individuals, for ungrouped input).

I think we can speed this up to scale effectively linear, as long as the allele frequency is low. The idea is that within the first loop, we first ask whether there is any derived allele frequency in the first population. If not, we just move on to the next outer loop item, because we know that all internal loop items would just add zero.

So I'm proposing to change this

 for Lftidx, leftPop in enumerate(LeftPops):
        for Tstidx, testPop in enumerate(TestPops):

to this:

 for Lftidx, leftPop in enumerate(LeftPops):
    if afDict[leftPop] > 0:
        for Tstidx, testPop in enumerate(TestPops):

or something to that effect.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions