Esempio n. 1
0
def gen_FE_norms(coordinates, faces, edges, vert_to_face):
    """
    Generate vectors normal to Faces and Edges.

    Parameters
    ----------
    coordinates : numpy.ndarray
        Vx3 array of spatial coordinates of vertices,
        V = number of vertices
    faces : list
        Fx2 list, where F is the number of faces.
        The first column details how many vertices the face has.
        The second column details the vertex IDs of the face.
    edges : numpy.ndarray
        Ex2 array where each row corresponds to one edge,
        denoting the vertices being connected. 1st column > 2nd column
    vert_to_face : list
        V-long list, each row containing a list of the face IDs the
        particular vertex belongs to.

    Returns
    -------
    face_norms
        Fx3 matrix containing outward normal for each face.
    edge_norms
        Ex3 matrix containing outward normal for each edge.
    """

    # Initialize
    coordinates = np.array(coordinates)
    face_norms = np.zeros(shape=(len(faces), 3))
    edge_norms = np.zeros(shape=(len(edges), 3))

    for face_ID in range(len(faces)):
        curr_face = np.array(faces[face_ID])  # current face
        curr_coords = coordinates[curr_face[0:3]]  # coordinates of face verts

        a_vec = curr_coords[0] - curr_coords[1]
        b_vec = curr_coords[2] - curr_coords[1]

        normal_vec = np.cross(b_vec, a_vec)  # cross-product for normal

        # normalize
        face_norms[face_ID] = normal_vec / np.linalg.norm(normal_vec)

    for edge_ID in range(len(edges)):
        edge_bgn = edges[edge_ID][0]
        edge_fin = edges[edge_ID][1]

        bordering_faces = intersect_lists(vert_to_face[edge_bgn],
                                          vert_to_face[edge_fin])

        normal_vec = face_norms[bordering_faces[0]] + \
            face_norms[bordering_faces[1]]

        # normalize
        edge_norms[edge_ID] = normal_vec / np.linalg.norm(normal_vec)

    return edge_norms
Esempio n. 2
0
def get_scaf_nick_pos(edges, route_real, edge_length_vec):
    first_node_in_route = route_real[0]
    second_node_in_route = route_real[1]
    min_node = min(first_node_in_route, second_node_in_route)
    max_node = max(first_node_in_route, second_node_in_route)

    edges = np.array(edges)
    from_nodes = np.where(edges[:, 0] == max_node)[0]
    to_nodes = np.where(edges[:, 1] == min_node)[0]

    # TODO: assured to always have 1 result?
    first_edge = intersect_lists(from_nodes, to_nodes)[0]

    first_edge_length = edge_length_vec[first_edge]
    if first_edge_length < 42:  # == 31
        scaf_nick_pos = 16
    else:
        scaf_nick_pos = 19

    return scaf_nick_pos
Esempio n. 3
0
 def test_input_can_be_numpy_array(self):
     a = np.array([1, 2, 3])
     b = np.array([2, 3, 4, 5])
     y = intersect_lists(a, b)
     assert y == [2, 3]
Esempio n. 4
0
 def test_full_match(self):
     a = [1, 2, 3]
     b = [1, 2, 3]
     y = intersect_lists(a, b)
     assert y == [1, 2, 3]
Esempio n. 5
0
 def test_partial_match(self):
     a = [1, 2]
     b = [2, 3]
     y = intersect_lists(a, b)
     assert y == [2]
Esempio n. 6
0
 def test_no_match(self):
     a = [1]
     b = [2, 3]
     y = intersect_lists(a, b)
     assert y == []
Esempio n. 7
0
def assign_scaf_to_edge(edges, num_edges, edge_type_mat, edge_bgn_vec,
                        edge_fin_vec, edge_type_vec):
    """
    # Assign enumerated scaffold bases to edges. Create vectors for each duplex
    # in each edge, identify to which scaffold base each edge base corresponds
    # Inputs: edges = Ex2 matrix where each row corresponds to one edge,
    #           denoting the vertices being connected. 1st column > 2nd column
    #         num_edges = number of edges, E
    #         edge_length_mat_full = VxV sparse matrix of edge lengths
    #         edge_bgn_vec = row vector of scaff nt IDs at which edge begins
    #         edge_fin_vec = row vector of scaff nt IDs at which edge finishes
    #         edge_type_vec = row vector of edge types, corresponding to
    #                          edge_length_mat_full
    #   2 is spanning tree edge: DX edge with 0 scaffold crossovers
    #  -3 is half of a non-spanning tree edge, connecting to vertex at 3' end
    #  -5 is half of a non-spanning tree edge, connecting to vertex at 5' end
    # Outputs: scaf_to_edge = Ex2 cell array, where each row corresponds to one
    #            edge, 1st column is duplex from low ID to high ID vertex,
    #            2nd column is from high to low. Each element is a row vector
    #            containing the scaffold base IDs in order on that duplex.
    ###########################################################################
    # by Sakul Ratanalert, MIT, Bathe Lab, 2016
    #
    # Copyright 2016. Massachusetts Institute of Technology. Rights Reserved.
    # M.I.T. hereby makes following copyrightable material available to the
    # public under GNU General Public License, version 2 (GPL-2.0). A copy of
    # this license is available at https://opensource.org/licenses/GPL-2.0
    ###########################################################################
    """

    scaf_to_edge = []
    for edge_ID in range(num_edges):  # TODO: convert to `for edge in edges:`
        # first column low to high, second column high to low
        row = [None, None]
        for high_to_low in [1, 2]:  # for each duplex direction on edge
            col = 2 - high_to_low

            if high_to_low == 1:  # high to low 5' to 3'
                edge_bgn = edges[edge_ID][0]
                edge_fin = edges[edge_ID][1]
            else:  # low_to_high 5' to 3'
                edge_bgn = edges[edge_ID][1]
                edge_fin = edges[edge_ID][0]

            edge_type = edge_type_mat[edge_bgn][edge_fin]['type']
            if edge_type == 2:  # tree edge  # TODO: extract into constant
                bases = intersect_lists(find(edge_bgn_vec, edge_bgn),
                                        find(edge_fin_vec, edge_fin))
            else:  # non-tree edge
                bases_all = intersect_lists(find(edge_bgn_vec, edge_bgn),
                                            find(edge_fin_vec, edge_fin))
                bases_5 = intersect_lists(bases_all, find(edge_type_vec, -5))
                bases_3 = intersect_lists(bases_all, find(edge_type_vec, -3))

                bases = bases_5 + bases_3

            row[col] = bases

        scaf_to_edge.append(row)

    return scaf_to_edge