Skip to content

Commit

Permalink
Add alternative apical point definition
Browse files Browse the repository at this point in the history
* Modifies apical point distance to smoothed version
* Adds parameter 'has_apical_tuft' for apical trees
* Replaces definition of apical point for untufted cells
* If 'has_apical_tuft' is False, the 70% of total lenght is defined as apical point distance

Change-Id: Idb3c8e41c080235b963c435b9a6dc7c3d4449401
  • Loading branch information
lidakanari committed Mar 24, 2020
1 parent 02a171c commit 678cc5e
Show file tree
Hide file tree
Showing 16 changed files with 226 additions and 9 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
install_requires=[
'matplotlib>=1.3.1',
'morph-tool>=0.1.12',
'tmd>=2.0.5',
'tmd>=2.0.8',
'neurom @ git+https://git@github.com/BlueBrain/NeuroM.git@mut_morphio#egg=neurom-2.0.0',
'enum-compat>=0.0.1',
'scipy>=0.13.3',
Expand Down
1 change: 1 addition & 0 deletions tests/data/bio_gradient_path_params.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"tree_type": 3,
"step_size": {"norm":{"mean":1.0, "std":0.2}}},
"apical": {"metric":"path_distances",
"has_apical_tuft": true,
"randomness": 0.0,
"targeting": 0.2,
"radius": 0.3,
Expand Down
1 change: 1 addition & 0 deletions tests/data/bio_path_params.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"tree_type": 3,
"step_size": {"norm":{"mean":1.0, "std":0.2}}},
"apical": {"metric":"path_distances",
"has_apical_tuft": true,
"randomness": 0.0,
"targeting": 0.2,
"radius": 0.3,
Expand Down
1 change: 1 addition & 0 deletions tests/data/bio_radial_params.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"tree_type": 3,
"step_size": {"norm":{"mean":1.0, "std":0.2}}},
"apical": {"metric":"radial_distances",
"has_apical_tuft": true,
"randomness": 0.0,
"targeting": 0.2,
"radius": 0.3,
Expand Down
1 change: 1 addition & 0 deletions tests/data/dummy_params.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{ "apical": {
"branching_method": "directional",
"has_apical_tuft": true,
"growth_method": "tmd_apical",
"metric": "path_distances",
"modify": null,
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
[[126.09063428326819, 124.10453820759906],
[124.20069277059756, 121.37772119511102],
[123.74416841361185, 119.41444325764101],
[120.10109760888852, 117.54309257164775],
[123.21093463804773, 118.67947034305747],
[169.95419098851545, 164.44511682573588],
[239.46781294675202, 217.46604923769462],
[1444.4331305221815, 1436.9670665328726],
[1230.0921577617214, 1227.8990257936548],
[1274.7173775623814, 1272.8294364521194],
[1275.1239359450242, 1273.2529208896842],
[1260.724389194065, 1257.9245813255784],
[1257.7334009255328, 1255.9411838037104],
[1259.3861179022706, 1257.5656299333928],
[1271.4091370080346, 1268.2266098287262],
[1269.9102936839406, 1265.8231884764332],
[1265.7990401353538, 1263.4905051106596],
[1264.6081996268763, 1261.5055950588915],
[1262.6352914912022, 1259.4235120081821],
[1259.2447755298722, 1257.2257756719134],
[1249.4145924983286, 1247.536674673896],
[1248.1485284370349, 1245.5496760881113],
[1232.3336848357708, 1230.0064429239808],
[1219.8978835052735, 1217.8283407766462],
[1243.9619887623599, 1242.5358822820642],
[1258.3647164749445, 1252.4998458238438],
[1237.7381736350649, 1235.1156979495572],
[1223.4348497720264, 1219.6391721372395],
[1254.1853015461786, 1241.1653568429306],
[1276.9581567300459, 1271.835337805798],
[1186.5292171800343, 1184.2635237701097],
[1189.4936738399583, 1186.2679219844583],
[1215.0016581948976, 1123.792744871628],
[1272.9060398796717, 1269.163421964716],
[1297.4944167463607, 1293.1672290879887],
[1298.9710884499523, 1291.8370407255773],
[1340.9775954174163, 1331.1338969391363],
[1340.329334684162, 1328.7039197161932],
[1350.9602032288803, 1118.0599416389152],
[400.54789351006536, 398.3924887125791],
[405.5089362539607, 281.20433760538384],
[353.1385172531772, 243.96224893545772],
[386.4131261415835, 383.98070733765064],
[389.8331315363019, 382.3530185276235],
[343.72236360032, 340.8833065431643],
[340.947436231104, 334.1203968335878],
[237.07403839151206, 227.7468470424102],
[91.87518783350485, 87.05298904547784],
[115.89437865009748, 114.02831067875327],
[113.31645106429792, 109.44137145170455],
[1408.30255049708, 1404.303410360479],
[1275.3443298879704, 1271.1802839076145],
[1271.09204829869, 1269.4173979947914],
[1269.3459120131715, 1267.4880558816214],
[1267.0772857059749, 1265.3325362434293],
[1265.874772160261, 1263.459146644464],
[1263.812703008362, 1261.6079557748706],
[1261.603360879883, 1259.6038834387941],
[1259.639338645864, 1257.5490681079975],
[1257.5658686939253, 1255.6379399244029],
[1255.2563401709733, 1252.9845473156283],
[1253.506636084003, 1250.9209381772826],
[1251.2662554758067, 1249.0639508428033],
[1255.5596880416551, 1252.9689258037838],
[1253.4994361974648, 1251.3390306716576],
[1251.4056761198635, 1249.3949174576214],
[1259.4884558252136, 1255.3438888882745],
[1256.889706818452, 1253.3107364508514],
[1253.1797893494333, 1251.2504955065608],
[1252.1029802959868, 1249.583697152044],
[1252.4477564833999, 1247.5283605325321],
[1243.9304729240473, 1241.7701559532534],
[1214.3287342189433, 1209.2483611411255],
[1177.4874973791482, 1173.4289698627738],
[1175.593046337795, 1169.81493485882],
[1182.0595253510467, 1176.6578148458739],
[1294.7248259109408, 1241.415489140755],
[1312.042281343506, 1159.9444658920238],
[1314.032087226726, 1153.963789487524],
[1298.3771459386446, 1129.1713072932419],
[1308.407952665437, 1102.1335178358052],
[1334.1555195643064, 1046.4179133081677],
[356.66166402507525, 347.3805298743328],
[68.7774629985999, 66.05434930308891],
[93.24955094977247, 60.89511703879089],
[111.95739585377504, 108.95466977091107],
[131.44272329584152, 95.2447684423312],
[1374.6493413893938, 788.2833711315108],
[1313.8139178583049, 712.2027640665237],
[1272.2275603210585, 1247.3755247098484],
[1272.0958706127449, 1245.586239088534],
[1250.2316936473142, 1243.882006665079],
[1246.56791525545, 1242.053777096381],
[1242.1265980833255, 1239.9915873641742],
[1239.6058335741195, 1237.9704985560115],
[1238.8008815788114, 1236.0590341590332],
[1248.9157170964113, 1239.852957581661],
[1241.7612656586753, 1237.8111186019712],
[1237.135607019618, 1234.1757738803747],
[1238.9624011336273, 1232.6542901426328],
[1235.1117896395635, 1229.754897044084],
[1231.0051199988354, 1226.7014345726575],
[1227.7972736029649, 1224.771229866081],
[1172.3345990801347, 1170.3596201659911],
[339.52869986934996, 336.6699617057484],
[94.4092314977401, 90.75189491666612],
[91.94584011645932, 85.22848794432156],
[427.7155739715852, 425.7551044647758],
[1234.829765357849, 1233.0990009639129],
[1234.8662429743486, 1230.9966636928586],
[1234.3723496656105, 1229.3282880217575],
[1232.8612257143918, 1227.7093982513716],
[1223.9206356599684, 1221.7284012708956],
[1221.7426605696407, 1219.7325303648313],
[1200.0396261677117, 1157.2350468348225],
[335.8410365703845, 332.76241479248307],
[360.74060828137544, 317.3687362522761],
[1232.5028889862356, 1225.517512435798],
[1225.9065587158263, 1223.8157930510715],
[1225.561761071135, 1220.804384153442],
[1221.19975066464, 1219.2154303584448],
[1220.2006653869043, 1217.1979660745533],
[1221.000231154886, 1215.1653505694844],
[1215.1788232853098, 1211.040120393731],
[1217.970669096221, 1215.0679418599261],
[311.4423527355396, 305.95897608875214],
[341.35126589003835, 264.5140002139433],
[1266.3629067789022, 1209.22233355402],
[252.77252261202128, 251.00963876828644],
[252.64352918339816, 249.19927698601967],
[1208.428720188675, 1203.0238261025802],
[1207.269636307343, 1200.913400835853],
[1248.8836389761736, 1198.7812935259747],
[1263.2033942918395, 1197.2669210771512],
[392.1625202202578, 240.5414163761892],
[1193.0215716057353, 1188.7600636038035],
[1271.191727709632, 1186.7165211402762],
[1186.6688831890988, 1184.5591274638384],
[1231.8530215339606, 1175.1702406913043],
[1276.4240458807935, 1113.1633020457448],
[236.4434673509246, 231.37858511318393],
[231.97783318093622, 229.20369573288906],
[262.1356675175829, 198.87918991994076],
[1075.3983692680881, 1070.6597362957261],
[1250.9649426448937, 1045.7435596105317],
[1268.0539679726357, 972.8457170595631],
[1276.887366686033, 953.9022317966137],
[1293.5943314899077, 941.5028419639448],
[1270.402123698699, 928.1184869310775],
[1302.8084581887895, 912.7160588162831],
[1360.7424618641542, 410.9026863856268],
[436.3604761794915, 241.01594208088818],
[230.38030739851789, 224.7872010541958],
[380.9321361458153, 195.6518755474316],
[415.86060260236815, 187.58234437242146],
[270.8747568113769, 185.70810870004038],
[190.06982962554025, 144.53837401226252],
[139.51071345070085, 134.01791335203902],
[403.7554501811374, 128.77134129013922],
[256.11658083979967, 117.18553506727773],
[134.4258289352997, 75.03205738346342],
[66.86943773218721, 62.58868166288255],
[105.5005819222302, 47.296495693005134],
[380.82912164792236, 26.308128936514812],
[169.73048291958364, 14.906441064432093],
[1513.9999746865494, 0]]
1 change: 1 addition & 0 deletions tests/data/params1.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{"apical": {"branching_method": "directional",
"growth_method": "tmd",
"has_apical_tuft": true,
"metric": "path_distances",
"modify": null,
"orientation": [[0.0,
Expand Down
1 change: 1 addition & 0 deletions tests/data/params2.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{"apical": {"branching_method": "directional",
"growth_method": "tmd_apical",
"has_apical_tuft": true,
"metric": "path_distances",
"modify": null,
"orientation": [[0.0,
Expand Down
1 change: 1 addition & 0 deletions tests/data/params3.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"bias_length": 100,
"branching_method": "directional",
"growth_method": "tmd_gradient",
"has_apical_tuft": true,
"metric": "path_distances",
"modify": null,
"orientation": [[0.0,
Expand Down
29 changes: 29 additions & 0 deletions tests/data/params4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{"apical": {"branching_method": "directional",
"growth_method": "tmd_apical",
"has_apical_tuft": false,
"metric": "path_distances",
"modify": null,
"orientation": [[0.0,
1.0,
0.0]],
"radius": 0.3,
"randomness": 0.15,
"targeting": 0.12,
"tree_type": 4,
"step_size": {"norm":{"mean":1.0, "std":0.2}}},
"axon": {},
"basal": {"branching_method": "bio_oriented",
"growth_method": "tmd",
"metric": "path_distances",
"modify": null,
"orientation": null,
"radius": 0.3,
"randomness": 0.15,
"targeting": 0.12,
"tree_type": 3,
"step_size": {"norm":{"mean":1.0, "std":0.2}}},
"grow_types": ["basal", "apical"],
"origin": [0.0,
0.0,
0.0],
"diameter_params": {"method": "default"}}
1 change: 1 addition & 0 deletions tests/test_algo.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def _setup_test(Algo, Grower):
parameters = json.load(f)['basal']
parameters['bias_length'] = 0.5
parameters['bias'] = 0.5
parameters["has_apical_tuft"] = True

np.random.seed(42)
algo = Algo(distributions, parameters, [0, 0, 1])
Expand Down
14 changes: 11 additions & 3 deletions tests/test_neuron_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def _load_inputs(distributions, parameters):
return distributions, params


def _test_full(feature, distributions, parameters, ref_cell, ref_persistence_diagram):
def _test_full(feature, distributions, parameters, ref_cell, ref_persistence_diagram, save=False):

np.random.seed(0)
distributions, params = _load_inputs(join(_path, distributions), join(_path, parameters))
Expand All @@ -53,14 +53,16 @@ def _test_full(feature, distributions, parameters, ref_cell, ref_persistence_dia
out_neuron = os.path.join(folder, 'test_output_neuron_.h5')
n.write(out_neuron)
# For checking purposes, we can output the cells as swc
# n.write(ref_cell.replace('.h5', 'NEW.h5'))
if save:
n.write(ref_cell.replace('.h5', 'NEW.h5'))

if ref_persistence_diagram is not None:
# Load with TMD and extract radial persistence
n0 = tmd.io.load_neuron(out_neuron)

actual_persistence_diagram = tmd.methods.get_persistence_diagram(n0.apical[0], feature=feature)
# print(actual_persistence_diagram)
if save:
print(actual_persistence_diagram)

with open(join(_path, ref_persistence_diagram)) as f:
expected_persistence_diagram = json.load(f)
Expand Down Expand Up @@ -120,3 +122,9 @@ def test_bio_rat_l5_tpc():
'params3.json',
'expected_bio_rat_L5_TPC_B_with_params3.h5',
'expected_bio_rat_L5_TPC_B_with_params3_persistence_diagram.json')

_test_full('path_distances',
'bio_rat_L5_TPC_B.json',
'params4.json',
'expected_bio_rat_L5_TPC_B_with_params4.h5',
'expected_bio_rat_L5_TPC_B_with_params4_persistence_diagram.json')
2 changes: 1 addition & 1 deletion tns/extract_input/from_neurom.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def trunk_neurite(pop, neurite_type=nm.BASAL_DENDRITE, bins=30):
angles = [i for a in angles for i in a]
heights, bins = np.histogram(angles, bins=bins)

# Extract trunk relative orientations to reshample
# Extract trunk relative orientations to resample
actual_bins = (bins[1:] + bins[:-1]) / 2.

return {"trunk": {"orientation_deviation": {"data":
Expand Down
9 changes: 7 additions & 2 deletions tns/generate/algorithms/tmdgrower.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,14 @@ def initialize(self):
Initializes the tree grower and
computes the apical distance using the input barcode.
"""
from tmd.Topology.analysis import find_apical_point_distance
from tmd.Topology.analysis import find_apical_point_distance_smoothed as ap_dist
stop, num_sec = super(TMDApicalAlgo, self).initialize()
self.apical_point_distance_from_soma = find_apical_point_distance(self.ph_angles)
if self.params['has_apical_tuft']:
self.apical_point_distance_from_soma = ap_dist(self.ph_angles)
else:
# If cell does not have a tuft return the 70% of its length instead
# this will result in a point very close to the proximal apical point.
self.apical_point_distance_from_soma = 0.7 * np.nanmax(self.ph_angles)
return stop, num_sec

def bifurcate(self, current_section):
Expand Down
5 changes: 3 additions & 2 deletions tns/generate/grower.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
'''
import copy
import logging

from morphio.mut import Morphology # pylint: disable=import-error
from tns.generate.soma import SomaGrower
from tns.morphmath import sample
Expand Down Expand Up @@ -72,8 +73,8 @@ def next(self):
for grower in list(self.active_neurites):
if grower.end():
# If tree is an apical, the apical points get appended at the end of growth
# This will ensure that for each apical tree the relevant apical point,
# as a set of 3D coordinates (x,y,z) will be exposed to the user.
# This will ensure that for each apical tree a relevant apical point,
# will be exposed to the user as a set of 3D coordinates (x,y,z).
if 'apical' in self.input_parameters['grow_types'] and \
grower.type == self.input_parameters['apical']['tree_type']:
self.apical_points.append(grower.growth_algo.apical_point)
Expand Down

0 comments on commit 678cc5e

Please sign in to comment.