bmtool 0.5.5__py3-none-any.whl → 0.5.6.1__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.
bmtool/bmplot.py CHANGED
@@ -18,6 +18,7 @@ import statistics
18
18
  import pandas as pd
19
19
  import os
20
20
  import sys
21
+ import re
21
22
 
22
23
  from .util.util import CellVarsFile #, missing_units
23
24
  from bmtk.analyzer.utils import listify
@@ -500,22 +501,78 @@ def plot_connection_info(text, num, source_labels,target_labels, title, syn_info
500
501
  plt.savefig(save_file)
501
502
  return
502
503
 
503
- def connector_percent_matrix(csv_path = None):
504
+ def connector_percent_matrix(csv_path: str = None, exclude_shell: bool = True,
505
+ exclude_assembly: bool = False, title: str = 'Percent connection matrix') -> None:
504
506
  """
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
507
+ Generates and plots a connection matrix based on connection probabilities from a CSV file produced by bmtool.connector.
508
+
509
+ This function is useful for visualizing percent connectivity while factoring in population distance and other parameters.
510
+ It processes the connection data by filtering the 'Source' and 'Target' columns in the CSV, and displays the percentage of
511
+ connected pairs for each population combination in a matrix.
512
+
513
+ Parameters:
514
+ -----------
515
+ csv_path : str
516
+ Path to the CSV file containing the connection data. The CSV should be an output from the bmtool.connector
517
+ classes, specifically generated by the `save_connection_report()` function.
518
+ exclude_shell : bool, optional, default=True
519
+ If True, rows where 'Source' or 'Target' contain "shell" will be excluded from the analysis.
520
+ exclude_assembly : bool, optional, default=False
521
+ If True, skips appending the assembly ID to the population name in the connection matrix.
522
+ title : str, optional, default='Percent connection matrix'
523
+ Title for the generated plot.
524
+
525
+ Returns:
526
+ --------
527
+ None
528
+ Displays a heatmap plot of the connection matrix, showing the percentage of connected pairs between populations.
529
+
530
+ Example:
531
+ --------
532
+ connector_percent_matrix('connections.csv', exclude_shell=True, exclude_assembly=False)
509
533
  """
510
534
  # Read the CSV data
511
535
  df = pd.read_csv(csv_path)
512
536
 
513
537
  # Choose the column to display
514
- selected_column = "Fraction of connected pairs in possible ones (%)" # Change this to the desired column name
538
+ selected_column = "Fraction of connected pairs in possible ones (%)" # Can change this for different column but this is best i think
515
539
 
516
540
  # Create an empty dictionary to store connection percentages
517
541
  connection_data = {}
518
542
 
543
+ def filter_dataframe(df, column_name, exclude_shell=exclude_shell, exclude_assembly=exclude_assembly):
544
+ def process_string(string):
545
+ # Use regex to extract 'FSI' or other match
546
+ match = re.search(r"\[\'(.*?)\'\]", string) # the cell name from ['fsi']
547
+ ints_in_string = re.findall(r'\d+', string) # get all ints in the string
548
+
549
+ # Conditionally remove rows containing "shell"
550
+ if exclude_shell and "shell" in string:
551
+ return None # Mark row for removal
552
+ else:
553
+ if match:
554
+ filtered_string = match.group(1)
555
+
556
+ # Conditionally process "assembly" in the string
557
+ if not exclude_assembly and "assembly" in string:
558
+ assem_value = int(ints_in_string[0])
559
+ filtered_string = filtered_string + str(f"-{assem_value}")
560
+
561
+ if 'Gap' in string:
562
+ filtered_string = filtered_string + "-Gap"
563
+ return filtered_string
564
+ return string # If no match, return the original string
565
+
566
+ # Apply the filtering logic to the specified column
567
+ df[column_name] = df[column_name].apply(process_string)
568
+
569
+ # Remove rows where None was returned in the specified column
570
+ df = df.dropna(subset=[column_name])
571
+
572
+ return df
573
+
574
+ df = filter_dataframe(df,'Source')
575
+ df = filter_dataframe(df,'Target')
519
576
  # Iterate over each row in the DataFrame
520
577
  for index, row in df.iterrows():
521
578
  source = row['Source']
@@ -570,7 +627,7 @@ def connector_percent_matrix(csv_path = None):
570
627
  plt.colorbar(im, label=f'Percentage of connected pairs ({selected_column})')
571
628
 
572
629
  # Set title and axis labels
573
- ax.set_title('Neuronal Connection Matrix')
630
+ ax.set_title(title)
574
631
  ax.set_xlabel('Target Population')
575
632
  ax.set_ylabel('Source Population')
576
633
 
bmtool/connectors.py CHANGED
@@ -10,6 +10,8 @@ import re
10
10
 
11
11
  rng = np.random.default_rng()
12
12
 
13
+ report_name = 'conn.csv'
14
+
13
15
  ##############################################################################
14
16
  ############################## CONNECT CELLS #################################
15
17
 
@@ -534,7 +536,7 @@ class ReciprocalConnector(AbstractConnector):
534
536
  pr=0., pr_arg=None, estimate_rho=True, rho=None,
535
537
  dist_range_forward=None, dist_range_backward=None,
536
538
  n_syn0=1, n_syn1=1, autapses=False,
537
- quick_pop_check=False, cache_data=True, verbose=True,save_report=True,report_name='connection_report.csv'):
539
+ quick_pop_check=False, cache_data=True, verbose=True,save_report=True,report_name=None):
538
540
  args = locals()
