# Path: pydigree/common.py
# def table(seq):
#     """
#     For each unique value in seq, runs count() on it. Returns a dictionary in
#     the form of {value1: count, value2: count}.
# 
#     :param seq: Values to make a table of
# 
#     :rtype: dict
#     """
#     seq = [x for x in seq]
#     keys = set(seq)
#     return dict([(k, seq.count(k)) for k in keys])


import pandas as pd
from itertools import chain
from operator import add
from functools import reduce
from pydigree.common import table

    def allele_frequency(self, location, allele, constraint=None):
        """
        Returns the frequency (as a percentage) of an allele in this population

        :param location: the locus to be evaluated
        :param allele: the allele to be counted
        :param constraint: Function that acts on an individual. If
            constraint(individual) can evaluate as True that person is included
        
        :type constraint: callable
        :rtype: float 
        """
        alleles = self.allele_list(location, constraint=constraint)
        freqtab = table(alleles)
        if allele not in freqtab:
            return 0
        return freqtab[allele] / float(len(alleles))

    def major_allele(self, location, constraint=None):
        """
        Returns the major (most common) allele in this population at a locus.

        
        :param location: the position to find the major allele at
        :param constraint: a constraint (see population.alleles)

        :returns: the major allele at a locus 
        """
        alleles = self.allele_list(location, constraint=constraint)

# Path: pydigree/common.py
# def table(seq):
#     """
#     For each unique value in seq, runs count() on it. Returns a dictionary in
#     the form of {value1: count, value2: count}.
# 
#     :param seq: Values to make a table of
# 
#     :rtype: dict
#     """
#     seq = [x for x in seq]
#     keys = set(seq)
#     return dict([(k, seq.count(k)) for k in keys])


# Path: pydigree/individualcontainer.py
import pandas as pd
from itertools import chain
from operator import add
from functools import reduce
from pydigree.common import table


    def allele_frequency(self, location, allele, constraint=None):
        """
        Returns the frequency (as a percentage) of an allele in this population

        :param location: the locus to be evaluated
        :param allele: the allele to be counted
        :param constraint: Function that acts on an individual. If
            constraint(individual) can evaluate as True that person is included
        
        :type constraint: callable
        :rtype: float 
        """
        alleles = self.allele_list(location, constraint=constraint)
        freqtab = table(alleles)
        if allele not in freqtab:
            return 0
        return freqtab[allele] / float(len(alleles))

    def major_allele(self, location, constraint=None):
        """
        Returns the major (most common) allele in this population at a locus.

        
        :param location: the position to find the major allele at
        :param constraint: a constraint (see population.alleles)

        :returns: the major allele at a locus 
        """
        alleles = self.allele_list(location, constraint=constraint)

        freqtab = table(alleles)