예제 #1
0
def update_with_slatkin_test(simconfig, s):
    """
    Takes an IndividualSampleClassified object, calculates the slatkin exact test for it,
    and updates the existing pergenerationstats_postclassification object.

    :param sample:
    :return:
    """
    class_counts = defaultdict(int)
    for indiv in s.sample:
        class_counts[indiv.classid] += 1

    counts = class_counts.values()

    (prob, theta) = montecarlo(simconfig.SLATKIN_MONTECARLO_REPLICATES, counts, len(counts))

    # find the proper pergeneration object for this sample, and add the slatkin result
    #
    record = data.PerGenerationStatsPostclassification.m.find(dict(
        classification_id=s.classification_id,
        simulation_run_id=s.simulation_run_id,
        simulation_time=s.simulation_time,
        replication=s.replication,
        sample_size=s.sample_size)).one()

    data.updateFieldPerGenerationStatsPostclassification(record._id, "class_neutrality_slatkin", prob )
import slatkin

counts = [8, 4, 3, 2, 2, 1, 1, 1, 1, 1, 1]

(prob, theta) = slatkin.montecarlo(100000, counts, len(counts))
print "prob: %s    theta: %s" % (prob, theta)

counts = [30, 62, 97, 15, 53, 18, 55, 35, 57, 14866,160, 439, 18, 356, 165, 40, 41, 14, 27, 36, 39, 23, 120, 209]
(prob, theta) = slatkin.montecarlo(100000, counts, len(counts))
print "prob: %s    theta: %s" % (prob, theta)


예제 #3
0
 def _slatkin_neutrality_for_classes(self, class_counts):
     (prob, theta) = montecarlo(self.simconfig.SLATKIN_MONTECARLO_REPLICATES, class_counts, len(class_counts))
     return prob
예제 #4
0
def slatkin_exact_test(count_list):
    (prob, theta) = slatkin.montecarlo(100000, count_list, len(count_list))
    #log.debug("slatkin prob: %s  theta: %s", prob, theta)
    return prob
#!/usr/bin/env python

from slatkin import montecarlo

counts = [8, 4, 3, 2, 2, 1, 1, 1, 1, 1, 1] 
numalleles = len(counts)

(prob,theta) = montecarlo(100000, counts, len(counts))

print "prob: %s    theta: %s" % (prob, theta)


counts2 = [91, 56, 27, 9, 7, 3, 1]

(prob, theta) = montecarlo(100000, counts2, len(counts2))

print "prob: %s    theta: %s" % (prob, theta)
예제 #6
0
 def _slatkin_neutrality_for_locus(self, trait_counts):
     (prob,
      theta) = montecarlo(self.simconfig.SLATKIN_MONTECARLO_REPLICATES,
                          trait_counts, len(trait_counts))
     return prob
예제 #7
0
 def _slatkin_neutrality_for_locus(self, trait_counts):
     (prob, theta) = montecarlo(self.simconfig.SLATKIN_MONTECARLO_REPLICATES, trait_counts, len(trait_counts))
     return prob