bmtool 0.5.9.7__py3-none-any.whl → 0.5.9.9__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
@@ -274,7 +274,7 @@ def divergence_connection_matrix(config=None,title=None,sources=None, targets=No
274
274
  plot_connection_info(syn_info,data,source_labels,target_labels,title, save_file=save_file)
275
275
  return
276
276
 
277
- 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'):
277
+ def gap_junction_matrix(config=None,title=None,sources=None, targets=None, sids=None,tids=None, no_prepend_pop=False,save_file=None,method='convergence'):
278
278
  """
279
279
  Generates connection plot displaying gap junction data.
280
280
  config: A BMTK simulation config
@@ -290,7 +290,7 @@ def gap_junction_matrix(config=None,title=None,sources=None, targets=None, sids=
290
290
  raise Exception("config not defined")
291
291
  if not sources or not targets:
292
292
  raise Exception("Sources or targets not defined")
293
- if type !='convergence' and type!='percent':
293
+ if method !='convergence' and method!='percent':
294
294
  raise Exception("type must be 'convergence' or 'percent'")
295
295
  sources = sources.split(",")
296
296
  targets = targets.split(",")
@@ -302,7 +302,7 @@ def gap_junction_matrix(config=None,title=None,sources=None, targets=None, sids=
302
302
  tids = tids.split(",")
303
303
  else:
304
304
  tids = []
305
- 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)
305
+ 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,method=method)
306
306
 
307
307
 
308
308
  def filter_rows(syn_info, data, source_labels, target_labels):
@@ -350,7 +350,7 @@ def gap_junction_matrix(config=None,title=None,sources=None, targets=None, sids=
350
350
  plot_connection_info(syn_info,data,source_labels,target_labels,title, save_file=save_file)
351
351
  return
352
352
 
353
- def connection_histogram(config=None,nodes=None,edges=None,sources=[],targets=[],sids=[],tids=[],prepend_pop=True,synaptic_info='0',
353
+ def connection_histogram(config=None,nodes=None,edges=None,sources=[],targets=[],sids=[],tids=[],no_prepend_pop=True,synaptic_info='0',
354
354
  source_cell = None,target_cell = None,include_gap=True):
355
355
  """
356
356
  Generates histogram of number of connections individual cells in a population receieve from another population
@@ -379,15 +379,15 @@ def connection_histogram(config=None,nodes=None,edges=None,sources=[],targets=[]
379
379
  conn_mean = statistics.mean(node_pairs.values)
380
380
  conn_std = statistics.stdev(node_pairs.values)
381
381
  conn_median = statistics.median(node_pairs.values)
382
- label = "mean {:.2f} std ({:.2f}) median {:.2f}".format(conn_mean,conn_std,conn_median)
382
+ label = "mean {:.2f} std {:.2f} median {:.2f}".format(conn_mean,conn_std,conn_median)
383
383
  except: # lazy fix for std not calculated with 1 node
384
384
  conn_mean = statistics.mean(node_pairs.values)
385
385
  conn_median = statistics.median(node_pairs.values)
386
386
  label = "mean {:.2f} median {:.2f}".format(conn_mean,conn_median)
387
- plt.hist(node_pairs.values,density=True,bins='auto',stacked=True,label=label)
387
+ plt.hist(node_pairs.values,density=False,bins='auto',stacked=True,label=label)
388
388
  plt.legend()
389
389
  plt.xlabel("# of conns from {} to {}".format(source_cell,target_cell))
390
- plt.ylabel("Density")
390
+ plt.ylabel("# of cells")
391
391
  plt.show()
392
392
  else: # dont care about other cell pairs so pass
393
393
  pass
@@ -406,10 +406,10 @@ def connection_histogram(config=None,nodes=None,edges=None,sources=[],targets=[]
406
406
  tids = tids.split(",")
407
407
  else:
408
408
  tids = []
409
- util.relation_matrix(config,nodes,edges,sources,targets,sids,tids,prepend_pop,relation_func=connection_pair_histogram,synaptic_info=synaptic_info)
409
+ util.relation_matrix(config,nodes,edges,sources,targets,sids,tids,not no_prepend_pop,relation_func=connection_pair_histogram,synaptic_info=synaptic_info)
410
410
 
411
- def connection_distance(config: str,source: str,target: str,
412
- source_cell_id: int,target_id_type: str) -> None:
411
+ def connection_distance(config: str,sources: str,targets: str,
412
+ source_cell_id: int,target_id_type: str,ignore_z:bool=False) -> None:
413
413
  """
414
414
  Plots the 3D spatial distribution of target nodes relative to a source node
415
415
  and a histogram of distances from the source node to each target node.
@@ -421,11 +421,12 @@ def connection_distance(config: str,source: str,target: str,
421
421
  targets: (str) network name(s) to plot
422
422
  source_cell_id : (int) ID of the source cell for calculating distances to target nodes.
423
423
  target_id_type : (str) A string to filter target nodes based off the target_query.
424
+ ignore_z : (bool) A bool to ignore_z axis or not for when calculating distance default is False
424
425
 
425
426
  """
426
427
  if not config:
427
428
  raise Exception("config not defined")
428
- if not source or not target:
429
+ if not sources or not targets:
429
430
  raise Exception("Sources or targets not defined")
430
431
  #if source != target:
431
432
  #raise Exception("Code is setup for source and target to be the same! Look at source code for function to add feature")
@@ -433,8 +434,8 @@ def connection_distance(config: str,source: str,target: str,
433
434
  # Load nodes and edges based on config file
434
435
  nodes, edges = util.load_nodes_edges_from_config(config)
435
436
 
436
- edge_network = source + "_to_" + target
437
- node_network = source
437
+ edge_network = sources + "_to_" + targets
438
+ node_network = sources
438
439
 
439
440
  # Filter edges to obtain connections originating from the source node
440
441
  edge = edges[edge_network]
@@ -450,16 +451,25 @@ def connection_distance(config: str,source: str,target: str,
450
451
  source_node = node.loc[node.index == source_cell_id]
451
452
 
452
453
  # Calculate distances between source node and each target node
453
- target_positions = target_nodes[['pos_x', 'pos_y', 'pos_z']].values
454
- source_position = np.array([source_node['pos_x'], source_node['pos_y'], source_node['pos_z']]).ravel() # Ensure 1D shape
454
+ if ignore_z:
455
+ target_positions = target_nodes[['pos_x', 'pos_y']].values
456
+ source_position = np.array([source_node['pos_x'], source_node['pos_y']]).ravel() # Ensure 1D shape
457
+ else:
458
+ target_positions = target_nodes[['pos_x', 'pos_y', 'pos_z']].values
459
+ source_position = np.array([source_node['pos_x'], source_node['pos_y'], source_node['pos_z']]).ravel() # Ensure 1D shape
455
460
  distances = np.linalg.norm(target_positions - source_position, axis=1)
456
461
 
457
- # Plot positions of source and target nodes in 3D space
458
- fig = plt.figure(figsize=(8, 6))
459
- ax = fig.add_subplot(111, projection='3d')
460
-
461
- ax.scatter(target_nodes['pos_x'], target_nodes['pos_y'], target_nodes['pos_z'], c='blue', label="target cells")
462
- ax.scatter(source_node['pos_x'], source_node['pos_y'], source_node['pos_z'], c='red', label="source cell")
462
+ # Plot positions of source and target nodes in 3D space or 2D
463
+ if ignore_z:
464
+ fig = plt.figure(figsize=(8, 6))
465
+ ax = fig.add_subplot(111)
466
+ ax.scatter(target_nodes['pos_x'], target_nodes['pos_y'], c='blue', label="target cells")
467
+ ax.scatter(source_node['pos_x'], source_node['pos_y'], c='red', label="source cell")
468
+ else:
469
+ fig = plt.figure(figsize=(8, 6))
470
+ ax = fig.add_subplot(111, projection='3d')
471
+ ax.scatter(target_nodes['pos_x'], target_nodes['pos_y'], target_nodes['pos_z'], c='blue', label="target cells")
472
+ ax.scatter(source_node['pos_x'], source_node['pos_y'], source_node['pos_z'], c='red', label="source cell")
463
473
 
464
474
  # Optional: Add text annotations for distances
465
475
  # for i, distance in enumerate(distances):
@@ -474,7 +484,7 @@ def connection_distance(config: str,source: str,target: str,
474
484
  plt.hist(distances, bins=20, color='blue', edgecolor='black')
475
485
  plt.xlabel("Distance")
476
486
  plt.ylabel("Count")
477
- plt.title("Distance from Source Node to Each Target Node")
487
+ plt.title(f"Distance from Source Node to Each Target Node")
478
488
  plt.grid(True)
479
489
  plt.show()
480
490
 
@@ -564,16 +574,16 @@ def plot_connection_info(text, num, source_labels,target_labels, title, syn_info
564
574
  if syn_info =='2' or syn_info =='3':
565
575
  if num_source > 8 and num_source <20:
566
576
  fig_text = ax1.text(j, i, edge_info,
567
- ha="center", va="center", color="k",rotation=37.5, size=8, weight = 'semibold')
577
+ ha="center", va="center", color="w",rotation=37.5, size=8, weight = 'semi\bold')
568
578
  elif num_source > 20:
569
579
  fig_text = ax1.text(j, i, edge_info,
570
- ha="center", va="center", color="k",rotation=37.5, size=7, weight = 'semibold')
580
+ ha="center", va="center", color="w",rotation=37.5, size=7, weight = 'semibold')
571
581
  else:
572
582
  fig_text = ax1.text(j, i, edge_info,
573
- ha="center", va="center", color="k",rotation=37.5, size=11, weight = 'semibold')
583
+ ha="center", va="center", color="w",rotation=37.5, size=11, weight = 'semibold')
574
584
  else:
575
585
  fig_text = ax1.text(j, i, edge_info,
576
- ha="center", va="center", color="k", size=11, weight = 'semibold')
586
+ ha="center", va="center", color="w", size=11, weight = 'semibold')
577
587
 
578
588
  ax1.set_ylabel('Source', size=11, weight = 'semibold')
579
589
  ax1.set_xlabel('Target', size=11, weight = 'semibold')
@@ -589,8 +599,7 @@ def plot_connection_info(text, num, source_labels,target_labels, title, syn_info
589
599
  else:
590
600
  return
591
601
 
592
- def connector_percent_matrix(csv_path: str = None, exclude_shell: bool = True,
593
- exclude_assembly: bool = False, title: str = 'Percent connection matrix') -> None:
602
+ def connector_percent_matrix(csv_path: str = None, exclude_strings=None, title: str = 'Percent connection matrix', pop_order=None) -> None:
594
603
  """
595
604
  Generates and plots a connection matrix based on connection probabilities from a CSV file produced by bmtool.connector.
596
605
 
@@ -603,123 +612,92 @@ def connector_percent_matrix(csv_path: str = None, exclude_shell: bool = True,
603
612
  csv_path : str
604
613
  Path to the CSV file containing the connection data. The CSV should be an output from the bmtool.connector
605
614
  classes, specifically generated by the `save_connection_report()` function.
606
- exclude_shell : bool, optional, default=True
607
- If True, rows where 'Source' or 'Target' contain "shell" will be excluded from the analysis.
608
- exclude_assembly : bool, optional, default=False
609
- If True, skips appending the assembly ID to the population name in the connection matrix.
615
+ exclude_strings : list of str, optional
616
+ List of strings to exclude rows where 'Source' or 'Target' contain these strings.
610
617
  title : str, optional, default='Percent connection matrix'
611
618
  Title for the generated plot.
619
+ pop_order : list of str, optional
620
+ List of population labels to specify the order for the x- and y-ticks in the plot.
612
621
 
613
622
  Returns:
614
623
  --------
615
624
  None
616
625
  Displays a heatmap plot of the connection matrix, showing the percentage of connected pairs between populations.
617
-
618
- Example:
619
- --------
620
- connector_percent_matrix('connections.csv', exclude_shell=True, exclude_assembly=False)
621
626
  """
622
627
  # Read the CSV data
623
628
  df = pd.read_csv(csv_path)
624
629
 
625
630
  # Choose the column to display
626
- selected_column = "Fraction of connected pairs in possible ones (%)" # Can change this for different column but this is best i think
627
-
628
- # Create an empty dictionary to store connection percentages
629
- connection_data = {}
631
+ selected_column = "Percent connectionivity within possible connections"
630
632
 
631
- def filter_dataframe(df, column_name, exclude_shell=exclude_shell, exclude_assembly=exclude_assembly):
633
+ # Filter the DataFrame based on exclude_strings
634
+ def filter_dataframe(df, column_name, exclude_strings):
632
635
  def process_string(string):
633
- # Use regex to extract 'FSI' or other match
634
- match = re.search(r"\[\'(.*?)\'\]", string) # the cell name from ['fsi']
635
- ints_in_string = re.findall(r'\d+', string) # get all ints in the string
636
-
637
- # Conditionally remove rows containing "shell"
638
- if exclude_shell and "shell" in string:
639
- return None # Mark row for removal
640
- else:
641
- if match:
642
- filtered_string = match.group(1)
643
-
644
- # Conditionally process "assembly" in the string
645
- if not exclude_assembly and "assembly" in string:
646
- assem_value = int(ints_in_string[0])
647
- filtered_string = filtered_string + str(f"-{assem_value}")
648
-
649
- if 'Gap' in string:
636
+ match = re.search(r"\[\'(.*?)\'\]", string)
637
+ if exclude_strings and any(ex_string in string for ex_string in exclude_strings):
638
+ return None
639
+ elif match:
640
+ filtered_string = match.group(1)
641
+ if 'Gap' in string:
650
642
  filtered_string = filtered_string + "-Gap"
651
- return filtered_string
652
- return string # If no match, return the original string
643
+ return filtered_string # Return matched string
653
644
 
654
- # Apply the filtering logic to the specified column
655
- df[column_name] = df[column_name].apply(process_string)
645
+ return string # If no match, return the original string
656
646
 
657
- # Remove rows where None was returned in the specified column
647
+ df[column_name] = df[column_name].apply(process_string)
658
648
  df = df.dropna(subset=[column_name])
659
-
660
649
  return df
661
650
 
662
- df = filter_dataframe(df,'Source')
663
- df = filter_dataframe(df,'Target')
664
- # Iterate over each row in the DataFrame
665
- for index, row in df.iterrows():
666
- source = row['Source']
667
- target = row['Target']
668
- selected_percentage = row[selected_column]
669
-
670
- # If the selected percentage is an array-like string, extract the first and second values
651
+ df = filter_dataframe(df, 'Source', exclude_strings)
652
+ df = filter_dataframe(df, 'Target', exclude_strings)
653
+
654
+ # Prepare connection data
655
+ connection_data = {}
656
+ for _, row in df.iterrows():
657
+ source, target, selected_percentage = row['Source'], row['Target'], row[selected_column]
671
658
  if isinstance(selected_percentage, str):
672
- selected_percentage = selected_percentage.strip('[]').split()
673
- selected_percentage = [float(p) for p in selected_percentage] # Convert to float
674
-
675
- # Store the selected percentage(s) for the source-target pair
659
+ selected_percentage = [float(p) for p in selected_percentage.strip('[]').split()]
676
660
  connection_data[(source, target)] = selected_percentage
677
661
 
678
- # Prepare unique populations and create an empty matrix
662
+ # Determine population order
679
663
  populations = sorted(list(set(df['Source'].unique()) | set(df['Target'].unique())))
664
+ if pop_order:
665
+ populations = [pop for pop in pop_order if pop in populations] # Order according to pop_order, if provided
680
666
  num_populations = len(populations)
667
+
668
+ # Create an empty matrix and populate it
681
669
  connection_matrix = np.zeros((num_populations, num_populations), dtype=float)
682
-
683
- # Populate the matrix with the selected connection percentages
684
- for source, target in connection_data.keys():
685
- source_idx = populations.index(source)
686
- target_idx = populations.index(target)
687
- connection_probabilities = connection_data[(source, target)]
688
-
689
- # Use the first value for one-way connection from source to target
690
- connection_matrix[source_idx][target_idx] = connection_probabilities[0]
691
-
692
- # Check if the source and target are the same population
693
- if source == target:
694
- # Use the first value (uni-directional) and ignore the second value (bi-directional)
695
- continue
696
-
697
- # Check if there is a bidirectional connection and use the second value
698
- if len(connection_probabilities) > 1:
699
- connection_matrix[target_idx][source_idx] = connection_probabilities[1]
700
-
701
- # Replace NaN values with 0
702
- connection_matrix[np.isnan(connection_matrix)] = 0
703
-
704
- # Plot the matrix
670
+ for (source, target), probabilities in connection_data.items():
671
+ if source in populations and target in populations:
672
+ source_idx = populations.index(source)
673
+ target_idx = populations.index(target)
674
+ connection_matrix[source_idx][target_idx] = probabilities[0]
675
+ if len(probabilities) == 1:
676
+ connection_matrix[source_idx][target_idx] = probabilities[0]
677
+ if len(probabilities) == 2:
678
+ connection_matrix[source_idx][target_idx] = probabilities[0]
679
+ if len(probabilities) == 3:
680
+ connection_matrix[source_idx][target_idx] = probabilities[0]
681
+ connection_matrix[target_idx][source_idx] = probabilities[1]
682
+
683
+ # Plotting
705
684
  fig, ax = plt.subplots(figsize=(10, 8))
706
685
  im = ax.imshow(connection_matrix, cmap='viridis', interpolation='nearest')
707
686
 
708
687
  # Add annotations
709
688
  for i in range(num_populations):
710
689
  for j in range(num_populations):
711
- text = ax.text(j, i, f"{connection_matrix[i, j]:.2f}%",
712
- ha="center", va="center", color="w", size=10, weight='bold')
690
+ text = ax.text(j, i, f"{connection_matrix[i, j]:.2f}%", ha="center", va="center", color="w", size=10, weight='semibold')
713
691
 
714
692
  # Add colorbar
715
- plt.colorbar(im, label=f'Percentage of connected pairs ({selected_column})')
693
+ plt.colorbar(im, label=f'{selected_column}')
716
694
 
717
695
  # Set title and axis labels
718
696
  ax.set_title(title)
719
697
  ax.set_xlabel('Target Population')
720
698
  ax.set_ylabel('Source Population')
721
699
 
722
- # Set ticks and labels
700
+ # Set ticks and labels based on populations in specified order
723
701
  ax.set_xticks(np.arange(num_populations))
724
702
  ax.set_yticks(np.arange(num_populations))
725
703
  ax.set_xticklabels(populations, rotation=45, ha="right", size=12, weight='semibold')
@@ -914,7 +892,7 @@ def plot_3d_positions(config=None, populations_list=None, group_by=None, title=N
914
892
 
915
893
  return
916
894
 
917
- def cell_rotation_3d(config=None, populations_list=None, group_by=None, title=None, save_file=None, quiver_length=None, arrow_length_ratio=None, group=None, max_cells=1000000):
895
+ def plot_3d_cell_rotation(config=None, populations_list=None, group_by=None, title=None, save_file=None, quiver_length=None, arrow_length_ratio=None, group=None, subset=None):
918
896
  from scipy.spatial.transform import Rotation as R
919
897
  if not config:
920
898
  raise Exception("config not defined")
@@ -957,23 +935,16 @@ def cell_rotation_3d(config=None, populations_list=None, group_by=None, title=No
957
935
  groupings = [(None, nodes_df)]
958
936
  color_map = ['blue']
959
937
 
960
- cells_plotted = 0
961
938
  for color, (group_name, group_df) in zip(color_map, groupings):
939
+ if subset is not None:
940
+ group_df = group_df.iloc[::subset]
941
+
962
942
  if group and group_name not in group.split(","):
963
943
  continue
964
944
 
965
945
  if "pos_x" not in group_df or "rotation_angle_xaxis" not in group_df:
966
946
  continue
967
947
 
968
- if cells_plotted >= max_cells:
969
- continue
970
-
971
- if len(group_df) + cells_plotted > max_cells:
972
- total_remaining = max_cells - cells_plotted
973
- group_df = group_df[:total_remaining]
974
-
975
- cells_plotted += len(group_df)
976
-
977
948
  X = group_df["pos_x"]
978
949
  Y = group_df["pos_y"]
979
950
  Z = group_df["pos_z"]
bmtool/connectors.py CHANGED
@@ -1064,8 +1064,8 @@ class ReciprocalConnector(AbstractConnector):
1064
1064
  data = {
1065
1065
  "Source": [src_str],
1066
1066
  "Target": [trg_str],
1067
- "Fraction of connected pairs in possible ones (%)": [fraction[0]*100],
1068
- "Fraction of connected pairs in all pairs (%)": [fraction[1]*100]
1067
+ "Percent connectionivity within possible connections": [fraction[0]*100],
1068
+ "Percent connectionivity within all connections": [fraction[1]*100]
1069
1069
  }
1070
1070
  df = pd.DataFrame(data)
1071
1071
 
@@ -1235,8 +1235,8 @@ class UnidirectionConnector(AbstractConnector):
1235
1235
  data = {
1236
1236
  "Source": [src_str],
1237
1237
  "Target": [trg_str],
1238
- "Fraction of connected pairs in possible ones (%)": [possible_fraction],
1239
- "Fraction of connected pairs in all pairs (%)": [all_fraction]
1238
+ "Percent connectionivity within possible connections": [possible_fraction],
1239
+ "Percent connectionivity within all connections": [all_fraction]
1240
1240
  }
1241
1241
  df = pd.DataFrame(data)
1242
1242
 
@@ -1272,8 +1272,8 @@ class GapJunction(UnidirectionConnector):
1272
1272
  Similar to `UnidirectionConnector`.
1273
1273
  """
1274
1274
 
1275
- def __init__(self, p=1., p_arg=None, verbose=True,report_name=None):
1276
- super().__init__(p=p, p_arg=p_arg, verbose=verbose,report_name=None)
1275
+ def __init__(self, p=1., p_arg=None, verbose=True,save_report=True,report_name=None):
1276
+ super().__init__(p=p, p_arg=p_arg, verbose=verbose,save_report=save_report,report_name=None)
1277
1277
 
1278
1278
 
1279
1279
  def setup_nodes(self, source=None, target=None):
@@ -1336,8 +1336,8 @@ class GapJunction(UnidirectionConnector):
1336
1336
  data = {
1337
1337
  "Source": [src_str+"Gap"],
1338
1338
  "Target": [trg_str+"Gap"],
1339
- "Fraction of connected pairs in possible ones (%)": [fraction_0*100],
1340
- "Fraction of connected pairs in all pairs (%)": [fraction_1*100]
1339
+ "Percent connectionivity within possible connections": [fraction_0*100],
1340
+ "Percent connectionivity within all connections": [fraction_1*100]
1341
1341
  }
1342
1342
  df = pd.DataFrame(data)
1343
1343
 
bmtool/synapses.py CHANGED
@@ -649,6 +649,4 @@ class SynapseTuner:
649
649
  display(ui)
650
650
 
651
651
 
652
-
653
-
654
652
 
bmtool/util/util.py CHANGED
@@ -736,8 +736,7 @@ def connection_divergence(config=None,nodes=None,edges=None,sources=[],targets=[
736
736
 
737
737
  return relation_matrix(config,nodes,edges,sources,targets,sids,tids,prepend_pop,relation_func=total_connection_relationship)
738
738
 
739
- def gap_junction_connections(config=None,nodes=None,edges=None,sources=[],targets=[],sids=[],tids=[],prepend_pop=True,type='convergence'):
740
- import pandas as pd
739
+ def gap_junction_connections(config=None,nodes=None,edges=None,sources=[],targets=[],sids=[],tids=[],prepend_pop=True,method='convergence'):
741
740
 
742
741
 
743
742
  def total_connection_relationship(**kwargs): #reduced version of original function; only gets mean+std
@@ -751,7 +750,7 @@ def gap_junction_connections(config=None,nodes=None,edges=None,sources=[],target
751
750
  #print(cons)
752
751
 
753
752
  try:
754
- cons = cons[cons['is_gap_junction'] != True]
753
+ cons = cons[cons['is_gap_junction'] == True]
755
754
  except:
756
755
  raise Exception("no gap junctions found to drop from connections")
757
756
  mean = cons['target_node_id'].value_counts().mean()
@@ -770,7 +769,7 @@ def gap_junction_connections(config=None,nodes=None,edges=None,sources=[],target
770
769
  cons = edges[(edges[source_id_type] == source_id) & (edges[target_id_type]==target_id)]
771
770
  #add functionality that shows only the one's with gap_junctions
772
771
  try:
773
- cons = cons[cons['is_gap_junction'] != True]
772
+ cons = cons[cons['is_gap_junction'] == True]
774
773
  except:
775
774
  raise Exception("no gap junctions found to drop from connections")
776
775
 
@@ -780,20 +779,15 @@ def gap_junction_connections(config=None,nodes=None,edges=None,sources=[],target
780
779
  num_targets = t_list[target_id_type].value_counts().sort_index().loc[target_id]
781
780
 
782
781
 
783
- total = round(total_cons / (num_sources*num_targets) * 100,2)
782
+ total = round(total_cons / (num_sources*num_targets) * 100,2) * 2 #not sure why but the percent is off by roughly 2 times ill make khuram fix it
784
783
  return total
785
784
 
786
- if type == 'convergence':
785
+ if method == 'convergence':
787
786
  return relation_matrix(config,nodes,edges,sources,targets,sids,tids,prepend_pop,relation_func=total_connection_relationship)
788
- elif type == 'percent':
787
+ elif method == 'percent':
789
788
  return relation_matrix(config,nodes,edges,sources,targets,sids,tids,prepend_pop,relation_func=precent_func)
790
789
 
791
790
 
792
- def gap_junction_percent_connections(config=None,nodes=None,edges=None,sources=[],targets=[],sids=[],tids=[],prepend_pop=True,method=None):
793
- import pandas as pd
794
-
795
-
796
-
797
791
  def connection_probabilities(config=None,nodes=None,edges=None,sources=[],
798
792
  targets=[],sids=[],tids=[],prepend_pop=True,dist_X=True,dist_Y=True,dist_Z=True,num_bins=10,include_gap=True):
799
793
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: bmtool
3
- Version: 0.5.9.7
3
+ Version: 0.5.9.9
4
4
  Summary: BMTool
5
5
  Home-page: https://github.com/cyneuro/bmtool
6
6
  Download-URL:
@@ -38,12 +38,12 @@ A collection of modules to make developing [Neuron](https://www.neuron.yale.edu/
38
38
  [![license](https://img.shields.io/github/license/mashape/apistatus.svg?maxAge=2592000)](https://github.com/cyneuro/bmtool/blob/master/LICENSE)
39
39
 
40
40
  ## Table of Contents
41
- - [Getting Started](#Getting-Started)
42
- - [CLI](#CLI)
43
- - [Single Cell](#Single-Cell-Module)
41
+ - [Getting Started](#getting-started)
42
+ - [CLI](#cli)
43
+ - [Single Cell](#single-cell-module)
44
44
  - [Synapses](#synapses-module)
45
- - [Connectors](#Connectors-Module)
46
- - [Bmplot](#bmplot-Module)
45
+ - [Connectors](#connectors-module)
46
+ - [Bmplot](#bmplot-module)
47
47
  - [Graphs](#graphs-module)
48
48
 
49
49
  ## Getting Started
@@ -397,148 +397,57 @@ connector.setup_nodes(target=net.nodes(pop_name = 'PopB'))
397
397
  net.add_edges(**connector.edge_params())
398
398
  ```
399
399
 
400
- ## Bmplot Module
401
- - [Total connections](#Total-connection-plot)
402
- - [Percent connections](#Percent-connection-plot)
403
- - [Convergence connnections](#convergence-plot)
404
- - [Divergence connections](#divergence-plot)
405
- - [Gap Junction connections](#gap-junction-plot)
406
- - [connection histogram](#connection-histogram)
407
- - [probability connection](#probability-of-connection-plot)
408
- - [3D location](#3d-position-plot)
409
- - [3D rotation](#cell-rotations)
410
- - [Plot Connection Diagram](#plot-connection-diagram)
411
-
412
- ### Total connection plot
400
+ ## Bmplot Module
401
+ ### for a demo please see the notebook [here](examples/bmplot/bmplot.ipynb)
402
+ - [total_connection_matrix](#total_connection_matrix)
403
+ - [percent_connection_matrix](#percent_connection_matrix)
404
+ - [connector_percent_matrix](#connector_percent_matrix)
405
+ - [convergence_connection_matrix](#convergence_connection_matrix)
406
+ - [divergence_connection_matrix](#divergence_connection_matrix)
407
+ - [gap_junction_matrix](#gap_junction_matrix)
408
+ - [connection_distance](#connection_distance)
409
+ - [connection_histogram](#connection_histogram)
410
+ - [plot_3d_positions](#plot_3d_positions)
411
+ - [plot_3d_cell_rotation](#plot_3d_cell_rotation)
412
+
413
+ ### total_connection_matrix
413
414
  #### Generates a table of total number of connections each neuron population recieves
414
415
 
415
-
416
- ```python
417
- from bmtool import bmplot
418
- bmplot.total_connection_matrix(config='config.json',sources='LA',targets='LA',tids='pop_name',sids='pop_name',no_prepend_pop=True,include_gap=False)
419
- ```
420
-
421
-
422
-
423
- ![png](readme_figures/output_19_0.png)
424
416
 
425
-
426
-
427
- ### Percent connection plot
417
+ ### percent_connection_matrix
428
418
  #### Generates a table of the percent connectivity of neuron populations.Method can change if you want the table to be total percent connectivity, only unidirectional connectivity or only bi directional connectvity
429
419
 
430
-
431
- ```python
432
- bmplot.percent_connection_matrix(config='config.json',sources='LA',targets='LA',tids='pop_name',sids='pop_name',no_prepend_pop=True,method='total',include_gap=False)
433
- ```
434
-
435
-
436
-
437
- ![png](readme_figures/output_21_0.png)
438
-
420
+ ### connector_percent_matrix
421
+ #### Generates a table of the percent connectivity using the output from bmtool.connector. By default will generate the percent connectivity of the possible connections meaning factoring in distance rules.
439
422
 
440
423
 
441
- ### Convergence plot
424
+ ### convergence_connection_matrix
442
425
  #### Generates a table of the mean convergence of neuron populations. Method can be changed to show max, min, mean, or std for convergence a cell recieves
443
426
 
444
-
445
- ```python
446
- bmplot.convergence_connection_matrix(config='config.json',sources='LA',targets='LA',tids='pop_name',sids='pop_name',no_prepend_pop=True,include_gap=False,method='mean+std')
447
- ```
448
-
449
-
450
-
451
- ![png](readme_figures/output_23_0.png)
452
427
 
453
-
454
-
455
- ### Divergence plot
428
+ ### divergence_connection_matrix
456
429
  #### Generates a table of the mean divergence of neuron populations. Method can be changed to show max, min, mean or std divergence a cell recieves.
457
430
 
458
-
459
- ```python
460
- bmplot.divergence_connection_matrix(config='config.json',sources='LA',targets='LA',tids='pop_name',sids='pop_name',no_prepend_pop=True,include_gap=False,method='mean+std')
461
- ```
462
-
463
-
464
431
 
465
- ![png](readme_figures/output_25_0.png)
466
-
467
- ### Gap Junction plot
468
- #### 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
469
-
432
+ ### gap_junction_matrix
433
+ #### While gap junctions can be include in the above plots, you can use this function to only view gap junctions. Method can be either 'convergence' or 'percent' connections to generate different plots
470
434
 
471
- ```python
472
- bmplot.gap_junction_matrix(config='config.json',sources='LA',targets='LA',sids='pop_name',tids='pop_name',no_prepend_pop=True,type='percent')
473
- ```
474
-
475
-
476
-
477
- ![png](output_gap.png)
478
435
 
436
+ ### connection_distance
437
+ #### Generates a 3d plot with the source and target cells location along with a histogram showing connection distance
479
438
 
480
- ### Connection histogram
439
+ ### connection_histogram
481
440
  #### Generates a histogram of the distribution of connections a population of cells give to individual cells of another population
482
441
 
483
442
 
484
- ```python
485
- bmplot.connection_histogram(config='config.json',sources='LA',targets='LA',tids='pop_name',sids='pop_name',source_cell='PV',target_cell='PV',include_gap=False)
486
- ```
487
-
488
-
489
-
490
- ![png](readme_figures/output_27_0.png)
491
-
492
-
493
-
494
- ### probability of connection plot
495
- #### this function needs some work
496
-
497
-
498
- ```python
499
- bmplot.probability_connection_matrix(config='config.json',sources='LA',targets='LA',tids='pop_name',sids='pop_name',no_prepend_pop=True,line_plot=True)
500
- ```
501
-
502
-
503
-
504
- ![png](readme_figures/output_29_0.png)
505
-
506
-
507
-
508
-
509
-
510
- ![png](readme_figures/output_29_1.png)
511
-
512
-
513
-
514
- ### 3D position plot
443
+ ### plot_3d_positions
515
444
  #### Generates a plot of cells positions in 3D space
516
445
 
517
446
 
518
- ```python
519
- bmplot.plot_3d_positions(config='config.json',populations_list='LA',group_by='pop_name',save_file=False)
520
- ```
521
-
522
-
523
-
524
- ![png](readme_figures/output_31_0.png)
525
-
526
-
527
-
528
- ### cell rotations
447
+ ### plot_3d_cell_rotation
529
448
  #### Generates a plot of cells location in 3D plot and also the cells rotation
530
449
 
531
450
 
532
- ```python
533
- bmplot.cell_rotation_3d(config='config2.json',populations_list='all',group_by='pop_name',save_file=False,quiver_length=20,arrow_length_ratio=0.25,max_cells=100)
534
- ```
535
-
536
-
537
-
538
- ![png](readme_figures/output_33_0.png)
539
-
540
-
541
-
542
451
  ### Plot Connection Diagram
543
452
 
544
453
 
@@ -553,252 +462,6 @@ bmplot.plot_network_graph(config='config.json',sources='LA',targets='LA',tids='p
553
462
 
554
463
 
555
464
 
556
-
557
-
558
- ```python
559
- from bmtool import bmplot
560
- bmplot.plot_basic_cell_info(config_file='config.json')
561
- ```
562
-
563
- Network and node info:
564
- LA:
565
-
566
-
567
-
568
- <table border="1" class="dataframe">
569
- <thead>
570
- <tr style="text-align: right;">
571
- <th></th>
572
- <th>node_type</th>
573
- <th>pop_name</th>
574
- <th>model_type</th>
575
- <th>model_template</th>
576
- <th>morphology</th>
577
- <th>count</th>
578
- </tr>
579
- </thead>
580
- <tbody>
581
- <tr>
582
- <th>0</th>
583
- <td>100</td>
584
- <td>PNa</td>
585
- <td>biophysical</td>
586
- <td>hoc:Cell_Af</td>
587
- <td>blank.swc</td>
588
- <td>800</td>
589
- </tr>
590
- <tr>
591
- <th>1</th>
592
- <td>101</td>
593
- <td>PNc</td>
594
- <td>biophysical</td>
595
- <td>hoc:Cell_Cf</td>
596
- <td>blank.swc</td>
597
- <td>800</td>
598
- </tr>
599
- <tr>
600
- <th>2</th>
601
- <td>102</td>
602
- <td>PV</td>
603
- <td>biophysical</td>
604
- <td>hoc:InterneuronCellf</td>
605
- <td>blank.swc</td>
606
- <td>240</td>
607
- </tr>
608
- <tr>
609
- <th>3</th>
610
- <td>103</td>
611
- <td>SOM</td>
612
- <td>biophysical</td>
613
- <td>hoc:LTS_Cell</td>
614
- <td>blank.swc</td>
615
- <td>160</td>
616
- </tr>
617
- </tbody>
618
- </table>
619
-
620
-
621
- thalamus_pyr:
622
-
623
-
624
-
625
- <table border="1" class="dataframe">
626
- <thead>
627
- <tr style="text-align: right;">
628
- <th></th>
629
- <th>node_type</th>
630
- <th>pop_name</th>
631
- <th>model_type</th>
632
- <th>count</th>
633
- </tr>
634
- </thead>
635
- <tbody>
636
- <tr>
637
- <th>0</th>
638
- <td>100</td>
639
- <td>pyr_inp</td>
640
- <td>virtual</td>
641
- <td>1600</td>
642
- </tr>
643
- </tbody>
644
- </table>
645
-
646
-
647
- thalamus_pv:
648
-
649
-
650
-
651
- <table border="1" class="dataframe">
652
- <thead>
653
- <tr style="text-align: right;">
654
- <th></th>
655
- <th>node_type</th>
656
- <th>pop_name</th>
657
- <th>model_type</th>
658
- <th>count</th>
659
- </tr>
660
- </thead>
661
- <tbody>
662
- <tr>
663
- <th>0</th>
664
- <td>100</td>
665
- <td>pv_inp</td>
666
- <td>virtual</td>
667
- <td>240</td>
668
- </tr>
669
- </tbody>
670
- </table>
671
-
672
-
673
- thalamus_som:
674
-
675
-
676
-
677
- <table border="1" class="dataframe">
678
- <thead>
679
- <tr style="text-align: right;">
680
- <th></th>
681
- <th>node_type</th>
682
- <th>pop_name</th>
683
- <th>model_type</th>
684
- <th>count</th>
685
- </tr>
686
- </thead>
687
- <tbody>
688
- <tr>
689
- <th>0</th>
690
- <td>100</td>
691
- <td>som_inp</td>
692
- <td>virtual</td>
693
- <td>160</td>
694
- </tr>
695
- </tbody>
696
- </table>
697
-
698
-
699
- tone:
700
-
701
-
702
-
703
- <table border="1" class="dataframe">
704
- <thead>
705
- <tr style="text-align: right;">
706
- <th></th>
707
- <th>node_type</th>
708
- <th>pop_name</th>
709
- <th>model_type</th>
710
- <th>count</th>
711
- </tr>
712
- </thead>
713
- <tbody>
714
- <tr>
715
- <th>0</th>
716
- <td>100</td>
717
- <td>tone</td>
718
- <td>virtual</td>
719
- <td>1840</td>
720
- </tr>
721
- </tbody>
722
- </table>
723
-
724
-
725
- shock:
726
-
727
-
728
-
729
- <table border="1" class="dataframe">
730
- <thead>
731
- <tr style="text-align: right;">
732
- <th></th>
733
- <th>node_type</th>
734
- <th>pop_name</th>
735
- <th>model_type</th>
736
- <th>count</th>
737
- </tr>
738
- </thead>
739
- <tbody>
740
- <tr>
741
- <th>0</th>
742
- <td>100</td>
743
- <td>shock</td>
744
- <td>virtual</td>
745
- <td>400</td>
746
- </tr>
747
- </tbody>
748
- </table>
749
-
750
-
751
- shell:
752
-
753
-
754
-
755
- <table border="1" class="dataframe">
756
- <thead>
757
- <tr style="text-align: right;">
758
- <th></th>
759
- <th>node_type</th>
760
- <th>pop_name</th>
761
- <th>model_type</th>
762
- <th>count</th>
763
- </tr>
764
- </thead>
765
- <tbody>
766
- <tr>
767
- <th>0</th>
768
- <td>100</td>
769
- <td>PNa</td>
770
- <td>virtual</td>
771
- <td>3975</td>
772
- </tr>
773
- <tr>
774
- <th>1</th>
775
- <td>101</td>
776
- <td>PNc</td>
777
- <td>virtual</td>
778
- <td>3975</td>
779
- </tr>
780
- <tr>
781
- <th>2</th>
782
- <td>102</td>
783
- <td>PV</td>
784
- <td>virtual</td>
785
- <td>1680</td>
786
- </tr>
787
- <tr>
788
- <th>3</th>
789
- <td>103</td>
790
- <td>SOM</td>
791
- <td>virtual</td>
792
- <td>1120</td>
793
- </tr>
794
- </tbody>
795
- </table>
796
-
797
-
798
-
799
-
800
-
801
- 'LA'
802
465
  ## Graphs Module
803
466
  - [Generate graph](#generate-graph)
804
467
  - [Plot Graph](#plot-graph)
@@ -806,7 +469,6 @@ bmplot.plot_basic_cell_info(config_file='config.json')
806
469
 
807
470
  ### Generate Graph
808
471
 
809
-
810
472
  ```python
811
473
  from bmtool import graphs
812
474
  import networkx as nx
@@ -1,24 +1,24 @@
1
1
  bmtool/SLURM.py,sha256=AX5MKV7dD-XwS8SROnW1IyesZ3jDwMf0txO6mHxTbuw,13694
2
2
  bmtool/__init__.py,sha256=ZStTNkAJHJxG7Pwiy5UgCzC4KlhMS5pUNPtUJZVwL_Y,136
3
3
  bmtool/__main__.py,sha256=TmFkmDxjZ6250nYD4cgGhn-tbJeEm0u-EMz2ajAN9vE,650
4
- bmtool/bmplot.py,sha256=otTOwFwOY9TTX5jaOcaTzari4wx6hVI_Is0GrezD_2Y,52717
5
- bmtool/connectors.py,sha256=8FbQXewdI9Q0Dlx6cVbM3hPKt9ead4WEDkG22tyKa2o,72187
4
+ bmtool/bmplot.py,sha256=Oq-aBkZxeAjVKdtAstQWVCv65c-hFMbmdGIcTt7xeno,51822
5
+ bmtool/connectors.py,sha256=2vVUsqYMaCuWZ-4C5eUzqwsFItFM9vm0ytZdRQdWgoc,72243
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
9
9
  bmtool/singlecell.py,sha256=Q4poQvG9fw0jlyMmHFzbRPrpcEkPz5MKS8Guuo73Bzs,26849
10
- bmtool/synapses.py,sha256=CA4mPeLCnyaqhDYphcKz-1s7C2JVknCRW_NoTfHS9MM,27500
10
+ bmtool/synapses.py,sha256=cBa4NAYob8BxCFi04FfVcqDs_LNYJrP4vscgnT8Rk1c,27498
11
11
  bmtool/debug/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
12
  bmtool/debug/commands.py,sha256=AwtcR7BUUheM0NxvU1Nu234zCdpobhJv5noX8x5K2vY,583
13
13
  bmtool/debug/debug.py,sha256=xqnkzLiH3s-tS26Y5lZZL62qR2evJdi46Gud-HzxEN4,207
14
14
  bmtool/util/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
15
  bmtool/util/commands.py,sha256=zJF-fiLk0b8LyzHDfvewUyS7iumOxVnj33IkJDzux4M,64396
16
- bmtool/util/util.py,sha256=24E5rUoDU86nqypDF4uZJkuJKO1BrwrQE8lZzAxu1kw,56770
16
+ bmtool/util/util.py,sha256=00vOAwTVIifCqouBoFoT0lBashl4fCalrk8fhg_Uq4c,56654
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.9.7.dist-info/LICENSE,sha256=qrXg2jj6kz5d0EnN11hllcQt2fcWVNumx0xNbV05nyM,1068
20
- bmtool-0.5.9.7.dist-info/METADATA,sha256=DgDwAN9aw0lw6DXI312P-Bi2nP6OTdo-4CNEnAfQJtA,24455
21
- bmtool-0.5.9.7.dist-info/WHEEL,sha256=a7TGlA-5DaHMRrarXjVbQagU3Man_dCnGIWMJr5kRWo,91
22
- bmtool-0.5.9.7.dist-info/entry_points.txt,sha256=0-BHZ6nUnh0twWw9SXNTiRmKjDnb1VO2DfG_-oprhAc,45
23
- bmtool-0.5.9.7.dist-info/top_level.txt,sha256=gpd2Sj-L9tWbuJEd5E8C8S8XkNm5yUE76klUYcM-eWM,7
24
- bmtool-0.5.9.7.dist-info/RECORD,,
19
+ bmtool-0.5.9.9.dist-info/LICENSE,sha256=qrXg2jj6kz5d0EnN11hllcQt2fcWVNumx0xNbV05nyM,1068
20
+ bmtool-0.5.9.9.dist-info/METADATA,sha256=cwW_xMDHd5dr14WsVtx0jMKKj07jUiz8MRWjfO2s9ok,19115
21
+ bmtool-0.5.9.9.dist-info/WHEEL,sha256=R06PA3UVYHThwHvxuRWMqaGcr-PuniXahwjmQRFMEkY,91
22
+ bmtool-0.5.9.9.dist-info/entry_points.txt,sha256=0-BHZ6nUnh0twWw9SXNTiRmKjDnb1VO2DfG_-oprhAc,45
23
+ bmtool-0.5.9.9.dist-info/top_level.txt,sha256=gpd2Sj-L9tWbuJEd5E8C8S8XkNm5yUE76klUYcM-eWM,7
24
+ bmtool-0.5.9.9.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.4.0)
2
+ Generator: setuptools (75.5.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5