def test_surrogate_parents(self): '''Find all surrogate parents of a node.''' p = itu.Templates.problem_hut().pedigree g = p.graph assert_equal(pt.surrogate_parents(g, 1298, 0), {}, 'Unexpected surrogate parent set') assert_equal(pt.surrogate_parents(g, 1298, 1), OrderedDict([(1480, 1), (1719, 1), (1217, 1), (1412, 1), (1413, 1)]), 'Unexpected surrogate parent set') assert_equal(pt.surrogate_parents(g, 1298, 2), OrderedDict([(1480, 1), (1719, 1), (2028, 2), (1829, 2), (2064, 2), (2082, 2), (1217, 1), (1412, 1), (1413, 1), (2627, 2), (2628, 2), (2629, 2), (2630, 2), (2755, 2), (2756, 2), (1756, 2)]), 'Unexpected surrogate parent set') assert_equal(pt.surrogate_parents(g, 1298, 3), OrderedDict([(1480, 1), (1719, 1), (2028, 2), (1829, 2), (2064, 2), (2082, 2), (2180, 3), (2158, 3), (2155, 3), (2070, 3), (2275, 3), (2278, 3), (2202, 3), (2171, 3), (1217, 1), (1412, 1), (1413, 1), (3236, 3), (2627, 2), (2628, 2), (2629, 2), (2630, 2), (617, 3), (1188, 3), (2755, 2), (1110, 3), (2756, 2), (1756, 2), (2982, 3), (1482, 3), (1484, 3), (1486, 3), (1487, 3), (1491, 3), (1492, 3), (2644, 3), (1728, 3), (134, 3), (1735, 3), (2635, 3), (2770, 3), (1749, 3), (1751, 3), (1752, 3), (1721, 3), (1754, 3), (1724, 3), (1726, 3)]), 'Unexpected surrogate parent set') assert_equal(pt.surrogate_parents(g, 1298, 3, min_depth=2), OrderedDict([(2028, 2), (1829, 2), (2064, 2), (2082, 2), (2180, 3), (2158, 3), (2155, 3), (2070, 3), (2275, 3), (2278, 3), (2202, 3), (2171, 3), (3236, 3), (2627, 2), (2628, 2), (2629, 2), (2630, 2), (617, 3), (1188, 3), (2755, 2), (1110, 3), (2756, 2), (1756, 2), (2982, 3), (1482, 3), (1484, 3), (1486, 3), (1487, 3), (1491, 3), (1492, 3), (2644, 3), (1728, 3), (134, 3), (1735, 3), (2635, 3), (2770, 3), (1749, 3), (1751, 3), (1752, 3), (1721, 3), (1754, 3), (1724, 3), (1726, 3)]), 'Unexpected surrogate parent set')
def test_surrogate_parents(self): '''Find all surrogate parents of a node.''' p = itu.Templates.problem_hut().pedigree g = p.graph assert_equal(pt.surrogate_parents(g, 1298, 0), {}, 'Unexpected surrogate parent set') assert_equal( pt.surrogate_parents(g, 1298, 1), OrderedDict([(1480, 1), (1719, 1), (1217, 1), (1412, 1), (1413, 1)]), 'Unexpected surrogate parent set') assert_equal( pt.surrogate_parents(g, 1298, 2), OrderedDict([(1480, 1), (1719, 1), (2028, 2), (1829, 2), (2064, 2), (2082, 2), (1217, 1), (1412, 1), (1413, 1), (2627, 2), (2628, 2), (2629, 2), (2630, 2), (2755, 2), (2756, 2), (1756, 2)]), 'Unexpected surrogate parent set') assert_equal( pt.surrogate_parents(g, 1298, 3), OrderedDict([(1480, 1), (1719, 1), (2028, 2), (1829, 2), (2064, 2), (2082, 2), (2180, 3), (2158, 3), (2155, 3), (2070, 3), (2275, 3), (2278, 3), (2202, 3), (2171, 3), (1217, 1), (1412, 1), (1413, 1), (3236, 3), (2627, 2), (2628, 2), (2629, 2), (2630, 2), (617, 3), (1188, 3), (2755, 2), (1110, 3), (2756, 2), (1756, 2), (2982, 3), (1482, 3), (1484, 3), (1486, 3), (1487, 3), (1491, 3), (1492, 3), (2644, 3), (1728, 3), (134, 3), (1735, 3), (2635, 3), (2770, 3), (1749, 3), (1751, 3), (1752, 3), (1721, 3), (1754, 3), (1724, 3), (1726, 3)]), 'Unexpected surrogate parent set') assert_equal( pt.surrogate_parents(g, 1298, 3, min_depth=2), OrderedDict([(2028, 2), (1829, 2), (2064, 2), (2082, 2), (2180, 3), (2158, 3), (2155, 3), (2070, 3), (2275, 3), (2278, 3), (2202, 3), (2171, 3), (3236, 3), (2627, 2), (2628, 2), (2629, 2), (2630, 2), (617, 3), (1188, 3), (2755, 2), (1110, 3), (2756, 2), (1756, 2), (2982, 3), (1482, 3), (1484, 3), (1486, 3), (1487, 3), (1491, 3), (1492, 3), (2644, 3), (1728, 3), (134, 3), (1735, 3), (2635, 3), (2770, 3), (1749, 3), (1751, 3), (1752, 3), (1721, 3), (1754, 3), (1724, 3), (1726, 3)]), 'Unexpected surrogate parent set')
def in_neighborhood(sample, problem, min_path_length, max_path_length, fill_threshold): '''Create a RelativeCollection with genotype relatives filled to fill_threshold of at most d=max_path_length proximity.''' genotyped_relatives = dict((x, y) for (x, y) in surrogate_parents(problem.pedigree.graph, sample, min_depth=min_path_length, max_depth=max_path_length).iteritems() if problem.is_genotyped(x)) f = problem.fill_fraction(sample=genotyped_relatives.keys()) r = RelativeCollection(sample) if f.size: filled = dict(zip(f[:, 0].astype('int'), f[:, 1])) r += [(x, y) for (x, y) in genotyped_relatives.iteritems() if filled[x] >= fill_threshold] # Sort by ascending priority (increasing depth, then decreasing fill %) # return a[np.lexsort((a[:, 1], -a[:, 2]))] if a.size else None return r
def in_neighborhood(sample, problem, min_path_length, max_path_length, fill_threshold): '''Create a RelativeCollection with genotype relatives filled to fill_threshold of at most d=max_path_length proximity.''' genotyped_relatives = dict((x, y) for ( x, y) in surrogate_parents(problem.pedigree.graph, sample, min_depth=min_path_length, max_depth=max_path_length).iteritems() if problem.is_genotyped(x)) f = problem.fill_fraction(sample=genotyped_relatives.keys()) r = RelativeCollection(sample) if f.size: filled = dict(zip(f[:, 0].astype('int'), f[:, 1])) r += [(x, y) for (x, y) in genotyped_relatives.iteritems() if filled[x] >= fill_threshold] # Sort by ascending priority (increasing depth, then decreasing fill %) # return a[np.lexsort((a[:, 1], -a[:, 2]))] if a.size else None return r