예제 #1
0
 def test_matrices(self):
     '''Test adjacency and Laplacian matrix computation.'''
     # Load data from text file to compare with the load result
     p = itu.read_pedigree_from_test_file(itu.HUTT_PED)
     A = sym_adjacency(p.graph)
     L = laplacian(p.graph)
     assert not np.nonzero(A-A.T)[0], 'Adjacency matrix returned from sym_adjacency() should be symmetric'
     assert not np.nonzero(L-L.T)[0], 'Laplacian matrix should be symmetric'
     assert (abs(L.sum(axis=1)) < 1e-8).all(), 'Laplacian matrix should be zero-row-sum'
예제 #2
0
 def test_matrices(self):
     '''Test adjacency and Laplacian matrix computation.'''
     # Load data from text file to compare with the load result
     p = itu.read_pedigree_from_test_file(itu.HUTT_PED)
     A = sym_adjacency(p.graph)
     L = laplacian(p.graph)
     assert not np.nonzero(
         A - A.T
     )[0], 'Adjacency matrix returned from sym_adjacency() should be symmetric'
     assert not np.nonzero(L -
                           L.T)[0], 'Laplacian matrix should be symmetric'
     assert (abs(L.sum(axis=1)) <
             1e-8).all(), 'Laplacian matrix should be zero-row-sum'
예제 #3
0
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()))))
예제 #4
0
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()))))