Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New feature: split connectivity #92

Open
schlegelp opened this issue Apr 15, 2022 · 3 comments
Open

New feature: split connectivity #92

schlegelp opened this issue Apr 15, 2022 · 3 comments

Comments

@schlegelp
Copy link
Collaborator

Occasionally I find myself splitting neurons into axon & dendrites and then do the same with connectivity.

While this is perfectly possible using Navis, it requires a fair bit of boiler plate. Would be nice to have a dedicated function. Perhaps something more general like a function that takes pre->post synapses and neuron splits (axon/dendrite, by compartment, etc) and returns a compartmentalized connectivity table?

@clbarnes
Copy link
Collaborator

How about something like:

def split_connectivity(
    pre: list[TreeNeuron],
    post: list[TreeNeuron] | None,
    split_fn: Callable[[TreeNeuron], dict[Any, TreeNeuron]]
) -> pd.DataFrame:
    pre_compartments = dict()
    for n in pre:
        compartment_to_nrn = split_fn(n)
        for compartment, nrn in split_fn(n).items():
            pre_compartments[(n.id, compartment)] = nrn

    if post is None:
        post_compartments = pre_compartments
    else:
        ...
        # same as above

    data = pd.DataFrame(
        np.array([[None] * len(post_compartments)] * pre_compartments),
        index=pre_compartments.keys(),
        columns=post_compartments.keys()
    )

    for (pre_key, pre_nrn), (post_key, post_nrn) in itertools.product(pre_compartments.items(), post_compartments.items()):
        adj = make_connectivity_matrix(post_name, post_nrn)  # whatever the current function is called...
        data[pre_key, post_key] = adj
    return adj

I think the split_fn is the thing which saves the most boilerplate while providing a lot of flexibility in how people may want to split their neurons. We could always accept some magic strings to use e.g. the default split_axon_dendrite arguments.

@schlegelp
Copy link
Collaborator Author

Yes something along those lines is what I had in mind. It boils down to a three-step process:

  1. Associate synaptic connections with a node/vertex on the pre- and postsynaptic neuron, respectively. This step can be skipped if the connectivity data already has that info (e.g. with CATMAID data).
  2. Have a function that assigns compartments (e.g. 'axon' or 'dendrite').
  3. Divvy up the connectivity on the different compartments.

I would have probably gone for a class design to be even more flexible.

@clbarnes
Copy link
Collaborator

Usually in favour of using classes, so sure! It might need to be a little more complex than the above to handle "compartments" which aren't necessarily contiguous. You could build a TreeNeuron on top of a graph which is a forest but that would probably break some validation steps elsewhere. Probably better, as you say, to just label nodes and then treat labels as a compartment (if people want to handle e.g. multiple dendrites then they can just do "dendrite-1", "dendrite-2" etc. in their split function).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants