graph_utils.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:PyMaid 作者: schlegelp 项目源码 文件源码
def dist_between(x, a, b):
    """ Returns the geodesic distance between nodes in nanometers.

    Parameters
    ----------
    x :             {CatmaidNeuron, CatmaidNeuronList}
                    Neuron containing the nodes
    a, b :          treenode IDs
                    Treenodes to check.

    Returns
    -------
    int
                    distance in nm

    See Also
    --------
    :func:`~pymaid.distal_to`
        Check if a node A is distal to node B.
    :func:`~pymaid.geodesic_matrix`
        Get all-by-all geodesic distance matrix.

    """

    if isinstance( x, core.CatmaidNeuronList ):
        if len(x) == 1:
            x = x[0]
        else:
            raise ValueError('Need a single CatmaidNeuron')
    elif isinstance( x, core.CatmaidNeuron ):
        pass
    else:
        raise ValueError('Unable to process data of type {0}'.format(type(x)))

    try:
        _ = int(a)
        _ = int(b)
    except:
        raise ValueError('a, b need to be treenode IDs')  


    return int( nx.algorithms.shortest_path_length( g.to_undirected(as_view=True), 
                                                    a, b, 
                                                    weight='weight') )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号