def test_check_generation_number(self): ''' Load hutterites pedigree from file including the old_generation numbers given in that file. Check if each child's parents have the same old_generation #. Such an ordering cannot be guaranteed to exist for any DAG, but maybe here. ''' file_name = itu.HUTT_PED p = PedigreeOldStudyReader().read(file_name) # Check that generation order from study is consistent self.__check_generation_order_consistent(p, p.old_generation) self.__assert_max_generation_gap_equals(p, p.old_generation, 7) # Test our algorithm vs. old study algorithm without alien node alignment. Only # a single node should be different (an alien, 999999981) depth = pt.node_depth(p.graph, max_generation_gap=0) self.__test_generation_order_differs_by(p, depth, 1) self.__assert_max_generation_gap_equals(p, depth, 10) # Test depth calculation with a sufficiently enough max generation gap between parent # and child, as is implicitly assumed in Gaixin's and Mark's old study code depth = pt.node_depth(p.graph, max_generation_gap=8) self.__test_generation_order_differs_by(p, depth, 0) self.__assert_max_generation_gap_equals(p, depth, 7) # With alien alignment and our default, smaller max generation gap, check that our # generation order is consistent, but it should be quite different than the old study's depth = pt.node_depth(p.graph) self.__test_generation_order_differs_by(p, depth, 19) # Our order almost attained the requested (default) max generation depth of 3 self.__assert_max_generation_gap_equals(p, depth, 4) '''
def _layout_positions(g, g_extended=None): '''Return a dictionary that maps pedigree nodes to graph layout positions (x,y). Uses a layered spring model. Capable of handling both normal and extended pedigree graphs.''' g_extended = g_extended if g_extended else g # x-positions: spring model L = laplacian(g_extended, dtype=np.float) [_, v] = eigsh(L, 2, which='SM') x = v[:, 1] # Compute depths based on -original- graph y = pt.node_depth(g) for node in g_extended.nodes_iter(): # Marriage node: 0.5 above child depth. Note that marriage nodes must have children if node < 0: y[node] = y[g_extended.successors_iter(node).next()] - 0.5 ymax = max(d for d in y.itervalues()) # Reverse the y-axis (generation 0 on top) return dict(zip(g_extended.nodes_iter(), zip(x, ((ymax - y[node]) for node in g_extended.nodes_iter()))))
def _layout_positions(g, g_extended=None): '''Return a dictionary that maps pedigree nodes to graph layout positions (x,y). Uses a layered spring model. Capable of handling both normal and extended pedigree graphs.''' g_extended = g_extended if g_extended else g # x-positions: spring model L = laplacian(g_extended, dtype=np.float) [_, v] = eigsh(L, 2, which='SM') x = v[:, 1] # Compute depths based on -original- graph y = pt.node_depth(g) for node in g_extended.nodes_iter(): # Marriage node: 0.5 above child depth. Note that marriage nodes must have children if node < 0: y[node] = y[g_extended.successors_iter(node).next()] - 0.5 ymax = max(d for d in y.itervalues()) # Reverse the y-axis (generation 0 on top) return dict( zip(g_extended.nodes_iter(), zip(x, ((ymax - y[node]) for node in g_extended.nodes_iter()))))