bmtool 0.5.2__tar.gz → 0.5.4__tar.gz
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.
- {bmtool-0.5.2/bmtool.egg-info → bmtool-0.5.4}/PKG-INFO +139 -3
- bmtool-0.5.2/PKG-INFO → bmtool-0.5.4/README.md +135 -31
- {bmtool-0.5.2 → bmtool-0.5.4}/bmtool/bmplot.py +168 -5
- {bmtool-0.5.2 → bmtool-0.5.4}/bmtool/connectors.py +309 -62
- bmtool-0.5.4/bmtool/graphs.py +170 -0
- {bmtool-0.5.2 → bmtool-0.5.4}/bmtool/singlecell.py +4 -4
- {bmtool-0.5.2 → bmtool-0.5.4}/bmtool/util/util.py +106 -22
- bmtool-0.5.2/README.md → bmtool-0.5.4/bmtool.egg-info/PKG-INFO +167 -0
- {bmtool-0.5.2 → bmtool-0.5.4}/bmtool.egg-info/SOURCES.txt +1 -0
- {bmtool-0.5.2 → bmtool-0.5.4}/bmtool.egg-info/requires.txt +1 -0
- {bmtool-0.5.2 → bmtool-0.5.4}/setup.py +5 -4
- {bmtool-0.5.2 → bmtool-0.5.4}/LICENSE +0 -0
- {bmtool-0.5.2 → bmtool-0.5.4}/bmtool/__init__.py +0 -0
- {bmtool-0.5.2 → bmtool-0.5.4}/bmtool/__main__.py +0 -0
- {bmtool-0.5.2 → bmtool-0.5.4}/bmtool/debug/__init__.py +0 -0
- {bmtool-0.5.2 → bmtool-0.5.4}/bmtool/debug/commands.py +0 -0
- {bmtool-0.5.2 → bmtool-0.5.4}/bmtool/debug/debug.py +0 -0
- {bmtool-0.5.2 → bmtool-0.5.4}/bmtool/manage.py +0 -0
- {bmtool-0.5.2 → bmtool-0.5.4}/bmtool/plot_commands.py +0 -0
- {bmtool-0.5.2 → bmtool-0.5.4}/bmtool/util/__init__.py +0 -0
- {bmtool-0.5.2 → bmtool-0.5.4}/bmtool/util/commands.py +0 -0
- {bmtool-0.5.2 → bmtool-0.5.4}/bmtool/util/neuron/__init__.py +0 -0
- {bmtool-0.5.2 → bmtool-0.5.4}/bmtool/util/neuron/celltuner.py +0 -0
- {bmtool-0.5.2 → bmtool-0.5.4}/bmtool.egg-info/dependency_links.txt +0 -0
- {bmtool-0.5.2 → bmtool-0.5.4}/bmtool.egg-info/entry_points.txt +0 -0
- {bmtool-0.5.2 → bmtool-0.5.4}/bmtool.egg-info/top_level.txt +0 -0
- {bmtool-0.5.2 → bmtool-0.5.4}/setup.cfg +0 -0
@@ -1,11 +1,11 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: bmtool
|
3
|
-
Version: 0.5.
|
3
|
+
Version: 0.5.4
|
4
4
|
Summary: BMTool
|
5
5
|
Home-page: https://github.com/cyneuro/bmtool
|
6
6
|
Download-URL:
|
7
|
-
Author:
|
8
|
-
Author-email:
|
7
|
+
Author: Neural Engineering Laboratory at the University of Missouri
|
8
|
+
Author-email: gregglickert@mail.missouri.edu
|
9
9
|
License: MIT
|
10
10
|
Classifier: Intended Audience :: Developers
|
11
11
|
Classifier: Intended Audience :: Education
|
@@ -28,6 +28,7 @@ Requires-Dist: numpy
|
|
28
28
|
Requires-Dist: pandas
|
29
29
|
Requires-Dist: questionary
|
30
30
|
Requires-Dist: pynmodlt
|
31
|
+
Requires-Dist: plotly
|
31
32
|
|
32
33
|
# bmtool
|
33
34
|
A collection of modules to make developing [Neuron](https://www.neuron.yale.edu/neuron/) and [BMTK](https://alleninstitute.github.io/bmtk/) models easier.
|
@@ -40,6 +41,7 @@ A collection of modules to make developing [Neuron](https://www.neuron.yale.edu/
|
|
40
41
|
- [Single Cell](#Single-Cell-Module)
|
41
42
|
- [Connectors](#Connectors-Module)
|
42
43
|
- [Bmplot](#bmplot-Module)
|
44
|
+
- [Graphs](#graphs-module)
|
43
45
|
|
44
46
|
## Getting Started
|
45
47
|
|
@@ -391,6 +393,7 @@ net.add_edges(**connector.edge_params())
|
|
391
393
|
- [Percent connections](#Percent-connection-plot)
|
392
394
|
- [Convergence connnections](#convergence-plot)
|
393
395
|
- [Divergence connections](#divergence-plot)
|
396
|
+
- [Gap Junction connections](#gap-junction-plot)
|
394
397
|
- [connection histogram](#connection-histogram)
|
395
398
|
- [probability connection](#probability-of-connection-plot)
|
396
399
|
- [3D location](#3d-position-plot)
|
@@ -452,6 +455,17 @@ bmplot.divergence_connection_matrix(config='config.json',sources='LA',targets='L
|
|
452
455
|
|
453
456
|

|
454
457
|
|
458
|
+
### Gap Junction plot
|
459
|
+
#### While gap junctions can be include in the above plots, you can use this function to only view gap junctions.Type can be either 'convergence' or 'percent' connections to generate different plots
|
460
|
+
|
461
|
+
|
462
|
+
```python
|
463
|
+
bmplot.gap_junction_matrix(config='config.json',sources='LA',targets='LA',sids='pop_name',tids='pop_name',no_prepend_pop=True,type='percent')
|
464
|
+
```
|
465
|
+
|
466
|
+
|
467
|
+
|
468
|
+

|
455
469
|
|
456
470
|
|
457
471
|
### Connection histogram
|
@@ -776,5 +790,127 @@ bmplot.plot_basic_cell_info(config_file='config.json')
|
|
776
790
|
|
777
791
|
|
778
792
|
'LA'
|
793
|
+
## Graphs Module
|
794
|
+
- [Generate graph](#generate-graph)
|
795
|
+
- [Plot Graph](#plot-graph)
|
796
|
+
- [Connectioon table](#generate-graph-connection-table)
|
797
|
+
|
798
|
+
### Generate Graph
|
799
|
+
|
800
|
+
|
801
|
+
```python
|
802
|
+
from bmtool import graphs
|
803
|
+
import networkx as nx
|
804
|
+
|
805
|
+
Graph = graphs.generate_graph(config='config.json',source='LA',target='LA')
|
806
|
+
print("Number of nodes:", Graph.number_of_nodes())
|
807
|
+
print("Number of edges:", Graph.number_of_edges())
|
808
|
+
print("Node labels:", set(nx.get_node_attributes(Graph, 'label').values()))
|
809
|
+
```
|
810
|
+
|
811
|
+
Number of nodes: 2000
|
812
|
+
Number of edges: 84235
|
813
|
+
Node labels: {'SOM', 'PNc', 'PNa', 'PV'}
|
814
|
+
|
815
|
+
|
816
|
+
### Plot Graph
|
817
|
+
#### Generates an interactive plot showing nodes, edges and # of connections
|
818
|
+
|
819
|
+
|
820
|
+
```python
|
821
|
+
graphs.plot_graph(Graph)
|
822
|
+
```
|
823
|
+
|
824
|
+
|
825
|
+
|
826
|
+
### Generate graph connection table
|
827
|
+
#### Generates a CSV of all cells and the number of connections each individual cell receives
|
828
|
+
|
829
|
+
|
830
|
+
```python
|
831
|
+
import pandas as pd
|
832
|
+
graphs.export_node_connections_to_csv(Graph, 'node_connections.csv')
|
833
|
+
df = pd.read_csv('node_connections.csv')
|
834
|
+
df.head()
|
835
|
+
```
|
836
|
+
|
837
|
+
|
838
|
+
|
839
|
+
|
840
|
+
<div>
|
841
|
+
<style scoped>
|
842
|
+
.dataframe tbody tr th:only-of-type {
|
843
|
+
vertical-align: middle;
|
844
|
+
}
|
845
|
+
|
846
|
+
.dataframe tbody tr th {
|
847
|
+
vertical-align: top;
|
848
|
+
}
|
849
|
+
|
850
|
+
.dataframe thead th {
|
851
|
+
text-align: right;
|
852
|
+
}
|
853
|
+
</style>
|
854
|
+
<table border="1" class="dataframe">
|
855
|
+
<thead>
|
856
|
+
<tr style="text-align: right;">
|
857
|
+
<th></th>
|
858
|
+
<th>Unnamed: 0</th>
|
859
|
+
<th>Node Label</th>
|
860
|
+
<th>PNc Connections</th>
|
861
|
+
<th>PV Connections</th>
|
862
|
+
<th>SOM Connections</th>
|
863
|
+
<th>PNa Connections</th>
|
864
|
+
</tr>
|
865
|
+
</thead>
|
866
|
+
<tbody>
|
867
|
+
<tr>
|
868
|
+
<th>0</th>
|
869
|
+
<td>0</td>
|
870
|
+
<td>PNa</td>
|
871
|
+
<td>15</td>
|
872
|
+
<td>11</td>
|
873
|
+
<td>9</td>
|
874
|
+
<td>6</td>
|
875
|
+
</tr>
|
876
|
+
<tr>
|
877
|
+
<th>1</th>
|
878
|
+
<td>1</td>
|
879
|
+
<td>PNa</td>
|
880
|
+
<td>24</td>
|
881
|
+
<td>25</td>
|
882
|
+
<td>6</td>
|
883
|
+
<td>21</td>
|
884
|
+
</tr>
|
885
|
+
<tr>
|
886
|
+
<th>2</th>
|
887
|
+
<td>2</td>
|
888
|
+
<td>PNa</td>
|
889
|
+
<td>27</td>
|
890
|
+
<td>28</td>
|
891
|
+
<td>12</td>
|
892
|
+
<td>25</td>
|
893
|
+
</tr>
|
894
|
+
<tr>
|
895
|
+
<th>3</th>
|
896
|
+
<td>3</td>
|
897
|
+
<td>PNa</td>
|
898
|
+
<td>19</td>
|
899
|
+
<td>27</td>
|
900
|
+
<td>15</td>
|
901
|
+
<td>35</td>
|
902
|
+
</tr>
|
903
|
+
<tr>
|
904
|
+
<th>4</th>
|
905
|
+
<td>4</td>
|
906
|
+
<td>PNa</td>
|
907
|
+
<td>25</td>
|
908
|
+
<td>11</td>
|
909
|
+
<td>8</td>
|
910
|
+
<td>16</td>
|
911
|
+
</tr>
|
912
|
+
</tbody>
|
913
|
+
</table>
|
914
|
+
</div>
|
779
915
|
|
780
916
|
|
@@ -1,34 +1,3 @@
|
|
1
|
-
Metadata-Version: 2.1
|
2
|
-
Name: bmtool
|
3
|
-
Version: 0.5.2
|
4
|
-
Summary: BMTool
|
5
|
-
Home-page: https://github.com/cyneuro/bmtool
|
6
|
-
Download-URL:
|
7
|
-
Author: Tyler Banks
|
8
|
-
Author-email: tbanks@mail.missouri.edu
|
9
|
-
License: MIT
|
10
|
-
Classifier: Intended Audience :: Developers
|
11
|
-
Classifier: Intended Audience :: Education
|
12
|
-
Classifier: Intended Audience :: Science/Research
|
13
|
-
Classifier: License :: OSI Approved :: MIT License
|
14
|
-
Classifier: Programming Language :: Python :: 3
|
15
|
-
Classifier: Programming Language :: Python :: 3.6
|
16
|
-
Classifier: Topic :: Software Development :: Libraries
|
17
|
-
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
18
|
-
Classifier: Operating System :: OS Independent
|
19
|
-
Description-Content-Type: text/markdown
|
20
|
-
License-File: LICENSE
|
21
|
-
Requires-Dist: bmtk
|
22
|
-
Requires-Dist: click
|
23
|
-
Requires-Dist: clint
|
24
|
-
Requires-Dist: h5py
|
25
|
-
Requires-Dist: matplotlib
|
26
|
-
Requires-Dist: networkx
|
27
|
-
Requires-Dist: numpy
|
28
|
-
Requires-Dist: pandas
|
29
|
-
Requires-Dist: questionary
|
30
|
-
Requires-Dist: pynmodlt
|
31
|
-
|
32
1
|
# bmtool
|
33
2
|
A collection of modules to make developing [Neuron](https://www.neuron.yale.edu/neuron/) and [BMTK](https://alleninstitute.github.io/bmtk/) models easier.
|
34
3
|
|
@@ -40,6 +9,7 @@ A collection of modules to make developing [Neuron](https://www.neuron.yale.edu/
|
|
40
9
|
- [Single Cell](#Single-Cell-Module)
|
41
10
|
- [Connectors](#Connectors-Module)
|
42
11
|
- [Bmplot](#bmplot-Module)
|
12
|
+
- [Graphs](#graphs-module)
|
43
13
|
|
44
14
|
## Getting Started
|
45
15
|
|
@@ -391,6 +361,7 @@ net.add_edges(**connector.edge_params())
|
|
391
361
|
- [Percent connections](#Percent-connection-plot)
|
392
362
|
- [Convergence connnections](#convergence-plot)
|
393
363
|
- [Divergence connections](#divergence-plot)
|
364
|
+
- [Gap Junction connections](#gap-junction-plot)
|
394
365
|
- [connection histogram](#connection-histogram)
|
395
366
|
- [probability connection](#probability-of-connection-plot)
|
396
367
|
- [3D location](#3d-position-plot)
|
@@ -452,6 +423,17 @@ bmplot.divergence_connection_matrix(config='config.json',sources='LA',targets='L
|
|
452
423
|
|
453
424
|

|
454
425
|
|
426
|
+
### Gap Junction plot
|
427
|
+
#### While gap junctions can be include in the above plots, you can use this function to only view gap junctions.Type can be either 'convergence' or 'percent' connections to generate different plots
|
428
|
+
|
429
|
+
|
430
|
+
```python
|
431
|
+
bmplot.gap_junction_matrix(config='config.json',sources='LA',targets='LA',sids='pop_name',tids='pop_name',no_prepend_pop=True,type='percent')
|
432
|
+
```
|
433
|
+
|
434
|
+
|
435
|
+
|
436
|
+

|
455
437
|
|
456
438
|
|
457
439
|
### Connection histogram
|
@@ -776,5 +758,127 @@ bmplot.plot_basic_cell_info(config_file='config.json')
|
|
776
758
|
|
777
759
|
|
778
760
|
'LA'
|
761
|
+
## Graphs Module
|
762
|
+
- [Generate graph](#generate-graph)
|
763
|
+
- [Plot Graph](#plot-graph)
|
764
|
+
- [Connectioon table](#generate-graph-connection-table)
|
765
|
+
|
766
|
+
### Generate Graph
|
767
|
+
|
768
|
+
|
769
|
+
```python
|
770
|
+
from bmtool import graphs
|
771
|
+
import networkx as nx
|
772
|
+
|
773
|
+
Graph = graphs.generate_graph(config='config.json',source='LA',target='LA')
|
774
|
+
print("Number of nodes:", Graph.number_of_nodes())
|
775
|
+
print("Number of edges:", Graph.number_of_edges())
|
776
|
+
print("Node labels:", set(nx.get_node_attributes(Graph, 'label').values()))
|
777
|
+
```
|
778
|
+
|
779
|
+
Number of nodes: 2000
|
780
|
+
Number of edges: 84235
|
781
|
+
Node labels: {'SOM', 'PNc', 'PNa', 'PV'}
|
782
|
+
|
783
|
+
|
784
|
+
### Plot Graph
|
785
|
+
#### Generates an interactive plot showing nodes, edges and # of connections
|
786
|
+
|
787
|
+
|
788
|
+
```python
|
789
|
+
graphs.plot_graph(Graph)
|
790
|
+
```
|
791
|
+
|
792
|
+
|
793
|
+
|
794
|
+
### Generate graph connection table
|
795
|
+
#### Generates a CSV of all cells and the number of connections each individual cell receives
|
796
|
+
|
797
|
+
|
798
|
+
```python
|
799
|
+
import pandas as pd
|
800
|
+
graphs.export_node_connections_to_csv(Graph, 'node_connections.csv')
|
801
|
+
df = pd.read_csv('node_connections.csv')
|
802
|
+
df.head()
|
803
|
+
```
|
804
|
+
|
805
|
+
|
806
|
+
|
807
|
+
|
808
|
+
<div>
|
809
|
+
<style scoped>
|
810
|
+
.dataframe tbody tr th:only-of-type {
|
811
|
+
vertical-align: middle;
|
812
|
+
}
|
813
|
+
|
814
|
+
.dataframe tbody tr th {
|
815
|
+
vertical-align: top;
|
816
|
+
}
|
817
|
+
|
818
|
+
.dataframe thead th {
|
819
|
+
text-align: right;
|
820
|
+
}
|
821
|
+
</style>
|
822
|
+
<table border="1" class="dataframe">
|
823
|
+
<thead>
|
824
|
+
<tr style="text-align: right;">
|
825
|
+
<th></th>
|
826
|
+
<th>Unnamed: 0</th>
|
827
|
+
<th>Node Label</th>
|
828
|
+
<th>PNc Connections</th>
|
829
|
+
<th>PV Connections</th>
|
830
|
+
<th>SOM Connections</th>
|
831
|
+
<th>PNa Connections</th>
|
832
|
+
</tr>
|
833
|
+
</thead>
|
834
|
+
<tbody>
|
835
|
+
<tr>
|
836
|
+
<th>0</th>
|
837
|
+
<td>0</td>
|
838
|
+
<td>PNa</td>
|
839
|
+
<td>15</td>
|
840
|
+
<td>11</td>
|
841
|
+
<td>9</td>
|
842
|
+
<td>6</td>
|
843
|
+
</tr>
|
844
|
+
<tr>
|
845
|
+
<th>1</th>
|
846
|
+
<td>1</td>
|
847
|
+
<td>PNa</td>
|
848
|
+
<td>24</td>
|
849
|
+
<td>25</td>
|
850
|
+
<td>6</td>
|
851
|
+
<td>21</td>
|
852
|
+
</tr>
|
853
|
+
<tr>
|
854
|
+
<th>2</th>
|
855
|
+
<td>2</td>
|
856
|
+
<td>PNa</td>
|
857
|
+
<td>27</td>
|
858
|
+
<td>28</td>
|
859
|
+
<td>12</td>
|
860
|
+
<td>25</td>
|
861
|
+
</tr>
|
862
|
+
<tr>
|
863
|
+
<th>3</th>
|
864
|
+
<td>3</td>
|
865
|
+
<td>PNa</td>
|
866
|
+
<td>19</td>
|
867
|
+
<td>27</td>
|
868
|
+
<td>15</td>
|
869
|
+
<td>35</td>
|
870
|
+
</tr>
|
871
|
+
<tr>
|
872
|
+
<th>4</th>
|
873
|
+
<td>4</td>
|
874
|
+
<td>PNa</td>
|
875
|
+
<td>25</td>
|
876
|
+
<td>11</td>
|
877
|
+
<td>8</td>
|
878
|
+
<td>16</td>
|
879
|
+
</tr>
|
880
|
+
</tbody>
|
881
|
+
</table>
|
882
|
+
</div>
|
779
883
|
|
780
884
|
|
@@ -3,7 +3,6 @@ Want to be able to take multiple plot names in and plot them all at the same tim
|
|
3
3
|
https://stackoverflow.com/questions/458209/is-there-a-way-to-detach-matplotlib-plots-so-that-the-computation-can-continue
|
4
4
|
"""
|
5
5
|
from .util import util
|
6
|
-
|
7
6
|
import argparse,os,sys
|
8
7
|
|
9
8
|
import numpy as np
|
@@ -267,6 +266,82 @@ def divergence_connection_matrix(config=None,title=None,sources=None, targets=No
|
|
267
266
|
plot_connection_info(syn_info,data,source_labels,target_labels,title, save_file=save_file)
|
268
267
|
return
|
269
268
|
|
269
|
+
def gap_junction_matrix(config=None,title=None,sources=None, targets=None, sids=None,tids=None, no_prepend_pop=False,save_file=None,type='convergence'):
|
270
|
+
"""
|
271
|
+
Generates connection plot displaying gap junction data.
|
272
|
+
config: A BMTK simulation config
|
273
|
+
sources: network name(s) to plot
|
274
|
+
targets: network name(s) to plot
|
275
|
+
sids: source node identifier
|
276
|
+
tids: target node identifier
|
277
|
+
no_prepend_pop: dictates if population name is displayed before sid or tid when displaying graph
|
278
|
+
save_file: If plot should be saved
|
279
|
+
type:'convergence' or 'percent' connections
|
280
|
+
"""
|
281
|
+
if not config:
|
282
|
+
raise Exception("config not defined")
|
283
|
+
if not sources or not targets:
|
284
|
+
raise Exception("Sources or targets not defined")
|
285
|
+
if type !='convergence' and type!='percent':
|
286
|
+
raise Exception("type must be 'convergence' or 'percent'")
|
287
|
+
sources = sources.split(",")
|
288
|
+
targets = targets.split(",")
|
289
|
+
if sids:
|
290
|
+
sids = sids.split(",")
|
291
|
+
else:
|
292
|
+
sids = []
|
293
|
+
if tids:
|
294
|
+
tids = tids.split(",")
|
295
|
+
else:
|
296
|
+
tids = []
|
297
|
+
syn_info, data, source_labels, target_labels = util.gap_junction_connections(config=config,nodes=None,edges=None,sources=sources,targets=targets,sids=sids,tids=tids,prepend_pop=not no_prepend_pop,type=type)
|
298
|
+
|
299
|
+
|
300
|
+
def filter_rows(syn_info, data, source_labels, target_labels):
|
301
|
+
new_syn_info = syn_info
|
302
|
+
new_data = data
|
303
|
+
new_source_labels = source_labels
|
304
|
+
new_target_labels = target_labels
|
305
|
+
for row in new_data:
|
306
|
+
row_index = -1
|
307
|
+
try:
|
308
|
+
if((np.isnan(row).all())): #checks if all of a row is nan
|
309
|
+
row_index = np.where(np.isnan(new_data)==np.isnan(row))[0][0]
|
310
|
+
except:
|
311
|
+
row_index = -1
|
312
|
+
finally:
|
313
|
+
if(all(x==0 for x in row)): #checks if all of a row is zeroes
|
314
|
+
row_index = np.where(new_data==row)[0][0]
|
315
|
+
if row_index!=-1: #deletes corresponding row accordingly in all relevant variables.
|
316
|
+
new_syn_info = np.delete(new_syn_info,row_index,0)
|
317
|
+
new_data = np.delete(new_data,row_index,0)
|
318
|
+
new_source_labels = np.delete(new_source_labels,row_index)
|
319
|
+
return new_syn_info, new_data,new_source_labels,new_target_labels
|
320
|
+
|
321
|
+
def filter_rows_and_columns(syn_info,data,source_labels,target_labels):
|
322
|
+
syn_info, data, source_labels, target_labels = filter_rows(syn_info, data, source_labels, target_labels)
|
323
|
+
transposed_syn_info = np.transpose(syn_info) #transpose everything and put it in to make sure columns get filtered
|
324
|
+
transposed_data = np.transpose(data)
|
325
|
+
transposed_source_labels = target_labels
|
326
|
+
transposed_target_labels = source_labels
|
327
|
+
syn_info, data, source_labels, target_labels = filter_rows(transposed_syn_info, transposed_data, transposed_source_labels, transposed_target_labels)
|
328
|
+
filtered_syn_info = np.transpose(syn_info) #transpose everything back to original order after filtering.
|
329
|
+
filtered_data = np.transpose(data)
|
330
|
+
filtered_source_labels = target_labels
|
331
|
+
filtered_target_labels = source_labels
|
332
|
+
return filtered_syn_info,filtered_data,filtered_source_labels,filtered_target_labels
|
333
|
+
|
334
|
+
syn_info, data, source_labels, target_labels = filter_rows_and_columns(syn_info, data, source_labels, target_labels)
|
335
|
+
|
336
|
+
if title == None or title=="":
|
337
|
+
title = 'Gap Junction'
|
338
|
+
if type == 'convergence':
|
339
|
+
title+=' Syn Convergence'
|
340
|
+
elif type == 'percent':
|
341
|
+
title+=' Percent Connectivity'
|
342
|
+
plot_connection_info(syn_info,data,source_labels,target_labels,title, save_file=save_file)
|
343
|
+
return
|
344
|
+
|
270
345
|
def connection_histogram(config=None,nodes=None,edges=None,sources=[],targets=[],sids=[],tids=[],prepend_pop=True,synaptic_info='0',
|
271
346
|
source_cell = None,target_cell = None,include_gap=True):
|
272
347
|
"""
|
@@ -292,10 +367,15 @@ def connection_histogram(config=None,nodes=None,edges=None,sources=[],targets=[]
|
|
292
367
|
if include_gap == False:
|
293
368
|
temp = temp[temp['is_gap_junction'] != True]
|
294
369
|
node_pairs = temp.groupby('target_node_id')['source_node_id'].count()
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
370
|
+
try:
|
371
|
+
conn_mean = statistics.mean(node_pairs.values)
|
372
|
+
conn_std = statistics.stdev(node_pairs.values)
|
373
|
+
conn_median = statistics.median(node_pairs.values)
|
374
|
+
label = "mean {:.2f} std ({:.2f}) median {:.2f}".format(conn_mean,conn_std,conn_median)
|
375
|
+
except: # lazy fix for std not calculated with 1 node
|
376
|
+
conn_mean = statistics.mean(node_pairs.values)
|
377
|
+
conn_median = statistics.median(node_pairs.values)
|
378
|
+
label = "mean {:.2f} median {:.2f}".format(conn_mean,conn_median)
|
299
379
|
plt.hist(node_pairs.values,density=True,bins='auto',stacked=True,label=label)
|
300
380
|
plt.legend()
|
301
381
|
plt.xlabel("# of conns from {} to {}".format(source_cell,target_cell))
|
@@ -420,6 +500,89 @@ def plot_connection_info(text, num, source_labels,target_labels, title, syn_info
|
|
420
500
|
plt.savefig(save_file)
|
421
501
|
return
|
422
502
|
|
503
|
+
def connector_percent_matrix(csv_path = None):
|
504
|
+
"""
|
505
|
+
useful because can display percent connectivity factoring in distance easily
|
506
|
+
Generates a connection matrix from the output of bmtool.connector
|
507
|
+
csv: An output csv from the bmtool.connector classes see function save_connection_report() in that module
|
508
|
+
returns: connection matrix plot
|
509
|
+
"""
|
510
|
+
# Read the CSV data
|
511
|
+
df = pd.read_csv(csv_path)
|
512
|
+
|
513
|
+
# Choose the column to display
|
514
|
+
selected_column = "Fraction of connected pairs in possible ones (%)" # Change this to the desired column name
|
515
|
+
|
516
|
+
# Create an empty dictionary to store connection percentages
|
517
|
+
connection_data = {}
|
518
|
+
|
519
|
+
# Iterate over each row in the DataFrame
|
520
|
+
for index, row in df.iterrows():
|
521
|
+
source = row['Source']
|
522
|
+
target = row['Target']
|
523
|
+
selected_percentage = row[selected_column]
|
524
|
+
|
525
|
+
# If the selected percentage is an array-like string, extract the first and second values
|
526
|
+
if isinstance(selected_percentage, str):
|
527
|
+
selected_percentage = selected_percentage.strip('[]').split()
|
528
|
+
selected_percentage = [float(p) for p in selected_percentage] # Convert to float
|
529
|
+
|
530
|
+
# Store the selected percentage(s) for the source-target pair
|
531
|
+
connection_data[(source, target)] = selected_percentage
|
532
|
+
|
533
|
+
# Prepare unique populations and create an empty matrix
|
534
|
+
populations = sorted(list(set(df['Source'].unique()) | set(df['Target'].unique())))
|
535
|
+
num_populations = len(populations)
|
536
|
+
connection_matrix = np.zeros((num_populations, num_populations), dtype=float)
|
537
|
+
|
538
|
+
# Populate the matrix with the selected connection percentages
|
539
|
+
for source, target in connection_data.keys():
|
540
|
+
source_idx = populations.index(source)
|
541
|
+
target_idx = populations.index(target)
|
542
|
+
connection_probabilities = connection_data[(source, target)]
|
543
|
+
|
544
|
+
# Use the first value for one-way connection from source to target
|
545
|
+
connection_matrix[source_idx][target_idx] = connection_probabilities[0]
|
546
|
+
|
547
|
+
# Check if the source and target are the same population
|
548
|
+
if source == target:
|
549
|
+
# Use the first value (uni-directional) and ignore the second value (bi-directional)
|
550
|
+
continue
|
551
|
+
|
552
|
+
# Check if there is a bidirectional connection and use the second value
|
553
|
+
if len(connection_probabilities) > 1:
|
554
|
+
connection_matrix[target_idx][source_idx] = connection_probabilities[1]
|
555
|
+
|
556
|
+
# Replace NaN values with 0
|
557
|
+
connection_matrix[np.isnan(connection_matrix)] = 0
|
558
|
+
|
559
|
+
# Plot the matrix
|
560
|
+
fig, ax = plt.subplots(figsize=(10, 8))
|
561
|
+
im = ax.imshow(connection_matrix, cmap='viridis', interpolation='nearest')
|
562
|
+
|
563
|
+
# Add annotations
|
564
|
+
for i in range(num_populations):
|
565
|
+
for j in range(num_populations):
|
566
|
+
text = ax.text(j, i, f"{connection_matrix[i, j]:.2f}%",
|
567
|
+
ha="center", va="center", color="w", size=10, weight='bold')
|
568
|
+
|
569
|
+
# Add colorbar
|
570
|
+
plt.colorbar(im, label=f'Percentage of connected pairs ({selected_column})')
|
571
|
+
|
572
|
+
# Set title and axis labels
|
573
|
+
ax.set_title('Neuronal Connection Matrix')
|
574
|
+
ax.set_xlabel('Target Population')
|
575
|
+
ax.set_ylabel('Source Population')
|
576
|
+
|
577
|
+
# Set ticks and labels
|
578
|
+
ax.set_xticks(np.arange(num_populations))
|
579
|
+
ax.set_yticks(np.arange(num_populations))
|
580
|
+
ax.set_xticklabels(populations, rotation=45, ha="right", size=12, weight='semibold')
|
581
|
+
ax.set_yticklabels(populations, size=12, weight='semibold')
|
582
|
+
|
583
|
+
plt.tight_layout()
|
584
|
+
plt.show()
|
585
|
+
|
423
586
|
def raster_old(config=None,title=None,populations=['hippocampus']):
|
424
587
|
"""
|
425
588
|
old function probs dep
|