neuron.py 文件源码

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

项目:SyConn 作者: StructuralNeurobiologyLab 项目源码 文件源码
def get_annotation_branch_lengths(annotation):
    """
    Fragments an annotation into pieces at every branch point - remaining
    lonely nodes are deleted. Branch nodes are simply deleted. The lengths of
    the resulting fragments are then returned.

    WARNING: THIS FUNCTION IS REALLY SLOW FOR SOME REASONS I DO NOT FULLY
    UNDERSTAND AT THE MOMENT, PROBABLY OBJECT COPY RELATED

    :param annotation:
    :return: list of branch lengths in um
    """

    # this is necessary to avoid trouble because of in place modifications
    anno = copy.deepcopy(annotation)
    nx_graph = su.annotation_to_nx_graph(anno)

    branches = list({k for k, v in nx_graph.degree().iteritems() if v > 2})
    nx_graph.remove_nodes_from(branches)
    lonely = list({k for k, v in nx_graph.degree().iteritems() if v == 0})
    nx_graph.remove_nodes_from(lonely)

    ccs = list(nx.connected_component_subgraphs(nx_graph))

    lengths = [cc.size(weight='weight') / 1000. for cc in ccs]
    return lengths
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号