539
541
  var_set = ('p0', 'p0_arg', 'p1', 'p1_arg',
540
542
  'pr', 'pr_arg', 'n_syn0', 'n_syn1')
@@ -553,6 +555,9 @@ class ReciprocalConnector(AbstractConnector):
553
555
  self.cache = self.ConnectorCache(cache_data and self.estimate_rho)
554
556
  self.verbose = verbose
555
557
  self.save_report = save_report
558
+
559
+ if report_name is None:
560
+ report_name = globals().get('report_name', 'default_report.csv')
556
561
  self.report_name = report_name
557
562
 
558
563
  self.conn_prop = [{}, {}]
@@ -1104,14 +1109,17 @@ class UnidirectionConnector(AbstractConnector):
1104
1109
  This is useful in similar manner as in ReciprocalConnector.
1105
1110
  """
1106
1111
 
1107
- def __init__(self, p=1., p_arg=None, n_syn=1, verbose=True,save_report=True,report_name='connection_report.csv'):
1112
+ def __init__(self, p=1., p_arg=None, n_syn=1, verbose=True,save_report=True,report_name=None):
1108
1113
  args = locals()
1109
1114
  var_set = ('p', 'p_arg', 'n_syn')
1110
1115
  self.vars = {key: args[key] for key in var_set}
1111
1116
 
1112
1117
  self.verbose = verbose
1113
1118
  self.save_report = save_report
1119
+ if report_name is None:
1120
+ report_name = globals().get('report_name', 'default_report.csv')
1114
1121
  self.report_name = report_name
1122
+
1115
1123
  self.conn_prop = {}
1116
1124
  self.iter_count = 0
1117
1125
 
@@ -1214,14 +1222,16 @@ class UnidirectionConnector(AbstractConnector):
1214
1222
  def save_connection_report(self):
1215
1223
  """Save connections into a CSV file to be read from later"""
1216
1224
  src_str, trg_str = self.get_nodes_info()
1217
- n_conn, n_poss, n_pair, fraction = self.connection_number()
1225
+
1226
+ possible_fraction = (100. * self.n_conn / self.n_poss)
1227
+ all_fraction = (100. * self.n_conn / self.n_pair)
1218
1228
 
1219
1229
  # Extract the population name from source_str and target_str
1220
1230
  data = {
1221
1231
  "Source": [src_str],
1222
1232
  "Target": [trg_str],
1223
- "Fraction of connected pairs in possible ones (%)": [fraction[0]*100],
1224
- "Fraction of connected pairs in all pairs (%)": [fraction[1]*100]
1233
+ "Fraction of connected pairs in possible ones (%)": [possible_fraction],
1234
+ "Fraction of connected pairs in all pairs (%)": [all_fraction]
1225
1235
  }
1226
1236
  df = pd.DataFrame(data)
1227
1237
 
@@ -1257,8 +1267,9 @@ class GapJunction(UnidirectionConnector):
1257
1267
  Similar to `UnidirectionConnector`.
1258
1268
  """
1259
1269
 
1260
- def __init__(self, p=1., p_arg=None, verbose=True,report_name='connection_report.csv'):
1261
- super().__init__(p=p, p_arg=p_arg, verbose=verbose,report_name=report_name)
1270
+ def __init__(self, p=1., p_arg=None, verbose=True,report_name=None):
1271
+ super().__init__(p=p, p_arg=p_arg, verbose=verbose,report_name=None)
1272
+
1262
1273
 
