Skip to content

Commit

Permalink
Use MorphIO Collections. (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
matz-e authored Oct 14, 2024
1 parent 7db6de1 commit 37f271c
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[MESSAGES CONTROL]
disable=fixme,invalid-name,len-as-condition,no-else-return,cyclic-import,import-outside-toplevel,useless-object-inheritance,self-assigning-variable,line-too-long,logging-fstring-interpolation,too-many-locals,too-many-branches,too-many-statements,no-member,unspecified-encoding,too-many-arguments,dangerous-default-value,similarities,too-many-lines,consider-using-f-string,broad-exception-caught,too-many-return-statements,eval-used
disable=fixme,invalid-name,len-as-condition,no-else-return,cyclic-import,import-outside-toplevel,useless-object-inheritance,self-assigning-variable,line-too-long,logging-fstring-interpolation,too-many-locals,too-many-branches,too-many-statements,no-member,unspecified-encoding,too-many-arguments,dangerous-default-value,similarities,too-many-lines,consider-using-f-string,broad-exception-caught,too-many-return-statements,eval-used,too-many-positional-arguments

[FORMAT]
# Maximum number of characters on a single line.
Expand Down
16 changes: 0 additions & 16 deletions connectome_manipulator/access_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

"""Collection of function for flexible nodes/edges access, to be used by model building and manipulation operations"""

from pathlib import Path

import numpy as np
import pandas as pd

Expand Down Expand Up @@ -57,20 +55,6 @@ def get_nodes(nodes, selection=None):
return result


def get_morphology_paths(nodes, selection, morpho_helper, extension="swc"):
"""Return paths to morphology files corresponding to `selection`.
Args:
nodes: a bluepysnap node set
selection (libsonata.Selection): a selection of nodes
morpho_helper: a bluepysnap MorphoHelper instance
extension (str): expected filetype extension of the morph file.
"""
morpho_dir = morpho_helper.get_morphology_dir(extension)
result = get_nodes(nodes, selection)
return [Path(morpho_dir, f"{name}.{extension}") for name in result[Node.MORPHOLOGY]]


def orientations(nodes, node_sel=None):
"""Node orientation(s) as a list of numpy arrays.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from bluepysnap.morph import MorphHelper
from bluepysnap.sonata_constants import Node
from morphio.mut import Morphology
from morphio import Collection
import numpy as np

from connectome_manipulator import access_functions
Expand Down Expand Up @@ -94,12 +94,13 @@ def __init__(self, nodes, writer=None, split_index=0, split_total=1):

def _get_tgt_morphs(self, morph_ext, tgt_node_sel):
"""Access function (incl. transformation!), using specified format (swc/h5/...)"""
morphology_paths = access_functions.get_morphology_paths(
self.nodes[1], tgt_node_sel, self.morpho_helper, morph_ext
)
morpho_dir = self.morpho_helper.get_morphology_dir(morph_ext)
collection = Collection(morpho_dir, [f".{morph_ext}"])
result = access_functions.get_nodes(self.nodes[1], tgt_node_sel)

morphologies = []
for mp in morphology_paths:
morphologies.append(Morphology(mp))
for morpho_name in result[Node.MORPHOLOGY]:
morphologies.append(collection.load(morpho_name, mutable=True))
return self._transform(morphologies, tgt_node_sel)

def _transform(self, morphs, node_sel):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def apply(
tgt_morphs = [None] * num_tgt

log.info(
f"Rewiring afferent {syn_class} connections to {num_tgt} ({amount_pct}%) of {len(tgt_sel)} target neurons in current split (total={num_tgt_total}, sel_src={sel_src}, sel_dest={sel_dest}, keep_indegree={keep_indegree}, gen_method={gen_method}, keep_conns={keep_conns}, reuse_conns={reuse_conns}, syn_pos_mode={syn_pos_mode}{', morph_ext=' + morph_ext if syn_pos_mode=='random' else ''}, rewire_mode={rewire_mode})"
f"Rewiring afferent {syn_class} connections to {num_tgt} ({amount_pct}%) of {len(tgt_sel)} target neurons in current split (total={num_tgt_total}, sel_src={sel_src}, sel_dest={sel_dest}, keep_indegree={keep_indegree}, gen_method={gen_method}, keep_conns={keep_conns}, reuse_conns={reuse_conns}, syn_pos_mode={syn_pos_mode}{', morph_ext=' + morph_ext if syn_pos_mode == 'random' else ''}, rewire_mode={rewire_mode})"
)

# Init/reset static variables (function attributes) related to generation methods which need only be initialized once [for better performance]
Expand Down
2 changes: 1 addition & 1 deletion connectome_manipulator/model_building/conn_props.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ def merge_uniq(vals, cnts):
conn_prop_model["p"][sidx, tidx, pidx] = c / np.sum(c)

log.info(
f"Interpolated {missing_list.shape[0]} missing values. Interpolation level counts: { {k: level_counts[k] for k in sorted(level_counts.keys())} }"
f"Interpolated {missing_list.shape[0]} missing values. Interpolation level counts: {{k: level_counts[k] for k in sorted(level_counts.keys())}}"
)

# Create model properties dictionary
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ include = 'connectome_manipulator\/.*\.py$|tests\/.*\.py$|doc\/source\/conf\.py$
pythonpath = [
"."
]

0 comments on commit 37f271c

Please sign in to comment.