示例#1
0
def paths_through_ancestor(ind1, ind2, ancestor):
    """
    Returns a list of paths through the pedigree between ind1 and ind2
    that pass through a specific ancestor.
    """
    paths = []
    ups = path_downward(ancestor, ind1)
    downs = path_downward(ancestor, ind2)
    for u in ups:
        for d in downs:
            # Often you get paths that go up and then come straight
            # back down, going through ind1. We dont want those and we're
            # not going to return them in the paths.
            if u[1] == d[1]:
                continue
            # Since you're pathing downward in both partial paths through
            # the common ancestor, the path from ind1 -> ancestor needs to
            # be reversed. Then we skip the first element of the downward
            # path because its the last element of the upward path.
            path = u[::-1] + d[1:]
            # In sort of a generalization of the first check for the up
            # and straight-back-down scenario, valid paths can only go
            # through an individual ONCE. So if any path has an individual
            # more than once, we'll skip that path entirely
            pt = table(path)
            if [pt[k] for k in pt if pt[k] > 1]:
                continue
            paths.append(path)
    return paths
示例#2
0
    def genotype_missingness(self, location):
        """
        Returns the percentage of individuals in the population missing a
        genotype at location.

        Returns: A float
        """
        genotypes = [x.get_genotype(location) for x in self.individuals]
        tab = table(genotypes)
        return tab[missing_genotype] / float(len(genotypes))
示例#3
0
    def genotype_missingness(self, location):
        """
        Returns the percentage of individuals in the population missing a
        genotype at location.

        Returns: A float
        """
        missing_genotype = (0, 0)
        genotypes = [x.get_genotype(location) for x in self.individuals]
        tab = table(genotypes)
        return tab[missing_genotype] / float(len(genotypes))
示例#4
0
    def bit_size(self):
        """
        Returns the bit size of the pedigree. The bitsize is defined as 2*n-f
        where n is the number of nonfounders and f is the number of founders.
        This represents the number of bits it takes to represent the
        inheritance vector in the Lander-Green algorithm.

        :returns: bit size
        :rtype: pedigree
        """
        t = table([x.is_founder() for x in self.individuals])
        return 2 * t[False] - t[True]
示例#5
0
    def allele_frequency(self, location, allele, constraint=None):
        """
        Returns the frequency (as a percentage) of an allele in this population

        The argument constraint is a function that acts on an individual. If
        constraint(individual) can evaluate as True that person is included

        Returns: a float 
        """
        alleles = self.allele_list(location, constraint=constraint)
        freqtab = table(alleles)
        if allele not in freqtab:
            return 0
        return freqtab[allele] / float(len(alleles))
示例#6
0
    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)
        # Reverse sort the table by the count of alleles, and return the first
        # item's first item (i.e. the allele label)
        return sorted(freqtab.items(), key=lambda x: x[1], reverse=True)[0][0]
    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)
        # Reverse sort the table by the count of alleles, and return the first
        # item's first item (i.e. the allele label)
        return sorted(freqtab.items(), key=lambda x: x[1], reverse=True)[0][0]
示例#8
0
    def major_allele(self, location, constraint=None):
        """
        Returns the major allele in this population at a locus.

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

        Returns: the major allele at a locus (type depends on how genotypes 
                    are stored)
        """
        alleles = self.allele_list(location, constraint=constraint)
        freqtab = table(alleles)
        # Reverse sort the table by the count of alleles, and return the first
        # item's first item (i.e. the allele label)
        return sorted(freqtab.items(), key=lambda x: x[1], reverse=True)[0][0]
示例#9
0
    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))
示例#10
0
    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))
示例#11
0
def paths_through_ancestor(ind1, ind2, ancestor):
    """
    Finds all paths through a genealogy between ind1 and ind2
    that pass through a specific ancestor.

    :param ind1: the first endpoint
    :param ind2: the other endpoint
    :param ancestor: the ancestor to pass through
    :type ind1: Individual
    :type ind2: Individual
    :type ancestor: Individual

    :returns: identified paths
    :rtype: list of lists of Individuals 
    """
    identified_paths = []
    ups = path_downward(ancestor, ind1)
    downs = path_downward(ancestor, ind2)
    for u in ups:
        for d in downs:
            # Often you get paths that go up and then come straight
            # back down, going through ind1. We dont want those and we're
            # not going to return them in the paths.
            if u[1] == d[1]:
                continue
            # Since you're pathing downward in both partial paths through
            # the common ancestor, the path from ind1 -> ancestor needs to
            # be reversed. Then we skip the first element of the downward
            # path because its the last element of the upward path.
            path = u[::-1] + d[1:]
            # In sort of a generalization of the first check for the up
            # and straight-back-down scenario, valid paths can only go
            # through an individual ONCE. So if any path has an individual
            # more than once, we'll skip that path entirely
            pt = table(path)
            if [pt[k] for k in pt if pt[k] > 1]:
                continue
            identified_paths.append(path)
    return identified_paths
示例#12
0
        continue

    for locidx, markerlabel in enumerate(chromobj.labels):

        if granges:
            inrange = any(x[1] <= chromobj.physical_map[locidx] <= x[2]
                          for x in granges)
            if not inrange:
                continue

        locus = chromidx, locidx

        if args.only is not None and markerlabel not in only:
            continue

        freqs = table(peds.allele_list(locus))
        alleles = [x[0]
                   for x in sorted(list(freqs.items()),
                                   key=lambda x: x[1],
                                   reverse=True)]

        if len(alleles) == 1:
            print('Monomorphic genotype: {}'.format(markerlabel))
            if args.interact:
                import IPython
                IPython.embed()
            continue

        maj_allele = alleles[0]
        minor_alleles = [allele for allele in alleles[1:] if allele != '']
        for min_allele in minor_alleles:
示例#13
0
        continue

    for locidx, markerlabel in enumerate(chromobj.labels):

        if granges:
            inrange = any(x[1] <= chromobj.physical_map[locidx] <= x[2]
                          for x in granges)
            if not inrange:
                continue

        locus = chromidx, locidx

        if args.only is not None and markerlabel not in only:
            continue

        freqs = table(peds.allele_list(locus))
        alleles = [x[0]
                   for x in sorted(list(freqs.items()),
                                   key=lambda x: x[1],
                                   reverse=True)]

        if len(alleles) == 1:
            print('Monomorphic genotype: {}'.format(markerlabel))
            if args.interact:
                import IPython
                IPython.embed()
            continue

        maj_allele = alleles[0]
        minor_alleles = [allele for allele in alleles[1:] if allele != '']
        for min_allele in minor_alleles: