Skip to content

Commit

Permalink
Use latest diameter-synthesis
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudon committed Aug 29, 2022
1 parent 44db085 commit d0eaafd
Show file tree
Hide file tree
Showing 19 changed files with 143 additions and 536 deletions.
8 changes: 2 additions & 6 deletions examples/rat_vaccum/luigi.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,17 @@ mtypes = ["L5_TPC:A", "L1_DAC"]
[GetSynthesisInputs]
# this fetches input data from a repository (one can also use local files)
url = git@bbpgitlab.epfl.ch:neuromath/synthdb.git
git_synthesis_input_path = insitu_synthesis_inputs/rat_sscx
git_synthesis_input_path = synthdb/insitu_synthesis_inputs/rat_sscx
local_synthesis_input_path = synthesis_input

[BuildMorphsDF]
# set the paths to input morphologies directories
neurondb_path = /gpfs/bbp.cscs.ch/project/proj83/home/gevaert/morph-release/morph_release_old_code-2020-07-27/output/06_RepairUnravel-asc/neuronDB.xml
morphology_dirs = {"morphology_path": "/gpfs/bbp.cscs.ch/project/proj83/home/gevaert/morph-release/morph_release_old_code-2020-07-27/output/06_RepairUnravel-asc", "morphology_path_h5": "/gpfs/bbp.cscs.ch/project/proj83/home/gevaert/morph-release/morph_release_old_code-2020-07-27/output/06_RepairUnravel-h5"}

[BuildSynthesisParameters]
# file in local_synthesis_input_path from GetSynthesisInput
input_tmd_parameters_path = tmd_specific_parameters.json

[VacuumSynthesize]
# number of cells to synthesize per mtype
n_cells = 10
n_cells = 30

[ValidateVacuumSynthesis]
# enable/disable the validation plots
Expand Down
4 changes: 2 additions & 2 deletions requirements/base.pip
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ neurom>=3,<4
pandas
placement_algorithm>=2.2.0
PyYAML
region_grower>=0.4.0
region_grower>=0.4.1
scipy
seaborn
tmd
neurots>=3.1,<4
neurots>=3.2,<4
tqdm
voxcell>=3,<4
bluepy-configfile
6 changes: 0 additions & 6 deletions src/synthesis_workflow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,3 @@
from morphio import SectionType

__version__ = pkg_resources.get_distribution("synthesis_workflow").version

STR_TO_TYPES = {
"basal": SectionType.basal_dendrite,
"apical": SectionType.apical_dendrite,
"axon": SectionType.axon,
}
2 changes: 1 addition & 1 deletion src/synthesis_workflow/fit_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
def _get_tmd_feature(input_population: Population, feature: str) -> np.array:
"""Returns a list of features using tmd."""
f = [
tmd.methods.get_persistence_diagram(n.apical[0], feature=feature)
tmd.methods.get_persistence_diagram(n.apical_dendrite[0], feature=feature)
for n in input_population.neurons
]

Expand Down
13 changes: 6 additions & 7 deletions src/synthesis_workflow/synthesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from tqdm import tqdm
from voxcell import CellCollection

from synthesis_workflow import STR_TO_TYPES
from synthesis_workflow.fit_utils import fit_path_distance_to_extent
from synthesis_workflow.tools import run_master

Expand All @@ -47,9 +46,9 @@ def _get_morph_class(path):
raise Exception("f{mtype} has not consistent morph_class, we stop here")

if morph_class[0] == "IN":
neurite_types[mtype] = ["basal"]
neurite_types[mtype] = ["basal_dendrite"]
if morph_class[0] == "PC":
neurite_types[mtype] = ["basal", "apical"]
neurite_types[mtype] = ["basal_dendrite", "apical_dendrite"]
return neurite_types


Expand Down Expand Up @@ -359,13 +358,13 @@ def rescale_neurites(morphology, neurite_type, target_length, scaling_mode="y"):
"""Rescale neurites of morphologies to match target length."""
max_length = -100
for neurite in morphology.root_sections:
if neurite.type == STR_TO_TYPES[neurite_type]:
if neurite.type.name == neurite_type:
max_length = max(max_length, get_max_len(neurite, mode=scaling_mode))