1263
1274
  def setup_nodes(self, source=None, target=None):
1264
1275
  super().setup_nodes(source=source, target=target)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: bmtool
3
- Version: 0.5.5
3
+ Version: 0.5.6.1
4
4
  Summary: BMTool
5
5
  Home-page: https://github.com/cyneuro/bmtool
6
6
  Download-URL:
@@ -1,8 +1,8 @@
1
1
  bmtool/SLURM.py,sha256=8XbzNLIQfE_lNRd_Z8ya2PEDT4TqhVnDZkil-ckLUCU,11508
2
2
  bmtool/__init__.py,sha256=ZStTNkAJHJxG7Pwiy5UgCzC4KlhMS5pUNPtUJZVwL_Y,136
3
3
  bmtool/__main__.py,sha256=TmFkmDxjZ6250nYD4cgGhn-tbJeEm0u-EMz2ajAN9vE,650
4
- bmtool/bmplot.py,sha256=p39s3SwXvG1D7ujYwY5zCmeUql2epnzLKqXZMBn_vjo,43511
5
- bmtool/connectors.py,sha256=RPQGFfefKxJxu5sM6uge-RKHvLAE96EVFh8xXj8HR0A,71560
4
+ bmtool/bmplot.py,sha256=-kw4VOcTnA22JVQi1PzH2E308pcmY1Xo7oqgCnm0cC8,46260
5
+ bmtool/connectors.py,sha256=d5Pt66f9UHm8YY2qJ0mtYbASimczOzfviFxZQWkazjs,71804
6
6
  bmtool/graphs.py,sha256=K8BiughRUeXFVvAgo8UzrwpSClIVg7UfmIcvtEsEsk0,6020
7
7
  bmtool/manage.py,sha256=_lCU0qBQZ4jSxjzAJUd09JEetb--cud7KZgxQFbLGSY,657
8
8
  bmtool/plot_commands.py,sha256=Tqujyf0c0u8olhiHOMwgUSJXIIE1hgjv6otb25G9cA0,12298
@@ -16,9 +16,9 @@ bmtool/util/commands.py,sha256=zJF-fiLk0b8LyzHDfvewUyS7iumOxVnj33IkJDzux4M,64396
16
16
  bmtool/util/util.py,sha256=24E5rUoDU86nqypDF4uZJkuJKO1BrwrQE8lZzAxu1kw,56770
17
17
  bmtool/util/neuron/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
18
18
  bmtool/util/neuron/celltuner.py,sha256=xSRpRN6DhPFz4q5buq_W8UmsD7BbUrkzYBEbKVloYss,87194
19
- bmtool-0.5.5.dist-info/LICENSE,sha256=qrXg2jj6kz5d0EnN11hllcQt2fcWVNumx0xNbV05nyM,1068
20
- bmtool-0.5.5.dist-info/METADATA,sha256=aRwr0X8bt33WJDcPh6Js-YULLKSfTlD_nPsMn1bSZTs,24105
21
- bmtool-0.5.5.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
22
- bmtool-0.5.5.dist-info/entry_points.txt,sha256=0-BHZ6nUnh0twWw9SXNTiRmKjDnb1VO2DfG_-oprhAc,45
23
- bmtool-0.5.5.dist-info/top_level.txt,sha256=gpd2Sj-L9tWbuJEd5E8C8S8XkNm5yUE76klUYcM-eWM,7
24
- bmtool-0.5.5.dist-info/RECORD,,
19
+ bmtool-0.5.6.1.dist-info/LICENSE,sha256=qrXg2jj6kz5d0EnN11hllcQt2fcWVNumx0xNbV05nyM,1068
20
+ bmtool-0.5.6.1.dist-info/METADATA,sha256=8LEjuoxY62XgrDbHqCvPhn67mAnj18aAlKilm1A3Mv0,24107
21
+ bmtool-0.5.6.1.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
22
+ bmtool-0.5.6.1.dist-info/entry_points.txt,sha256=0-BHZ6nUnh0twWw9SXNTiRmKjDnb1VO2DfG_-oprhAc,45
23
+ bmtool-0.5.6.1.dist-info/top_level.txt,sha256=gpd2Sj-L9tWbuJEd5E8C8S8XkNm5yUE76klUYcM-eWM,7
24
+ bmtool-0.5.6.1.dist-info/RECORD,,