bmtool 0.7.6__py3-none-any.whl → 0.7.8__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of bmtool might be problematic. Click here for more details.
- bmtool/analysis/entrainment.py +113 -0
- bmtool/analysis/lfp.py +1 -1
- bmtool/bmplot/connections.py +759 -337
- bmtool/bmplot/entrainment.py +169 -49
- bmtool/bmplot/lfp.py +146 -11
- bmtool/bmplot/netcon_reports.py +1 -0
- bmtool/bmplot/spikes.py +175 -18
- bmtool/connectors.py +386 -0
- bmtool/singlecell.py +474 -31
- bmtool/synapses.py +1684 -651
- bmtool/util/util.py +40 -5
- {bmtool-0.7.6.dist-info → bmtool-0.7.8.dist-info}/METADATA +1 -1
- {bmtool-0.7.6.dist-info → bmtool-0.7.8.dist-info}/RECORD +17 -17
- {bmtool-0.7.6.dist-info → bmtool-0.7.8.dist-info}/WHEEL +0 -0
- {bmtool-0.7.6.dist-info → bmtool-0.7.8.dist-info}/entry_points.txt +0 -0
- {bmtool-0.7.6.dist-info → bmtool-0.7.8.dist-info}/licenses/LICENSE +0 -0
- {bmtool-0.7.6.dist-info → bmtool-0.7.8.dist-info}/top_level.txt +0 -0
bmtool/bmplot/connections.py
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
"""
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
Connection visualization module for BMTK models.
|
|
3
|
+
|
|
4
|
+
This module provides functions to visualize connectivity matrices from BMTK simulations,
|
|
5
|
+
including total connections, percent connectivity, connection probabilities, convergence,
|
|
6
|
+
divergence, and gap junctions.
|
|
7
|
+
|
|
8
|
+
See Also:
|
|
9
|
+
https://stackoverflow.com/questions/458209/is-there-a-way-to-detach-matplotlib-plots-so-that-the-computation-can-continue
|
|
4
10
|
"""
|
|
5
11
|
import re
|
|
6
12
|
import statistics
|
|
13
|
+
from typing import Dict, List, Optional, Tuple, Union
|
|
7
14
|
|
|
8
15
|
import matplotlib
|
|
9
16
|
import matplotlib.cm as cmx
|
|
@@ -17,27 +24,24 @@ from neuron import h
|
|
|
17
24
|
|
|
18
25
|
from ..util import util
|
|
19
26
|
|
|
20
|
-
use_description = """
|
|
21
|
-
|
|
22
|
-
Plot BMTK models easily.
|
|
23
|
-
|
|
24
|
-
python -m bmtool.plot
|
|
25
|
-
"""
|
|
26
|
-
|
|
27
|
-
|
|
28
27
|
def is_notebook() -> bool:
|
|
29
28
|
"""
|
|
30
29
|
Detect if code is running in a Jupyter notebook environment.
|
|
31
30
|
|
|
32
|
-
Returns
|
|
33
|
-
|
|
31
|
+
Returns
|
|
32
|
+
-------
|
|
34
33
|
bool
|
|
35
34
|
True if running in a Jupyter notebook, False otherwise.
|
|
36
35
|
|
|
37
|
-
Notes
|
|
38
|
-
|
|
36
|
+
Notes
|
|
37
|
+
-----
|
|
39
38
|
This is used to determine whether to call plt.show() explicitly or
|
|
40
39
|
rely on Jupyter's automatic display functionality.
|
|
40
|
+
|
|
41
|
+
Examples
|
|
42
|
+
--------
|
|
43
|
+
>>> if is_notebook():
|
|
44
|
+
... plt.show()
|
|
41
45
|
"""
|
|
42
46
|
try:
|
|
43
47
|
shell = get_ipython().__class__.__name__
|
|
@@ -52,52 +56,65 @@ def is_notebook() -> bool:
|
|
|
52
56
|
|
|
53
57
|
|
|
54
58
|
def total_connection_matrix(
|
|
55
|
-
config
|
|
56
|
-
title=None,
|
|
57
|
-
sources=None,
|
|
58
|
-
targets=None,
|
|
59
|
-
sids=None,
|
|
60
|
-
tids=None,
|
|
61
|
-
no_prepend_pop=False,
|
|
62
|
-
save_file=None,
|
|
63
|
-
synaptic_info="0",
|
|
64
|
-
include_gap=True,
|
|
65
|
-
):
|
|
59
|
+
config: str,
|
|
60
|
+
title: Optional[str] = None,
|
|
61
|
+
sources: Optional[str] = None,
|
|
62
|
+
targets: Optional[str] = None,
|
|
63
|
+
sids: Optional[str] = None,
|
|
64
|
+
tids: Optional[str] = None,
|
|
65
|
+
no_prepend_pop: bool = False,
|
|
66
|
+
save_file: Optional[str] = None,
|
|
67
|
+
synaptic_info: str = "0",
|
|
68
|
+
include_gap: bool = True,
|
|
69
|
+
) -> None:
|
|
66
70
|
"""
|
|
67
71
|
Generate a plot displaying total connections or other synaptic statistics.
|
|
68
72
|
|
|
69
|
-
Parameters
|
|
70
|
-
|
|
73
|
+
Parameters
|
|
74
|
+
----------
|
|
71
75
|
config : str
|
|
72
76
|
Path to a BMTK simulation config file.
|
|
73
77
|
title : str, optional
|
|
74
78
|
Title for the plot. If None, a default title will be used.
|
|
75
|
-
sources : str
|
|
79
|
+
sources : str, optional
|
|
76
80
|
Comma-separated string of network names to use as sources.
|
|
77
|
-
targets : str
|
|
81
|
+
targets : str, optional
|
|
78
82
|
Comma-separated string of network names to use as targets.
|
|
79
83
|
sids : str, optional
|
|
80
84
|
Comma-separated string of source node identifiers to filter.
|
|
81
85
|
tids : str, optional
|
|
82
86
|
Comma-separated string of target node identifiers to filter.
|
|
83
87
|
no_prepend_pop : bool, optional
|
|
84
|
-
If True, don't display population name before sid or tid in the plot.
|
|
88
|
+
If True, don't display population name before sid or tid in the plot. Default is False.
|
|
85
89
|
save_file : str, optional
|
|
86
90
|
Path to save the plot. If None, plot is not saved.
|
|
87
91
|
synaptic_info : str, optional
|
|
88
|
-
Type of information to display:
|
|
92
|
+
Type of information to display. Options:
|
|
89
93
|
- '0': Total connections (default)
|
|
90
94
|
- '1': Mean and standard deviation of connections
|
|
91
95
|
- '2': All synapse .mod files used
|
|
92
96
|
- '3': All synapse .json files used
|
|
93
97
|
include_gap : bool, optional
|
|
94
98
|
If True, include gap junctions and chemical synapses in the analysis.
|
|
95
|
-
If False, only include chemical synapses.
|
|
99
|
+
If False, only include chemical synapses. Default is True.
|
|
96
100
|
|
|
97
|
-
Returns
|
|
98
|
-
|
|
101
|
+
Returns
|
|
102
|
+
-------
|
|
99
103
|
None
|
|
100
|
-
|
|
104
|
+
|
|
105
|
+
Raises
|
|
106
|
+
------
|
|
107
|
+
Exception
|
|
108
|
+
If config is not defined or sources/targets are not defined.
|
|
109
|
+
|
|
110
|
+
Examples
|
|
111
|
+
--------
|
|
112
|
+
>>> total_connection_matrix(
|
|
113
|
+
... config='config.json',
|
|
114
|
+
... sources='PN',
|
|
115
|
+
... targets='LN',
|
|
116
|
+
... title='PN to LN Connections'
|
|
117
|
+
... )
|
|
101
118
|
"""
|
|
102
119
|
if not config:
|
|
103
120
|
raise Exception("config not defined")
|
|
@@ -138,34 +155,75 @@ def total_connection_matrix(
|
|
|
138
155
|
plot_connection_info(
|
|
139
156
|
text, num, source_labels, target_labels, title, syn_info=synaptic_info, save_file=save_file
|
|
140
157
|
)
|
|
141
|
-
return
|
|
142
158
|
|
|
143
159
|
|
|
144
160
|
def percent_connection_matrix(
|
|
145
|
-
config
|
|
146
|
-
nodes=None,
|
|
147
|
-
edges=None,
|
|
148
|
-
title=None,
|
|
149
|
-
sources=None,
|
|
150
|
-
targets=None,
|
|
151
|
-
sids=None,
|
|
152
|
-
tids=None,
|
|
153
|
-
no_prepend_pop=False,
|
|
154
|
-
save_file=None,
|
|
155
|
-
method="total",
|
|
156
|
-
include_gap=True,
|
|
157
|
-
|
|
161
|
+
config: str,
|
|
162
|
+
nodes: Optional[pd.DataFrame] = None,
|
|
163
|
+
edges: Optional[pd.DataFrame] = None,
|
|
164
|
+
title: Optional[str] = None,
|
|
165
|
+
sources: Optional[str] = None,
|
|
166
|
+
targets: Optional[str] = None,
|
|
167
|
+
sids: Optional[str] = None,
|
|
168
|
+
tids: Optional[str] = None,
|
|
169
|
+
no_prepend_pop: bool = False,
|
|
170
|
+
save_file: Optional[str] = None,
|
|
171
|
+
method: str = "total",
|
|
172
|
+
include_gap: bool = True,
|
|
173
|
+
return_dict: bool = False,
|
|
174
|
+
) -> Optional[Dict]:
|
|
158
175
|
"""
|
|
159
|
-
Generates a plot showing the percent connectivity of a network
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
176
|
+
Generates a plot showing the percent connectivity of a network.
|
|
177
|
+
|
|
178
|
+
Parameters
|
|
179
|
+
----------
|
|
180
|
+
config : str
|
|
181
|
+
Path to a BMTK simulation config file.
|
|
182
|
+
nodes : pd.DataFrame, optional
|
|
183
|
+
Pre-loaded node data. If None, will be loaded from config.
|
|
184
|
+
edges : pd.DataFrame, optional
|
|
185
|
+
Pre-loaded edge data. If None, will be loaded from config.
|
|
186
|
+
title : str, optional
|
|
187
|
+
Title for the plot. If None, a default title will be used.
|
|
188
|
+
sources : str, optional
|
|
189
|
+
Comma-separated string of network name(s) to plot.
|
|
190
|
+
targets : str, optional
|
|
191
|
+
Comma-separated string of network name(s) to plot.
|
|
192
|
+
sids : str, optional
|
|
193
|
+
Comma-separated string of source node identifier(s) to filter.
|
|
194
|
+
tids : str, optional
|
|
195
|
+
Comma-separated string of target node identifier(s) to filter.
|
|
196
|
+
no_prepend_pop : bool, optional
|
|
197
|
+
If True, population name is not displayed before sid or tid in the plot. Default is False.
|
|
198
|
+
save_file : str, optional
|
|
199
|
+
Path to save the plot. If None, plot is not saved.
|
|
200
|
+
method : str, optional
|
|
201
|
+
Method for calculating percent connectivity. Options: 'total', 'uni', 'bi'.
|
|
202
|
+
Default is 'total'.
|
|
203
|
+
include_gap : bool, optional
|
|
204
|
+
If True, include gap junctions in analysis. If False, only include chemical synapses.
|
|
205
|
+
Default is True.
|
|
206
|
+
return_dict : bool, optional
|
|
207
|
+
If True, return connection information as a dictionary. Default is False.
|
|
208
|
+
|
|
209
|
+
Returns
|
|
210
|
+
-------
|
|
211
|
+
dict, optional
|
|
212
|
+
Dictionary containing connection information if return_dict=True, None otherwise.
|
|
213
|
+
|
|
214
|
+
Raises
|
|
215
|
+
------
|
|
216
|
+
Exception
|
|
217
|
+
If config is not defined or sources/targets are not defined.
|
|
218
|
+
|
|
219
|
+
Examples
|
|
220
|
+
--------
|
|
221
|
+
>>> result = percent_connection_matrix(
|
|
222
|
+
... config='config.json',
|
|
223
|
+
... sources='PN',
|
|
224
|
+
... targets='LN',
|
|
225
|
+
... return_dict=True
|
|
226
|
+
... )
|
|
169
227
|
"""
|
|
170
228
|
if not config:
|
|
171
229
|
raise Exception("config not defined")
|
|
@@ -197,33 +255,86 @@ def percent_connection_matrix(
|
|
|
197
255
|
if title is None or title == "":
|
|
198
256
|
title = "Percent Connectivity"
|
|
199
257
|
|
|
200
|
-
|
|
201
|
-
|
|
258
|
+
if return_dict:
|
|
259
|
+
result_dict = plot_connection_info(
|
|
260
|
+
text, num, source_labels, target_labels, title, save_file=save_file, return_dict=return_dict
|
|
261
|
+
)
|
|
262
|
+
return result_dict
|
|
263
|
+
else:
|
|
264
|
+
plot_connection_info(text, num, source_labels, target_labels, title, save_file=save_file)
|
|
202
265
|
|
|
203
266
|
|
|
204
267
|
def probability_connection_matrix(
|
|
205
|
-
config
|
|
206
|
-
nodes=None,
|
|
207
|
-
edges=None,
|
|
208
|
-
title=None,
|
|
209
|
-
sources=None,
|
|
210
|
-
targets=None,
|
|
211
|
-
sids=None,
|
|
212
|
-
tids=None,
|
|
213
|
-
no_prepend_pop=False,
|
|
214
|
-
save_file=None,
|
|
215
|
-
dist_X=True,
|
|
216
|
-
dist_Y=True,
|
|
217
|
-
dist_Z=True,
|
|
218
|
-
bins=8,
|
|
219
|
-
line_plot=False,
|
|
220
|
-
verbose=False,
|
|
221
|
-
include_gap=True,
|
|
222
|
-
):
|
|
268
|
+
config: str,
|
|
269
|
+
nodes: Optional[pd.DataFrame] = None,
|
|
270
|
+
edges: Optional[pd.DataFrame] = None,
|
|
271
|
+
title: Optional[str] = None,
|
|
272
|
+
sources: Optional[str] = None,
|
|
273
|
+
targets: Optional[str] = None,
|
|
274
|
+
sids: Optional[str] = None,
|
|
275
|
+
tids: Optional[str] = None,
|
|
276
|
+
no_prepend_pop: bool = False,
|
|
277
|
+
save_file: Optional[str] = None,
|
|
278
|
+
dist_X: bool = True,
|
|
279
|
+
dist_Y: bool = True,
|
|
280
|
+
dist_Z: bool = True,
|
|
281
|
+
bins: int = 8,
|
|
282
|
+
line_plot: bool = False,
|
|
283
|
+
verbose: bool = False,
|
|
284
|
+
include_gap: bool = True,
|
|
285
|
+
) -> None:
|
|
223
286
|
"""
|
|
224
|
-
Generates probability graphs
|
|
225
|
-
|
|
226
|
-
|
|
287
|
+
Generates probability graphs showing connectivity as a function of distance.
|
|
288
|
+
|
|
289
|
+
Parameters
|
|
290
|
+
----------
|
|
291
|
+
config : str
|
|
292
|
+
Path to a BMTK simulation config file.
|
|
293
|
+
nodes : pd.DataFrame, optional
|
|
294
|
+
Pre-loaded node data. If None, will be loaded from config.
|
|
295
|
+
edges : pd.DataFrame, optional
|
|
296
|
+
Pre-loaded edge data. If None, will be loaded from config.
|
|
297
|
+
title : str, optional
|
|
298
|
+
Title for the plot. If None, a default title will be used.
|
|
299
|
+
sources : str, optional
|
|
300
|
+
Comma-separated string of network name(s) to plot.
|
|
301
|
+
targets : str, optional
|
|
302
|
+
Comma-separated string of network name(s) to plot.
|
|
303
|
+
sids : str, optional
|
|
304
|
+
Comma-separated string of source node identifier(s) to filter.
|
|
305
|
+
tids : str, optional
|
|
306
|
+
Comma-separated string of target node identifier(s) to filter.
|
|
307
|
+
no_prepend_pop : bool, optional
|
|
308
|
+
If True, population name is not displayed before sid or tid. Default is False.
|
|
309
|
+
save_file : str, optional
|
|
310
|
+
Path to save the plot. If None, plot is not saved.
|
|
311
|
+
dist_X : bool, optional
|
|
312
|
+
If True, include X distance in calculations. Default is True.
|
|
313
|
+
dist_Y : bool, optional
|
|
314
|
+
If True, include Y distance in calculations. Default is True.
|
|
315
|
+
dist_Z : bool, optional
|
|
316
|
+
If True, include Z distance in calculations. Default is True.
|
|
317
|
+
bins : int, optional
|
|
318
|
+
Number of distance bins for the probability calculation. Default is 8.
|
|
319
|
+
line_plot : bool, optional
|
|
320
|
+
If True, plot lines instead of bars. Default is False.
|
|
321
|
+
verbose : bool, optional
|
|
322
|
+
If True, print debugging information. Default is False.
|
|
323
|
+
include_gap : bool, optional
|
|
324
|
+
If True, include gap junctions in analysis. Default is True.
|
|
325
|
+
|
|
326
|
+
Returns
|
|
327
|
+
-------
|
|
328
|
+
None
|
|
329
|
+
|
|
330
|
+
Raises
|
|
331
|
+
------
|
|
332
|
+
Exception
|
|
333
|
+
If config is not defined or sources/targets are not defined.
|
|
334
|
+
|
|
335
|
+
Notes
|
|
336
|
+
-----
|
|
337
|
+
This function needs model_template to be defined to work properly.
|
|
227
338
|
"""
|
|
228
339
|
if not config:
|
|
229
340
|
raise Exception("config not defined")
|
|
@@ -272,9 +383,9 @@ def probability_connection_matrix(
|
|
|
272
383
|
for x in range(num_src):
|
|
273
384
|
for y in range(num_tar):
|
|
274
385
|
ns = data[x][y]["ns"]
|
|
275
|
-
|
|
386
|
+
bins_data = data[x][y]["bins"]
|
|
276
387
|
|
|
277
|
-
XX =
|
|
388
|
+
XX = bins_data[:-1]
|
|
278
389
|
YY = ns[0] / ns[1]
|
|
279
390
|
|
|
280
391
|
if line_plot:
|
|
@@ -300,37 +411,74 @@ def probability_connection_matrix(
|
|
|
300
411
|
st = fig.suptitle(tt, fontsize=14)
|
|
301
412
|
fig.text(0.5, 0.04, "Target", ha="center")
|
|
302
413
|
fig.text(0.04, 0.5, "Source", va="center", rotation="vertical")
|
|
303
|
-
notebook = is_notebook
|
|
414
|
+
notebook = is_notebook()
|
|
304
415
|
if not notebook:
|
|
305
416
|
fig.show()
|
|
306
417
|
|
|
307
|
-
return
|
|
308
|
-
|
|
309
418
|
|
|
310
419
|
def convergence_connection_matrix(
|
|
311
|
-
config
|
|
312
|
-
title=None,
|
|
313
|
-
sources=None,
|
|
314
|
-
targets=None,
|
|
315
|
-
sids=None,
|
|
316
|
-
tids=None,
|
|
317
|
-
no_prepend_pop=False,
|
|
318
|
-
save_file=None,
|
|
319
|
-
convergence=True,
|
|
320
|
-
method="mean+std",
|
|
321
|
-
include_gap=True,
|
|
322
|
-
return_dict=None,
|
|
323
|
-
):
|
|
420
|
+
config: str,
|
|
421
|
+
title: Optional[str] = None,
|
|
422
|
+
sources: Optional[str] = None,
|
|
423
|
+
targets: Optional[str] = None,
|
|
424
|
+
sids: Optional[str] = None,
|
|
425
|
+
tids: Optional[str] = None,
|
|
426
|
+
no_prepend_pop: bool = False,
|
|
427
|
+
save_file: Optional[str] = None,
|
|
428
|
+
convergence: bool = True,
|
|
429
|
+
method: str = "mean+std",
|
|
430
|
+
include_gap: bool = True,
|
|
431
|
+
return_dict: Optional[bool] = None,
|
|
432
|
+
) -> Optional[Dict]:
|
|
324
433
|
"""
|
|
325
|
-
Generates connection plot displaying convergence data
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
434
|
+
Generates connection plot displaying synaptic convergence data.
|
|
435
|
+
|
|
436
|
+
Parameters
|
|
437
|
+
----------
|
|
438
|
+
config : str
|
|
439
|
+
Path to a BMTK simulation config file.
|
|
440
|
+
title : str, optional
|
|
441
|
+
Title for the plot. If None, a default title will be used.
|
|
442
|
+
sources : str, optional
|
|
443
|
+
Comma-separated string of network name(s) to plot.
|
|
444
|
+
targets : str, optional
|
|
445
|
+
Comma-separated string of network name(s) to plot.
|
|
446
|
+
sids : str, optional
|
|
447
|
+
Comma-separated string of source node identifier(s) to filter.
|
|
448
|
+
tids : str, optional
|
|
449
|
+
Comma-separated string of target node identifier(s) to filter.
|
|
450
|
+
no_prepend_pop : bool, optional
|
|
451
|
+
If True, population name is not displayed before sid or tid. Default is False.
|
|
452
|
+
save_file : str, optional
|
|
453
|
+
Path to save the plot. If None, plot is not saved.
|
|
454
|
+
convergence : bool, optional
|
|
455
|
+
If True, compute convergence; if False, compute divergence. Default is True.
|
|
456
|
+
method : str, optional
|
|
457
|
+
Statistical method for display. Options: 'mean', 'min', 'max', 'stdev', 'mean+std'.
|
|
458
|
+
Default is 'mean+std'.
|
|
459
|
+
include_gap : bool, optional
|
|
460
|
+
If True, include gap junctions in analysis. Default is True.
|
|
461
|
+
return_dict : bool, optional
|
|
462
|
+
If True, return connection information as a dictionary. Default is None.
|
|
463
|
+
|
|
464
|
+
Returns
|
|
465
|
+
-------
|
|
466
|
+
dict, optional
|
|
467
|
+
Dictionary containing connection information if return_dict=True, None otherwise.
|
|
468
|
+
|
|
469
|
+
Raises
|
|
470
|
+
------
|
|
471
|
+
Exception
|
|
472
|
+
If config is not defined or sources/targets are not defined.
|
|
473
|
+
|
|
474
|
+
Examples
|
|
475
|
+
--------
|
|
476
|
+
>>> result = convergence_connection_matrix(
|
|
477
|
+
... config='config.json',
|
|
478
|
+
... sources='PN',
|
|
479
|
+
... targets='LN',
|
|
480
|
+
... method='mean+std'
|
|
481
|
+
... )
|
|
334
482
|
"""
|
|
335
483
|
if not config:
|
|
336
484
|
raise Exception("config not defined")
|
|
@@ -353,29 +501,68 @@ def convergence_connection_matrix(
|
|
|
353
501
|
|
|
354
502
|
|
|
355
503
|
def divergence_connection_matrix(
|
|
356
|
-
config
|
|
357
|
-
title=None,
|
|
358
|
-
sources=None,
|
|
359
|
-
targets=None,
|
|
360
|
-
sids=None,
|
|
361
|
-
tids=None,
|
|
362
|
-
no_prepend_pop=False,
|
|
363
|
-
save_file=None,
|
|
364
|
-
convergence=False,
|
|
365
|
-
method="mean+std",
|
|
366
|
-
include_gap=True,
|
|
367
|
-
return_dict=None,
|
|
368
|
-
):
|
|
504
|
+
config: str,
|
|
505
|
+
title: Optional[str] = None,
|
|
506
|
+
sources: Optional[str] = None,
|
|
507
|
+
targets: Optional[str] = None,
|
|
508
|
+
sids: Optional[str] = None,
|
|
509
|
+
tids: Optional[str] = None,
|
|
510
|
+
no_prepend_pop: bool = False,
|
|
511
|
+
save_file: Optional[str] = None,
|
|
512
|
+
convergence: bool = False,
|
|
513
|
+
method: str = "mean+std",
|
|
514
|
+
include_gap: bool = True,
|
|
515
|
+
return_dict: Optional[bool] = None,
|
|
516
|
+
) -> Optional[Dict]:
|
|
369
517
|
"""
|
|
370
|
-
Generates connection plot displaying divergence data
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
518
|
+
Generates connection plot displaying synaptic divergence data.
|
|
519
|
+
|
|
520
|
+
Parameters
|
|
521
|
+
----------
|
|
522
|
+
config : str
|
|
523
|
+
Path to a BMTK simulation config file.
|
|
524
|
+
title : str, optional
|
|
525
|
+
Title for the plot. If None, a default title will be used.
|
|
526
|
+
sources : str, optional
|
|
527
|
+
Comma-separated string of network name(s) to plot.
|
|
528
|
+
targets : str, optional
|
|
529
|
+
Comma-separated string of network name(s) to plot.
|
|
530
|
+
sids : str, optional
|
|
531
|
+
Comma-separated string of source node identifier(s) to filter.
|
|
532
|
+
tids : str, optional
|
|
533
|
+
Comma-separated string of target node identifier(s) to filter.
|
|
534
|
+
no_prepend_pop : bool, optional
|
|
535
|
+
If True, population name is not displayed before sid or tid. Default is False.
|
|
536
|
+
save_file : str, optional
|
|
537
|
+
Path to save the plot. If None, plot is not saved.
|
|
538
|
+
convergence : bool, optional
|
|
539
|
+
If True, compute convergence; if False, compute divergence. Default is False.
|
|
540
|
+
method : str, optional
|
|
541
|
+
Statistical method for display. Options: 'mean', 'min', 'max', 'stdev', 'mean+std'.
|
|
542
|
+
Default is 'mean+std'.
|
|
543
|
+
include_gap : bool, optional
|
|
544
|
+
If True, include gap junctions in analysis. Default is True.
|
|
545
|
+
return_dict : bool, optional
|
|
546
|
+
If True, return connection information as a dictionary. Default is None.
|
|
547
|
+
|
|
548
|
+
Returns
|
|
549
|
+
-------
|
|
550
|
+
dict, optional
|
|
551
|
+
Dictionary containing connection information if return_dict=True, None otherwise.
|
|
552
|
+
|
|
553
|
+
Raises
|
|
554
|
+
------
|
|
555
|
+
Exception
|
|
556
|
+
If config is not defined or sources/targets are not defined.
|
|
557
|
+
|
|
558
|
+
Examples
|
|
559
|
+
--------
|
|
560
|
+
>>> result = divergence_connection_matrix(
|
|
561
|
+
... config='config.json',
|
|
562
|
+
... sources='PN',
|
|
563
|
+
... targets='LN',
|
|
564
|
+
... method='mean+std'
|
|
565
|
+
... )
|
|
379
566
|
"""
|
|
380
567
|
if not config:
|
|
381
568
|
raise Exception("config not defined")
|
|
@@ -425,7 +612,7 @@ def divergence_connection_matrix(
|
|
|
425
612
|
else:
|
|
426
613
|
title = title + "Synaptic Divergence"
|
|
427
614
|
if return_dict:
|
|
428
|
-
|
|
615
|
+
result_dict = plot_connection_info(
|
|
429
616
|
syn_info,
|
|
430
617
|
data,
|
|
431
618
|
source_labels,
|
|
@@ -434,35 +621,66 @@ def divergence_connection_matrix(
|
|
|
434
621
|
save_file=save_file,
|
|
435
622
|
return_dict=return_dict,
|
|
436
623
|
)
|
|
437
|
-
return
|
|
624
|
+
return result_dict
|
|
438
625
|
else:
|
|
439
626
|
plot_connection_info(
|
|
440
627
|
syn_info, data, source_labels, target_labels, title, save_file=save_file
|
|
441
628
|
)
|
|
442
|
-
return
|
|
443
629
|
|
|
444
630
|
|
|
445
631
|
def gap_junction_matrix(
|
|
446
|
-
config
|
|
447
|
-
title=None,
|
|
448
|
-
sources=None,
|
|
449
|
-
targets=None,
|
|
450
|
-
sids=None,
|
|
451
|
-
tids=None,
|
|
452
|
-
no_prepend_pop=False,
|
|
453
|
-
save_file=None,
|
|
454
|
-
method="convergence",
|
|
455
|
-
):
|
|
632
|
+
config: str,
|
|
633
|
+
title: Optional[str] = None,
|
|
634
|
+
sources: Optional[str] = None,
|
|
635
|
+
targets: Optional[str] = None,
|
|
636
|
+
sids: Optional[str] = None,
|
|
637
|
+
tids: Optional[str] = None,
|
|
638
|
+
no_prepend_pop: bool = False,
|
|
639
|
+
save_file: Optional[str] = None,
|
|
640
|
+
method: str = "convergence",
|
|
641
|
+
) -> None:
|
|
456
642
|
"""
|
|
457
643
|
Generates connection plot displaying gap junction data.
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
644
|
+
|
|
645
|
+
Parameters
|
|
646
|
+
----------
|
|
647
|
+
config : str
|
|
648
|
+
Path to a BMTK simulation config file.
|
|
649
|
+
title : str, optional
|
|
650
|
+
Title for the plot. If None, a default title will be used.
|
|
651
|
+
sources : str, optional
|
|
652
|
+
Comma-separated string of network name(s) to plot.
|
|
653
|
+
targets : str, optional
|
|
654
|
+
Comma-separated string of network name(s) to plot.
|
|
655
|
+
sids : str, optional
|
|
656
|
+
Comma-separated string of source node identifier(s) to filter.
|
|
657
|
+
tids : str, optional
|
|
658
|
+
Comma-separated string of target node identifier(s) to filter.
|
|
659
|
+
no_prepend_pop : bool, optional
|
|
660
|
+
If True, population name is not displayed before sid or tid. Default is False.
|
|
661
|
+
save_file : str, optional
|
|
662
|
+
Path to save the plot. If None, plot is not saved.
|
|
663
|
+
method : str, optional
|
|
664
|
+
Method for computing gap junction statistics. Options: 'convergence', 'percent'.
|
|
665
|
+
Default is 'convergence'.
|
|
666
|
+
|
|
667
|
+
Returns
|
|
668
|
+
-------
|
|
669
|
+
None
|
|
670
|
+
|
|
671
|
+
Raises
|
|
672
|
+
------
|
|
673
|
+
Exception
|
|
674
|
+
If config is not defined, sources/targets are not defined, or method is invalid.
|
|
675
|
+
|
|
676
|
+
Examples
|
|
677
|
+
--------
|
|
678
|
+
>>> gap_junction_matrix(
|
|
679
|
+
... config='config.json',
|
|
680
|
+
... sources='PN',
|
|
681
|
+
... targets='LN',
|
|
682
|
+
... method='convergence'
|
|
683
|
+
... )
|
|
466
684
|
"""
|
|
467
685
|
if not config:
|
|
468
686
|
raise Exception("config not defined")
|
|
@@ -492,28 +710,34 @@ def gap_junction_matrix(
|
|
|
492
710
|
method=method,
|
|
493
711
|
)
|
|
494
712
|
|
|
495
|
-
def filter_rows(
|
|
713
|
+
def filter_rows(
|
|
714
|
+
syn_info: np.ndarray,
|
|
715
|
+
data: np.ndarray,
|
|
716
|
+
source_labels: List,
|
|
717
|
+
target_labels: List,
|
|
718
|
+
) -> Tuple[np.ndarray, np.ndarray, np.ndarray, List]:
|
|
496
719
|
"""
|
|
497
720
|
Filters out rows in a connectivity matrix that contain only NaN or zero values.
|
|
498
721
|
|
|
499
|
-
This function is used to clean up connection matrices by removing rows that have
|
|
500
|
-
which helps create more informative visualizations of network connectivity.
|
|
722
|
+
This function is used to clean up connection matrices by removing rows that have
|
|
723
|
+
no meaningful data, which helps create more informative visualizations of network connectivity.
|
|
501
724
|
|
|
502
|
-
Parameters
|
|
503
|
-
|
|
504
|
-
syn_info :
|
|
725
|
+
Parameters
|
|
726
|
+
----------
|
|
727
|
+
syn_info : np.ndarray
|
|
505
728
|
Array containing synaptic information corresponding to the data matrix.
|
|
506
|
-
data :
|
|
507
|
-
2D matrix containing connectivity data with rows representing sources
|
|
729
|
+
data : np.ndarray
|
|
730
|
+
2D matrix containing connectivity data with rows representing sources
|
|
731
|
+
and columns representing targets.
|
|
508
732
|
source_labels : list
|
|
509
733
|
List of labels for the source populations corresponding to rows in the data matrix.
|
|
510
734
|
target_labels : list
|
|
511
735
|
List of labels for the target populations corresponding to columns in the data matrix.
|
|
512
736
|
|
|
513
|
-
Returns
|
|
514
|
-
|
|
737
|
+
Returns
|
|
738
|
+
-------
|
|
515
739
|
tuple
|
|
516
|
-
A tuple containing
|
|
740
|
+
A tuple containing (syn_info, data, source_labels, target_labels) with invalid rows removed.
|
|
517
741
|
"""
|
|
518
742
|
# Identify rows with all NaN or all zeros
|
|
519
743
|
valid_rows = ~np.all(np.isnan(data), axis=1) & ~np.all(data == 0, axis=1)
|
|
@@ -525,7 +749,12 @@ def gap_junction_matrix(
|
|
|
525
749
|
|
|
526
750
|
return new_syn_info, new_data, new_source_labels, target_labels
|
|
527
751
|
|
|
528
|
-
def filter_rows_and_columns(
|
|
752
|
+
def filter_rows_and_columns(
|
|
753
|
+
syn_info: np.ndarray,
|
|
754
|
+
data: np.ndarray,
|
|
755
|
+
source_labels: List,
|
|
756
|
+
target_labels: List,
|
|
757
|
+
) -> Tuple[np.ndarray, np.ndarray, List, List]:
|
|
529
758
|
"""
|
|
530
759
|
Filters out both rows and columns in a connectivity matrix that contain only NaN or zero values.
|
|
531
760
|
|
|
@@ -533,21 +762,22 @@ def gap_junction_matrix(
|
|
|
533
762
|
then transposing the matrix and removing columns with no data (by treating them as rows).
|
|
534
763
|
This creates a cleaner, more informative connectivity matrix visualization.
|
|
535
764
|
|
|
536
|
-
Parameters
|
|
537
|
-
|
|
538
|
-
syn_info :
|
|
765
|
+
Parameters
|
|
766
|
+
----------
|
|
767
|
+
syn_info : np.ndarray
|
|
539
768
|
Array containing synaptic information corresponding to the data matrix.
|
|
540
|
-
data :
|
|
541
|
-
2D matrix containing connectivity data with rows representing sources
|
|
769
|
+
data : np.ndarray
|
|
770
|
+
2D matrix containing connectivity data with rows representing sources
|
|
771
|
+
and columns representing targets.
|
|
542
772
|
source_labels : list
|
|
543
773
|
List of labels for the source populations corresponding to rows in the data matrix.
|
|
544
774
|
target_labels : list
|
|
545
775
|
List of labels for the target populations corresponding to columns in the data matrix.
|
|
546
776
|
|
|
547
|
-
Returns
|
|
548
|
-
|
|
777
|
+
Returns
|
|
778
|
+
-------
|
|
549
779
|
tuple
|
|
550
|
-
A tuple containing
|
|
780
|
+
A tuple containing (syn_info, data, source_labels, target_labels) with both
|
|
551
781
|
invalid rows and columns removed.
|
|
552
782
|
"""
|
|
553
783
|
# Filter rows first
|
|
@@ -590,75 +820,101 @@ def gap_junction_matrix(
|
|
|
590
820
|
elif method == "percent":
|
|
591
821
|
title += " Percent Connectivity"
|
|
592
822
|
plot_connection_info(syn_info, data, source_labels, target_labels, title, save_file=save_file)
|
|
593
|
-
return
|
|
594
823
|
|
|
595
824
|
|
|
596
825
|
def connection_histogram(
|
|
597
|
-
config
|
|
598
|
-
nodes=None,
|
|
599
|
-
edges=None,
|
|
600
|
-
sources
|
|
601
|
-
targets
|
|
602
|
-
sids
|
|
603
|
-
tids
|
|
604
|
-
no_prepend_pop=True,
|
|
605
|
-
synaptic_info="0",
|
|
606
|
-
source_cell=None,
|
|
607
|
-
target_cell=None,
|
|
608
|
-
include_gap=True,
|
|
609
|
-
):
|
|
826
|
+
config: str,
|
|
827
|
+
nodes: Optional[pd.DataFrame] = None,
|
|
828
|
+
edges: Optional[pd.DataFrame] = None,
|
|
829
|
+
sources: Optional[str] = None,
|
|
830
|
+
targets: Optional[str] = None,
|
|
831
|
+
sids: Optional[str] = None,
|
|
832
|
+
tids: Optional[str] = None,
|
|
833
|
+
no_prepend_pop: bool = True,
|
|
834
|
+
synaptic_info: str = "0",
|
|
835
|
+
source_cell: Optional[str] = None,
|
|
836
|
+
target_cell: Optional[str] = None,
|
|
837
|
+
include_gap: bool = True,
|
|
838
|
+
) -> None:
|
|
610
839
|
"""
|
|
611
|
-
Generates histogram of number of connections individual cells
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
840
|
+
Generates histogram of the number of connections individual cells receive from another population.
|
|
841
|
+
|
|
842
|
+
Parameters
|
|
843
|
+
----------
|
|
844
|
+
config : str
|
|
845
|
+
Path to a BMTK simulation config file.
|
|
846
|
+
nodes : pd.DataFrame, optional
|
|
847
|
+
Pre-loaded node data. If None, will be loaded from config.
|
|
848
|
+
edges : pd.DataFrame, optional
|
|
849
|
+
Pre-loaded edge data. If None, will be loaded from config.
|
|
850
|
+
sources : str, optional
|
|
851
|
+
Comma-separated string of network name(s) to plot as sources.
|
|
852
|
+
targets : str, optional
|
|
853
|
+
Comma-separated string of network name(s) to plot as targets.
|
|
854
|
+
sids : str, optional
|
|
855
|
+
Comma-separated string of source node identifier(s) to filter by.
|
|
856
|
+
tids : str, optional
|
|
857
|
+
Comma-separated string of target node identifier(s) to filter by.
|
|
858
|
+
no_prepend_pop : bool, optional
|
|
859
|
+
If True, population name is not prepended to sid or tid. Default is True.
|
|
860
|
+
synaptic_info : str, optional
|
|
861
|
+
Type of synaptic information to display. Default is '0'.
|
|
862
|
+
source_cell : str, optional
|
|
863
|
+
Specific source cell type to plot connections from.
|
|
864
|
+
target_cell : str, optional
|
|
865
|
+
Specific target cell type to plot connections onto.
|
|
866
|
+
include_gap : bool, optional
|
|
867
|
+
If True, include gap junctions in analysis. Default is True.
|
|
868
|
+
|
|
869
|
+
Returns
|
|
870
|
+
-------
|
|
871
|
+
None
|
|
621
872
|
"""
|
|
873
|
+
if not config:
|
|
874
|
+
raise Exception("config not defined")
|
|
875
|
+
if not sources or not targets:
|
|
876
|
+
raise Exception("Sources or targets not defined")
|
|
877
|
+
|
|
878
|
+
sources_list = sources.split(",") if sources else []
|
|
879
|
+
targets_list = targets.split(",") if targets else []
|
|
880
|
+
if sids:
|
|
881
|
+
sids_list = sids.split(",")
|
|
882
|
+
else:
|
|
883
|
+
sids_list = []
|
|
884
|
+
if tids:
|
|
885
|
+
tids_list = tids.split(",")
|
|
886
|
+
else:
|
|
887
|
+
tids_list = []
|
|
622
888
|
|
|
623
|
-
def connection_pair_histogram(**kwargs):
|
|
889
|
+
def connection_pair_histogram(**kwargs: Dict) -> None:
|
|
624
890
|
"""
|
|
625
|
-
Creates a histogram showing the distribution of connection counts between
|
|
891
|
+
Creates a histogram showing the distribution of connection counts between specific cell types.
|
|
626
892
|
|
|
627
|
-
This function is designed to be used with the relation_matrix utility and will only
|
|
628
|
-
for the specified source and target cell types
|
|
893
|
+
This function is designed to be used with the relation_matrix utility and will only
|
|
894
|
+
create histograms for the specified source and target cell types.
|
|
629
895
|
|
|
630
|
-
Parameters
|
|
631
|
-
|
|
896
|
+
Parameters
|
|
897
|
+
----------
|
|
632
898
|
kwargs : dict
|
|
633
|
-
Dictionary containing
|
|
899
|
+
Dictionary containing edge data and filtering information.
|
|
634
900
|
- edges: DataFrame containing edge information
|
|
635
901
|
- sid: Column name for source ID type in the edges DataFrame
|
|
636
902
|
- tid: Column name for target ID type in the edges DataFrame
|
|
637
903
|
- source_id: Value to filter edges by source ID type
|
|
638
904
|
- target_id: Value to filter edges by target ID type
|
|
639
905
|
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
source_cell : str
|
|
643
|
-
The source cell type to plot.
|
|
644
|
-
target_cell : str
|
|
645
|
-
The target cell type to plot.
|
|
646
|
-
include_gap : bool
|
|
647
|
-
Whether to include gap junctions in the analysis. If False, gap junctions are excluded.
|
|
648
|
-
|
|
649
|
-
Returns:
|
|
650
|
-
--------
|
|
906
|
+
Returns
|
|
907
|
+
-------
|
|
651
908
|
None
|
|
652
|
-
Displays a histogram showing the distribution of connection counts.
|
|
653
909
|
"""
|
|
654
|
-
|
|
910
|
+
edges_data = kwargs["edges"]
|
|
655
911
|
source_id_type = kwargs["sid"]
|
|
656
912
|
target_id_type = kwargs["tid"]
|
|
657
913
|
source_id = kwargs["source_id"]
|
|
658
914
|
target_id = kwargs["target_id"]
|
|
659
915
|
if source_id == source_cell and target_id == target_cell:
|
|
660
|
-
temp =
|
|
661
|
-
(
|
|
916
|
+
temp = edges_data[
|
|
917
|
+
(edges_data[source_id_type] == source_id) & (edges_data[target_id_type] == target_id)
|
|
662
918
|
]
|
|
663
919
|
if not include_gap:
|
|
664
920
|
gap_col = temp["is_gap_junction"].fillna(False).astype(bool)
|
|
@@ -671,7 +927,7 @@ def connection_histogram(
|
|
|
671
927
|
label = "mean {:.2f} std {:.2f} median {:.2f}".format(
|
|
672
928
|
conn_mean, conn_std, conn_median
|
|
673
929
|
)
|
|
674
|
-
except: # lazy fix for std not calculated with 1 node
|
|
930
|
+
except (statistics.StatisticsError, ValueError): # lazy fix for std not calculated with 1 node
|
|
675
931
|
conn_mean = statistics.mean(node_pairs.values)
|
|
676
932
|
conn_median = statistics.median(node_pairs.values)
|
|
677
933
|
label = "mean {:.2f} median {:.2f}".format(conn_mean, conn_median)
|
|
@@ -687,24 +943,15 @@ def connection_histogram(
|
|
|
687
943
|
raise Exception("config not defined")
|
|
688
944
|
if not sources or not targets:
|
|
689
945
|
raise Exception("Sources or targets not defined")
|
|
690
|
-
|
|
691
|
-
targets = targets.split(",")
|
|
692
|
-
if sids:
|
|
693
|
-
sids = sids.split(",")
|
|
694
|
-
else:
|
|
695
|
-
sids = []
|
|
696
|
-
if tids:
|
|
697
|
-
tids = tids.split(",")
|
|
698
|
-
else:
|
|
699
|
-
tids = []
|
|
946
|
+
|
|
700
947
|
util.relation_matrix(
|
|
701
948
|
config,
|
|
702
949
|
nodes,
|
|
703
950
|
edges,
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
951
|
+
sources_list,
|
|
952
|
+
targets_list,
|
|
953
|
+
sids_list,
|
|
954
|
+
tids_list,
|
|
708
955
|
not no_prepend_pop,
|
|
709
956
|
relation_func=connection_pair_histogram,
|
|
710
957
|
synaptic_info=synaptic_info,
|
|
@@ -723,15 +970,35 @@ def connection_distance(
|
|
|
723
970
|
Plots the 3D spatial distribution of target nodes relative to a source node
|
|
724
971
|
and a histogram of distances from the source node to each target node.
|
|
725
972
|
|
|
726
|
-
Parameters
|
|
973
|
+
Parameters
|
|
727
974
|
----------
|
|
728
|
-
config:
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
975
|
+
config : str
|
|
976
|
+
Path to a BMTK simulation config file.
|
|
977
|
+
sources : str
|
|
978
|
+
Network name(s) to plot as sources.
|
|
979
|
+
targets : str
|
|
980
|
+
Network name(s) to plot as targets.
|
|
981
|
+
source_cell_id : int
|
|
982
|
+
ID of the source cell for calculating distances to target nodes.
|
|
983
|
+
target_id_type : str
|
|
984
|
+
String to filter target nodes based off the target_query.
|
|
985
|
+
ignore_z : bool, optional
|
|
986
|
+
If True, ignore Z axis when calculating distance. Default is False.
|
|
987
|
+
|
|
988
|
+
Returns
|
|
989
|
+
-------
|
|
990
|
+
None
|
|
734
991
|
|
|
992
|
+
Examples
|
|
993
|
+
--------
|
|
994
|
+
>>> connection_distance(
|
|
995
|
+
... config='config.json',
|
|
996
|
+
... sources='PN',
|
|
997
|
+
... targets='LN',
|
|
998
|
+
... source_cell_id=0,
|
|
999
|
+
... target_id_type='LN',
|
|
1000
|
+
... ignore_z=False
|
|
1001
|
+
... )
|
|
735
1002
|
"""
|
|
736
1003
|
if not config:
|
|
737
1004
|
raise Exception("config not defined")
|
|
@@ -815,46 +1082,45 @@ def connection_distance(
|
|
|
815
1082
|
|
|
816
1083
|
|
|
817
1084
|
def edge_histogram_matrix(
|
|
818
|
-
config
|
|
819
|
-
sources=None,
|
|
820
|
-
targets=None,
|
|
821
|
-
sids=None,
|
|
822
|
-
tids=None,
|
|
823
|
-
no_prepend_pop=None,
|
|
824
|
-
edge_property=None,
|
|
825
|
-
time=None,
|
|
826
|
-
time_compare=None,
|
|
827
|
-
report=None,
|
|
828
|
-
title=None,
|
|
829
|
-
save_file=None,
|
|
830
|
-
):
|
|
1085
|
+
config: str,
|
|
1086
|
+
sources: Optional[str] = None,
|
|
1087
|
+
targets: Optional[str] = None,
|
|
1088
|
+
sids: Optional[str] = None,
|
|
1089
|
+
tids: Optional[str] = None,
|
|
1090
|
+
no_prepend_pop: Optional[bool] = None,
|
|
1091
|
+
edge_property: Optional[str] = None,
|
|
1092
|
+
time: Optional[int] = None,
|
|
1093
|
+
time_compare: Optional[int] = None,
|
|
1094
|
+
report: Optional[str] = None,
|
|
1095
|
+
title: Optional[str] = None,
|
|
1096
|
+
save_file: Optional[str] = None,
|
|
1097
|
+
) -> None:
|
|
831
1098
|
"""
|
|
832
|
-
Generates a matrix of histograms showing the distribution of edge properties between
|
|
1099
|
+
Generates a matrix of histograms showing the distribution of edge properties between populations.
|
|
833
1100
|
|
|
834
|
-
This function creates a grid of histograms where each cell
|
|
835
|
-
specific edge property
|
|
836
|
-
target population (column).
|
|
1101
|
+
This function creates a grid of histograms where each cell represents the distribution
|
|
1102
|
+
of a specific edge property between source and target populations.
|
|
837
1103
|
|
|
838
|
-
Parameters
|
|
839
|
-
|
|
1104
|
+
Parameters
|
|
1105
|
+
----------
|
|
840
1106
|
config : str
|
|
841
1107
|
Path to a BMTK simulation config file.
|
|
842
|
-
sources : str
|
|
1108
|
+
sources : str, optional
|
|
843
1109
|
Comma-separated list of source network names.
|
|
844
|
-
targets : str
|
|
1110
|
+
targets : str, optional
|
|
845
1111
|
Comma-separated list of target network names.
|
|
846
1112
|
sids : str, optional
|
|
847
1113
|
Comma-separated list of source node identifiers to filter by.
|
|
848
1114
|
tids : str, optional
|
|
849
1115
|
Comma-separated list of target node identifiers to filter by.
|
|
850
1116
|
no_prepend_pop : bool, optional
|
|
851
|
-
If True, population names are not prepended to node identifiers
|
|
852
|
-
edge_property : str
|
|
853
|
-
The edge property to analyze
|
|
1117
|
+
If True, population names are not prepended to node identifiers.
|
|
1118
|
+
edge_property : str, optional
|
|
1119
|
+
The edge property to analyze (e.g., 'syn_weight', 'delay').
|
|
854
1120
|
time : int, optional
|
|
855
1121
|
Time point to analyze from a time series report.
|
|
856
1122
|
time_compare : int, optional
|
|
857
|
-
Second time point for comparison with
|
|
1123
|
+
Second time point for comparison with time.
|
|
858
1124
|
report : str, optional
|
|
859
1125
|
Name of the report to analyze.
|
|
860
1126
|
title : str, optional
|
|
@@ -862,10 +1128,18 @@ def edge_histogram_matrix(
|
|
|
862
1128
|
save_file : str, optional
|
|
863
1129
|
Path to save the generated plot.
|
|
864
1130
|
|
|
865
|
-
Returns
|
|
866
|
-
|
|
1131
|
+
Returns
|
|
1132
|
+
-------
|
|
867
1133
|
None
|
|
868
|
-
|
|
1134
|
+
|
|
1135
|
+
Examples
|
|
1136
|
+
--------
|
|
1137
|
+
>>> edge_histogram_matrix(
|
|
1138
|
+
... config='config.json',
|
|
1139
|
+
... sources='PN',
|
|
1140
|
+
... targets='LN',
|
|
1141
|
+
... edge_property='syn_weight'
|
|
1142
|
+
... )
|
|
869
1143
|
"""
|
|
870
1144
|
|
|
871
1145
|
if not config:
|
|
@@ -928,22 +1202,41 @@ def distance_delay_plot(
|
|
|
928
1202
|
simulation_config: str, source: str, target: str, group_by: str, sid: str, tid: str
|
|
929
1203
|
) -> None:
|
|
930
1204
|
"""
|
|
931
|
-
Plots the relationship between the distance and delay of connections between nodes in a neural network
|
|
932
|
-
|
|
933
|
-
This function loads
|
|
934
|
-
identifies connections (edges) between source and target node populations, calculates the Euclidean distance
|
|
935
|
-
connected nodes, and plots the delay as a function of distance.
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
1205
|
+
Plots the relationship between the distance and delay of connections between nodes in a neural network.
|
|
1206
|
+
|
|
1207
|
+
This function loads node and edge data from a simulation configuration file, filters nodes by population,
|
|
1208
|
+
identifies connections (edges) between source and target node populations, calculates the Euclidean distance
|
|
1209
|
+
between connected nodes, and plots the delay as a function of distance.
|
|
1210
|
+
|
|
1211
|
+
Parameters
|
|
1212
|
+
----------
|
|
1213
|
+
simulation_config : str
|
|
1214
|
+
Path to the simulation config file.
|
|
1215
|
+
source : str
|
|
1216
|
+
The name of the source population in the edge data.
|
|
1217
|
+
target : str
|
|
1218
|
+
The name of the target population in the edge data.
|
|
1219
|
+
group_by : str
|
|
1220
|
+
Column name to group nodes by (e.g., population name).
|
|
1221
|
+
sid : str
|
|
1222
|
+
Identifier for the source group (e.g., 'PN').
|
|
1223
|
+
tid : str
|
|
1224
|
+
Identifier for the target group (e.g., 'PN').
|
|
1225
|
+
|
|
1226
|
+
Returns
|
|
1227
|
+
-------
|
|
1228
|
+
None
|
|
1229
|
+
|
|
1230
|
+
Examples
|
|
1231
|
+
--------
|
|
1232
|
+
>>> distance_delay_plot(
|
|
1233
|
+
... 'config.json',
|
|
1234
|
+
... 'cortex',
|
|
1235
|
+
... 'cortex',
|
|
1236
|
+
... 'node_type_id',
|
|
1237
|
+
... 'E',
|
|
1238
|
+
... 'E'
|
|
1239
|
+
... )
|
|
947
1240
|
"""
|
|
948
1241
|
nodes, edges = util.load_nodes_edges_from_config(simulation_config)
|
|
949
1242
|
nodes = nodes[target]
|
|
@@ -984,37 +1277,56 @@ def distance_delay_plot(
|
|
|
984
1277
|
plt.show()
|
|
985
1278
|
|
|
986
1279
|
|
|
987
|
-
def plot_synapse_location(
|
|
1280
|
+
def plot_synapse_location(
|
|
1281
|
+
config: str,
|
|
1282
|
+
source: str,
|
|
1283
|
+
target: str,
|
|
1284
|
+
sids: str,
|
|
1285
|
+
tids: str,
|
|
1286
|
+
syn_feature: str = "afferent_section_id",
|
|
1287
|
+
) -> Tuple[plt.Figure, plt.Axes]:
|
|
988
1288
|
"""
|
|
989
1289
|
Generates a connectivity matrix showing synaptic distribution across different cell sections.
|
|
990
|
-
|
|
1290
|
+
|
|
1291
|
+
Note: Excludes gap junctions since they don't have an afferent id stored in the h5 file.
|
|
991
1292
|
|
|
992
1293
|
Parameters
|
|
993
1294
|
----------
|
|
994
1295
|
config : str
|
|
995
|
-
Path to BMTK config file
|
|
1296
|
+
Path to BMTK config file.
|
|
996
1297
|
source : str
|
|
997
|
-
The source BMTK network name
|
|
1298
|
+
The source BMTK network name.
|
|
998
1299
|
target : str
|
|
999
|
-
The target BMTK network name
|
|
1300
|
+
The target BMTK network name.
|
|
1000
1301
|
sids : str
|
|
1001
|
-
Column name in nodes file containing source population identifiers
|
|
1302
|
+
Column name in nodes file containing source population identifiers.
|
|
1002
1303
|
tids : str
|
|
1003
|
-
Column name in nodes file containing target population identifiers
|
|
1004
|
-
syn_feature : str,
|
|
1005
|
-
Synaptic feature to analyze
|
|
1304
|
+
Column name in nodes file containing target population identifiers.
|
|
1305
|
+
syn_feature : str, optional
|
|
1306
|
+
Synaptic feature to analyze. Default is 'afferent_section_id'.
|
|
1307
|
+
Options: 'afferent_section_id' or 'afferent_section_pos'.
|
|
1006
1308
|
|
|
1007
1309
|
Returns
|
|
1008
1310
|
-------
|
|
1009
1311
|
tuple
|
|
1010
|
-
(matplotlib.figure.Figure, matplotlib.axes.Axes) containing the plot
|
|
1312
|
+
(matplotlib.figure.Figure, matplotlib.axes.Axes) containing the plot.
|
|
1011
1313
|
|
|
1012
1314
|
Raises
|
|
1013
1315
|
------
|
|
1014
1316
|
ValueError
|
|
1015
|
-
If required parameters are missing or invalid
|
|
1317
|
+
If required parameters are missing or invalid.
|
|
1016
1318
|
RuntimeError
|
|
1017
|
-
If template loading or cell instantiation fails
|
|
1319
|
+
If template loading or cell instantiation fails.
|
|
1320
|
+
|
|
1321
|
+
Examples
|
|
1322
|
+
--------
|
|
1323
|
+
>>> fig, ax = plot_synapse_location(
|
|
1324
|
+
... config='config.json',
|
|
1325
|
+
... source='LGN',
|
|
1326
|
+
... target='cortex',
|
|
1327
|
+
... sids='node_type_id',
|
|
1328
|
+
... tids='node_type_id'
|
|
1329
|
+
... )
|
|
1018
1330
|
"""
|
|
1019
1331
|
# Validate inputs
|
|
1020
1332
|
if not all([config, source, target, sids, tids]):
|
|
@@ -1156,11 +1468,47 @@ def plot_synapse_location(config: str, source: str, target: str, sids: str, tids
|
|
|
1156
1468
|
|
|
1157
1469
|
|
|
1158
1470
|
def plot_connection_info(
|
|
1159
|
-
text
|
|
1160
|
-
|
|
1471
|
+
text: np.ndarray,
|
|
1472
|
+
num: np.ndarray,
|
|
1473
|
+
source_labels: List[str],
|
|
1474
|
+
target_labels: List[str],
|
|
1475
|
+
title: str,
|
|
1476
|
+
syn_info: str = "0",
|
|
1477
|
+
save_file: Optional[str] = None,
|
|
1478
|
+
return_dict: Optional[bool] = None,
|
|
1479
|
+
) -> Union[Tuple, Dict, None]:
|
|
1161
1480
|
"""
|
|
1162
|
-
|
|
1163
|
-
|
|
1481
|
+
Plot connection information as a heatmap with text annotations.
|
|
1482
|
+
|
|
1483
|
+
Parameters
|
|
1484
|
+
----------
|
|
1485
|
+
text : np.ndarray
|
|
1486
|
+
2D array of text annotations for each cell.
|
|
1487
|
+
num : np.ndarray
|
|
1488
|
+
2D array of numerical values for the heatmap colors.
|
|
1489
|
+
source_labels : list of str
|
|
1490
|
+
Labels for source populations (rows).
|
|
1491
|
+
target_labels : list of str
|
|
1492
|
+
Labels for target populations (columns).
|
|
1493
|
+
title : str
|
|
1494
|
+
Title for the plot.
|
|
1495
|
+
syn_info : str, optional
|
|
1496
|
+
Type of synaptic information being displayed. Options: '0', '1', '2', '3'.
|
|
1497
|
+
Default is '0'.
|
|
1498
|
+
save_file : str, optional
|
|
1499
|
+
Path to save the plot. If None, plot is not saved.
|
|
1500
|
+
return_dict : bool, optional
|
|
1501
|
+
If True, return connection information as a dictionary. Default is None.
|
|
1502
|
+
|
|
1503
|
+
Returns
|
|
1504
|
+
-------
|
|
1505
|
+
Union[Tuple, Dict, None]
|
|
1506
|
+
If return_dict=True, returns a dictionary of connection information.
|
|
1507
|
+
Otherwise, returns a tuple of (Figure, Axes), or None if just displaying.
|
|
1508
|
+
|
|
1509
|
+
Notes
|
|
1510
|
+
-----
|
|
1511
|
+
Handles missing source and target values by setting them to 0.
|
|
1164
1512
|
"""
|
|
1165
1513
|
# Ensure text dimensions match num dimensions
|
|
1166
1514
|
num_source = len(source_labels)
|
|
@@ -1315,35 +1663,45 @@ def plot_connection_info(
|
|
|
1315
1663
|
|
|
1316
1664
|
|
|
1317
1665
|
def connector_percent_matrix(
|
|
1318
|
-
csv_path: str = None,
|
|
1319
|
-
exclude_strings=None,
|
|
1320
|
-
assemb_key=None,
|
|
1666
|
+
csv_path: Optional[str] = None,
|
|
1667
|
+
exclude_strings: Optional[List[str]] = None,
|
|
1668
|
+
assemb_key: Optional[str] = None,
|
|
1321
1669
|
title: str = "Percent connection matrix",
|
|
1322
|
-
pop_order=None,
|
|
1670
|
+
pop_order: Optional[List[str]] = None,
|
|
1323
1671
|
) -> None:
|
|
1324
1672
|
"""
|
|
1325
|
-
Generates and plots a connection matrix based on connection probabilities from a CSV file
|
|
1673
|
+
Generates and plots a connection matrix based on connection probabilities from a CSV file.
|
|
1326
1674
|
|
|
1327
|
-
This function
|
|
1328
|
-
It processes
|
|
1329
|
-
connected pairs for each population combination in a matrix.
|
|
1675
|
+
This function visualizes percent connectivity while factoring in population distance and other parameters.
|
|
1676
|
+
It processes connection data by filtering 'Source' and 'Target' columns in the CSV and displays the
|
|
1677
|
+
percentage of connected pairs for each population combination in a matrix.
|
|
1330
1678
|
|
|
1331
|
-
Parameters
|
|
1332
|
-
|
|
1333
|
-
csv_path : str
|
|
1334
|
-
Path to the CSV file containing
|
|
1335
|
-
classes, specifically generated by the `save_connection_report()` function.
|
|
1679
|
+
Parameters
|
|
1680
|
+
----------
|
|
1681
|
+
csv_path : str, optional
|
|
1682
|
+
Path to the CSV file containing connection data. The CSV should be an output from the
|
|
1683
|
+
bmtool.connector classes, specifically generated by the `save_connection_report()` function.
|
|
1336
1684
|
exclude_strings : list of str, optional
|
|
1337
1685
|
List of strings to exclude rows where 'Source' or 'Target' contain these strings.
|
|
1338
|
-
|
|
1339
|
-
|
|
1686
|
+
assemb_key : str, optional
|
|
1687
|
+
Key to identify and process assembly connections.
|
|
1688
|
+
title : str, optional
|
|
1689
|
+
Title for the generated plot. Default is 'Percent connection matrix'.
|
|
1340
1690
|
pop_order : list of str, optional
|
|
1341
|
-
List of population labels to specify the order for
|
|
1691
|
+
List of population labels to specify the order for x- and y-ticks in the plot.
|
|
1342
1692
|
|
|
1343
|
-
Returns
|
|
1344
|
-
|
|
1693
|
+
Returns
|
|
1694
|
+
-------
|
|
1345
1695
|
None
|
|
1346
|
-
Displays a heatmap plot of the connection matrix
|
|
1696
|
+
Displays a heatmap plot of the connection matrix.
|
|
1697
|
+
|
|
1698
|
+
Examples
|
|
1699
|
+
--------
|
|
1700
|
+
>>> connector_percent_matrix(
|
|
1701
|
+
... csv_path='connections.csv',
|
|
1702
|
+
... exclude_strings=['Gap'],
|
|
1703
|
+
... title='Network Connectivity'
|
|
1704
|
+
... )
|
|
1347
1705
|
"""
|
|
1348
1706
|
# Read the CSV data
|
|
1349
1707
|
df = pd.read_csv(csv_path)
|
|
@@ -1491,17 +1849,44 @@ def connector_percent_matrix(
|
|
|
1491
1849
|
plt.show()
|
|
1492
1850
|
|
|
1493
1851
|
|
|
1494
|
-
def plot_3d_positions(
|
|
1852
|
+
def plot_3d_positions(
|
|
1853
|
+
config: Optional[str] = None,
|
|
1854
|
+
sources: Optional[str] = None,
|
|
1855
|
+
sid: Optional[str] = None,
|
|
1856
|
+
title: Optional[str] = None,
|
|
1857
|
+
save_file: Optional[str] = None,
|
|
1858
|
+
subset: Optional[int] = None,
|
|
1859
|
+
) -> None:
|
|
1495
1860
|
"""
|
|
1496
1861
|
Plots a 3D graph of all cells with x, y, z location.
|
|
1497
1862
|
|
|
1498
|
-
Parameters
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1863
|
+
Parameters
|
|
1864
|
+
----------
|
|
1865
|
+
config : str, optional
|
|
1866
|
+
Path to a BMTK simulation config file.
|
|
1867
|
+
sources : str, optional
|
|
1868
|
+
Which network(s) to plot. If None or 'all', plots all networks.
|
|
1869
|
+
sid : str, optional
|
|
1870
|
+
Column name to group cell types (node grouping criteria).
|
|
1871
|
+
title : str, optional
|
|
1872
|
+
Plot title. Default is '3D positions'.
|
|
1873
|
+
save_file : str, optional
|
|
1874
|
+
Path to save the plot. If None, plot is not saved.
|
|
1875
|
+
subset : int, optional
|
|
1876
|
+
Take every Nth row. This makes plotting large networks easier to visualize.
|
|
1877
|
+
|
|
1878
|
+
Returns
|
|
1879
|
+
-------
|
|
1880
|
+
None
|
|
1881
|
+
|
|
1882
|
+
Examples
|
|
1883
|
+
--------
|
|
1884
|
+
>>> plot_3d_positions(
|
|
1885
|
+
... config='config.json',
|
|
1886
|
+
... sources='cortex',
|
|
1887
|
+
... sid='node_type_id',
|
|
1888
|
+
... title='3D Neuron Positions'
|
|
1889
|
+
... )
|
|
1505
1890
|
"""
|
|
1506
1891
|
|
|
1507
1892
|
if not config:
|
|
@@ -1605,16 +1990,53 @@ def plot_3d_positions(config=None, sources=None, sid=None, title=None, save_file
|
|
|
1605
1990
|
|
|
1606
1991
|
|
|
1607
1992
|
def plot_3d_cell_rotation(
|
|
1608
|
-
config=None,
|
|
1609
|
-
sources=None,
|
|
1610
|
-
sids=None,
|
|
1611
|
-
title=None,
|
|
1612
|
-
save_file=None,
|
|
1613
|
-
quiver_length=None,
|
|
1614
|
-
arrow_length_ratio=None,
|
|
1615
|
-
group=None,
|
|
1616
|
-
subset=None,
|
|
1617
|
-
):
|
|
1993
|
+
config: Optional[str] = None,
|
|
1994
|
+
sources: Optional[List[str]] = None,
|
|
1995
|
+
sids: Optional[str] = None,
|
|
1996
|
+
title: Optional[str] = None,
|
|
1997
|
+
save_file: Optional[str] = None,
|
|
1998
|
+
quiver_length: Optional[float] = None,
|
|
1999
|
+
arrow_length_ratio: Optional[float] = None,
|
|
2000
|
+
group: Optional[str] = None,
|
|
2001
|
+
subset: Optional[int] = None,
|
|
2002
|
+
) -> None:
|
|
2003
|
+
"""
|
|
2004
|
+
Plot 3D visualization of cell rotations with quiver arrows showing rotation orientations.
|
|
2005
|
+
|
|
2006
|
+
Parameters
|
|
2007
|
+
----------
|
|
2008
|
+
config : str, optional
|
|
2009
|
+
Path to a BMTK simulation config file.
|
|
2010
|
+
sources : list of str, optional
|
|
2011
|
+
Network names to plot. If None or contains 'all', plots all networks.
|
|
2012
|
+
sids : str, optional
|
|
2013
|
+
Comma-separated column names to group cell types.
|
|
2014
|
+
title : str, optional
|
|
2015
|
+
Plot title. Default is 'Cell rotations'.
|
|
2016
|
+
save_file : str, optional
|
|
2017
|
+
Path to save the plot. If None, plot is not saved.
|
|
2018
|
+
quiver_length : float, optional
|
|
2019
|
+
Length of the quiver arrows. If None, use matplotlib default.
|
|
2020
|
+
arrow_length_ratio : float, optional
|
|
2021
|
+
Ratio of arrow head size to quiver length.
|
|
2022
|
+
group : str, optional
|
|
2023
|
+
Comma-separated group names to include. If None, include all groups.
|
|
2024
|
+
subset : int, optional
|
|
2025
|
+
Take every Nth row. Useful for visualizing large networks.
|
|
2026
|
+
|
|
2027
|
+
Returns
|
|
2028
|
+
-------
|
|
2029
|
+
None
|
|
2030
|
+
|
|
2031
|
+
Examples
|
|
2032
|
+
--------
|
|
2033
|
+
>>> plot_3d_cell_rotation(
|
|
2034
|
+
... config='config.json',
|
|
2035
|
+
... sources=['cortex'],
|
|
2036
|
+
... sids='node_type_id',
|
|
2037
|
+
... title='Cell Rotation Vectors'
|
|
2038
|
+
... )
|
|
2039
|
+
"""
|
|
1618
2040
|
from scipy.spatial.transform import Rotation as R
|
|
1619
2041
|
|
|
1620
2042
|
if not config:
|