Skip to content

get_border_crosser_links

Get the links that cross the border between the ROI and interface cells.

Parameters:

Name Type Description Default
union_weights W

The union of the ROI and interface weights. NOTE: contains links between ROI & interface cells.

required
roi_weights W

The ROI weights. NOTE: contains only links between ROI cells.

required
iface_weights W

The interface weights. NOTE: contains only links between interface cells.

required
only_border_crossers bool

Whether to return only the links that cross the border between the ROI and interface cells or all neighbors of the node that has a border crossing link. This includes also the liks that do not cross the border. By default True.

True

Returns:

Name Type Description
W W

The links that cross the border between the ROI and interface cells.

Source code in cellseg_gsontools/graphs.py
def get_border_crosser_links(
    union_weights: W,
    roi_weights: W,
    iface_weights: W,
    only_border_crossers: bool = True,
) -> W:
    """Get the links that cross the border between the ROI and interface cells.

    Parameters:
        union_weights (W):
            The union of the ROI and interface weights. NOTE: contains links between ROI
            & interface cells.
        roi_weights (W):
            The ROI weights. NOTE: contains only links between ROI cells.
        iface_weights (W):
            The interface weights. NOTE: contains only links between interface cells.
        only_border_crossers (bool, optional):
            Whether to return only the links that cross the border between the ROI and
            interface cells or all neighbors of the node that has a border crossing link.
            This includes also the liks that do not cross the border. By default True.

    Returns:
        W:
            The links that cross the border between the ROI and interface cells.
    """
    # loop the nodes in the union graph and check if they are border crossing links
    graph = {}
    for node, neigh in union_weights.neighbors.items():
        is_roi_node = node in roi_weights.neighbors.keys()
        is_iface_node = node in iface_weights.neighbors.keys()

        neighbors = []
        for n in neigh:
            is_roi_neigh = n in roi_weights.neighbors.keys()
            is_iface_neigh = n in iface_weights.neighbors.keys()
            if (is_roi_node and is_iface_neigh) or (is_iface_node and is_roi_neigh):
                # return all neighbors if requested
                if not only_border_crossers:
                    neighbors.extend(neigh)
                    break
                else:
                    neighbors.append(n)

        graph[node] = neighbors

    return W(graph, silence_warnings=True)