コード例 #1
0
ファイル: genedrop.py プロジェクト: jameshicks/pydigree
def sbool(ped, inds, loc):
    npairs = float(len(inds) * (len(inds) - 1) / 2)
    r = [
        ibs(j.get_genotype(loc, checkhasgeno=False), k.get_genotype(loc, checkhasgeno=False)) > 0
        for j, k in itertools.combinations(inds, 2)
    ]
    return sum(r) / npairs
コード例 #2
0
ファイル: simulation.py プロジェクト: y-chai/pydigree
 def _writeibd(self, replicatenumber):
     # Warning: Don't call this function! If the individuals in the pedigree dont have
     # LABEL genotypes, you're just going to get IBS configurations at each locus, not
     # actual IBD calculations.
     #
     # If you have data you want to identify IBD segments in, check
     # pydigree.sgs
     with smartopen(
             '{0}-{1}.ibd.gz'.format(self.label, replicatenumber + 1),
             'w') as of:
         for ped in self.template.pedigrees:
             for ind1, ind2 in combinations_with_replacement(
                     ped.individuals, 2):
                 identical = []
                 for chrom_idx in range(ind1.chromosomes.nchrom()):
                     if ind1 == ind2:
                         genos = zip(*ind1.genotypes[chrom_idx])
                         ibd = [2 * (x == y) for x, y in genos]
                     else:
                         genos1 = zip(*ind1.genotypes[chrom_idx])
                         genos2 = zip(*ind2.genotypes[chrom_idx])
                         ibd = [
                             ibs(g1, g2) for g1, g2 in zip(genos1, genos2)
                         ]
                     identical.extend(ibd)
                 outline = [ped.label, ind1.label, ind2.label] + identical
                 outline = ' '.join([str(x) for x in outline])
                 of.write('{}\n'.format(outline))
コード例 #3
0
def test_ibs():
    assert ibs( (2,2), (2,2) ) == 2
    assert ibs( (1,2), (1,2) ) == 2
    assert ibs( (2,1), (2,2) ) == 1
    assert ibs( (2,2), (2,1) ) == 1
    assert ibs( (1,1), (2,2) ) == 0
    assert ibs( (1,1), (0,0), missingval=64) == 64
    assert ibs( (1,1), (0,0) ) == None
    assert ibs( (0,0), (1,1) ) == None
コード例 #4
0
ファイル: genedrop.py プロジェクト: jameshicks/pydigree
def spairs(inds, loc):
    
    "Returns total number of IBD alleles"

    r = [ibs(j.get_genotype(loc, checkhasgeno=False),
             k.get_genotype(loc, checkhasgeno=False)) 
         for j, k in itertools.combinations(inds, 2)]
    return sum(r)
コード例 #5
0
def spairs(inds, loc):

    "Returns total number of IBD alleles"

    r = [
        ibs(j.get_genotype(loc, checkhasgeno=False),
            k.get_genotype(loc, checkhasgeno=False))
        for j, k in itertools.combinations(inds, 2)
    ]
    return sum(r)
コード例 #6
0
def sbool(inds, loc):

    "Returns proportion of pairs IBD != 0"

    npairs = float(len(inds) * (len(inds) - 1) / 2)
    r = [
        ibs(j.get_genotype(loc, checkhasgeno=False),
            k.get_genotype(loc, checkhasgeno=False)) > 0
        for j, k in itertools.combinations(inds, 2)
    ]
    return sum(r) / npairs
コード例 #7
0
ファイル: simulation.py プロジェクト: jameshicks/pydigree
 def _writeibd(self, replicatenumber):
     # Warning: Don't call this function! If the individuals in the pedigree dont have
     # LABEL genotypes, you're just going to get IBS configurations at each locus, not
     # actual IBD calculations.
     #
     # If you have data you want to identify IBD segments in, check
     # pydigree.sgs
     with smartopen('{0}-{1}.ibd.gz'.format(self.label, replicatenumber + 1), 'w') as of:
         for ped in self.template.pedigrees:
             for ind1, ind2 in combinations_with_replacement(ped.individuals, 2):
                 identical = []
                 for chrom_idx in range(ind1.chromosomes.nchrom()):
                     if ind1 == ind2:
                         genos = zip(*ind1.genotypes[chrom_idx])
                         ibd = [2 * (x == y) for x, y in genos]
                     else:
                         genos1 = zip(*ind1.genotypes[chrom_idx])
                         genos2 = zip(*ind2.genotypes[chrom_idx])
                         ibd = [ibs(g1, g2)
                                for g1, g2 in zip(genos1, genos2)]
                     identical.extend(ibd)
                 outline = [ped.label, ind1.label, ind2.label] + identical
                 outline = ' '.join([str(x) for x in outline])
                 of.write('{}\n'.format(outline))
コード例 #8
0
ファイル: genedrop.py プロジェクト: jameshicks/pydigree
def spairs(ped, inds, loc):
    r = [
        ibs(j.get_genotype(loc, checkhasgeno=False), k.get_genotype(loc, checkhasgeno=False))
        for j, k in itertools.combinations(inds, 2)
    ]
    return sum(r)
コード例 #9
0
ファイル: test_segments.py プロジェクト: y-chai/pydigree
s = pyd.sgs.sgs_population(ped, seed_size=ms)


with smartopen('{}-{}.ibd.gz'.format(prefix, replicate)) as f:
    trueibd = {}
    for line in f:
        fam, id1, id2, ibd_states = line.strip().split(None, 3)
        trueibd[frozenset({id1,id2})] = np.array([int(x) for x in ibd_states.split()])

a = intervals_to_array(s[frozenset({ped['7'],ped['8']})][0], ped.chromosomes[0].nmark())
b = trueibd[frozenset({'7','8'})]


genos1 = zip(*ped['7'].genotypes[0])
genos2 = zip(*ped['8'].genotypes[0])
identical = [ibs(x,y) for x,y in zip(genos1, genos2)]

from pydigree.common import table, runs


for start, stop in runs(list(a), lambda x: x>0, ms):
    print('Predicted segment: {}-{}'.format(start, stop))

print()

for start, stop in runs(list(b), lambda x: x>0, 2):
    print('True IBD Segment: {}-{}'.format(start, stop))

correct_calls = a == b
print('Accuracy: {}'.format(correct_calls.sum() / float(correct_calls.shape[0])))