scale = target_length / max_length
if 0.1 < scale < 10:
for neurite in morphology.root_sections:
if neurite.type == STR_TO_TYPES[neurite_type]:
if neurite.type.name == neurite_type:
scale_section(
neurite,
ScaleParameters(),
Expand Down Expand Up @@ -540,9 +539,9 @@ def _process_scaling_rule(
)
continue
context = tmd_parameters[mtype].get("context_constraints", {})
neurite_type_params = context.get("apical", {}).get("extent_to_target", {})
neurite_type_params = context.get("apical_dendrite", {}).get("extent_to_target", {})
neurite_type_params.update({"slope": slope, "intercept": intercept})
context["apical"]["extent_to_target"] = neurite_type_params
context["apical_dendrite"]["extent_to_target"] = neurite_type_params
tmd_parameters[mtype]["context_constraints"] = context
L.debug(
"Fitting parameters for %s: slope=%s ; intercept=%s",
Expand Down
50 changes: 27 additions & 23 deletions src/synthesis_workflow/tasks/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,41 +97,45 @@ def output(self):
class DiametrizerConfig(luigi.Config):
"""Diametrizer configuration."""

model = luigi.Parameter(default="generic")
model = luigi.ChoiceParameter(default="simpler", choices=["generic", "simpler"])
terminal_threshold = luigi.FloatParameter(default=2.0)
taper_min = luigi.FloatParameter(default=-0.01)
taper_max = luigi.FloatParameter(default=1e-6)
asymmetry_threshold_basal = luigi.FloatParameter(default=1.0)
asymmetry_threshold_apical = luigi.FloatParameter(default=0.2)
neurite_types = luigi.ListParameter(default=["basal", "apical"])
neurite_types = luigi.ListParameter(default=["basal_dendrite", "apical_dendrite"])

trunk_max_tries = luigi.IntParameter(default=100)
n_samples = luigi.IntParameter(default=2)

def __init__(self, *args, **kwargs):
"""Init."""
super().__init__(*args, **kwargs)
self.config_model = {
"models": [self.model],
"neurite_types": self.neurite_types,
"terminal_threshold": self.terminal_threshold,
"taper": {"max": self.taper_max, "min": self.taper_min},
"asymmetry_threshold": {
"apical": self.asymmetry_threshold_apical,
"basal": self.asymmetry_threshold_basal,
},
}

self.config_diametrizer = {
"models": [self.model],
"neurite_types": self.neurite_types,
"asymmetry_threshold": {
"apical": self.asymmetry_threshold_apical,
"basal": self.asymmetry_threshold_basal,
},
"trunk_max_tries": self.trunk_max_tries,
"n_samples": self.n_samples,
}
self.config_model = {"models": [self.model], "neurite_types": self.neurite_types}
if self.model == "generic":
self.config_model.update(
{
"terminal_threshold": self.terminal_threshold,
"taper": {"max": self.taper_max, "min": self.taper_min},
"asymmetry_threshold": {
"apical_dendrite": self.asymmetry_threshold_apical,
"basal_dendrite": self.asymmetry_threshold_basal,
},
}
)

self.config_diametrizer = {"models": [self.model], "neurite_types": self.neurite_types}
if self.model == "generic":
self.config_diametrizer.update(
{
"asymmetry_threshold": {
"apical_dendrite": self.asymmetry_threshold_apical,
"basal_dendrite": self.asymmetry_threshold_basal,
},
"trunk_max_tries": self.trunk_max_tries,
"n_samples": self.n_samples,
}
)


class RunnerConfig(luigi.Config):
Expand Down
18 changes: 11 additions & 7 deletions src/synthesis_workflow/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -869,15 +869,17 @@ def _generate_synthetic_random_population(
"""Generate a synthetic population with random projections."""
files = []
y_synth = []
slope = tmd_parameters["context_constraints"]["apical"]["extent_to_target"]["slope"]
intercept = tmd_parameters["context_constraints"]["apical"]["extent_to_target"]["intercept"]
slope = tmd_parameters["context_constraints"]["apical_dendrite"]["extent_to_target"]["slope"]
intercept = tmd_parameters["context_constraints"]["apical_dendrite"]["extent_to_target"][
"intercept"
]
for i in range(nb):
tmp_name = str((Path(dir_path) / str(i)).with_suffix(".h5"))
files.append(tmp_name)
projection = np.random.randint(proj_min, proj_max)
y_synth.append(projection)
target_path_distance = get_path_distance_from_extent(slope, intercept, projection)
tmd_parameters["apical"].update(
tmd_parameters["apical_dendrite"].update(
{
"modify": {
"funct": scale_target_barcode,
Expand All @@ -904,7 +906,9 @@ def _get_fit_population(mtype, files, outlier_percentage, tmd_parameters, tmd_di
else:
return return_error + (f"No file to load for mtype='{mtype}'",)
if (
tmd_parameters.get("context_constraints", {}).get("apical", {}).get("extent_to_target")
tmd_parameters.get("context_constraints", {})
.get("apical_dendrite", {})
.get("extent_to_target")
is None
):
return return_error + (f"No fit for mtype='{mtype}'",)
Expand Down Expand Up @@ -959,7 +963,7 @@ def plot_path_distance_fits(
for mtype in morphs_df.mtype.unique().tolist()
if tmd_parameters.get(mtype, {})
.get("context_constraints", {})
.get("apical", {})
.get("apical_dendrite", {})
.get("extent_to_target")
is not None
]
Expand Down Expand Up @@ -1000,10 +1004,10 @@ def plot_path_distance_fits(
plt.plot(
[
get_path_distance_from_extent(
tmd_parameters[mtype]["context_constraints"]["apical"][
tmd_parameters[mtype]["context_constraints"]["apical_dendrite"][
"extent_to_target"
]["slope"],
tmd_parameters[mtype]["context_constraints"]["apical"][
tmd_parameters[mtype]["context_constraints"]["apical_dendrite"][
"extent_to_target"
]["intercept"],
i,
Expand Down
Loading

0 comments on commit d0eaafd

Please sign in to comment.