bmtool 0.5.9.8__py3-none-any.whl → 0.6.0__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
@@ -574,16 +574,16 @@ def plot_connection_info(text, num, source_labels,target_labels, title, syn_info
574
574
  if syn_info =='2' or syn_info =='3':
575
575
  if num_source > 8 and num_source <20:
576
576
  fig_text = ax1.text(j, i, edge_info,
577
- 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')
578
578
  elif num_source > 20:
579
579
  fig_text = ax1.text(j, i, edge_info,
580
- 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')
581
581
  else:
582
582
  fig_text = ax1.text(j, i, edge_info,
583
- 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')
584
584
  else:
585
585
  fig_text = ax1.text(j, i, edge_info,
586
- ha="center", va="center", color="k", size=11, weight = 'semibold')
586
+ ha="center", va="center", color="w", size=11, weight = 'semibold')
587
587
 
588
588
  ax1.set_ylabel('Source', size=11, weight = 'semibold')
589
589
  ax1.set_xlabel('Target', size=11, weight = 'semibold')
@@ -599,8 +599,7 @@ def plot_connection_info(text, num, source_labels,target_labels, title, syn_info
599
599
  else:
600
600
  return
601
601
 
602
- def connector_percent_matrix(csv_path: str = None, exclude_shell: bool = True,
603
- 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:
604
603
  """
605
604
  Generates and plots a connection matrix based on connection probabilities from a CSV file produced by bmtool.connector.
606
605
 
@@ -613,123 +612,92 @@ def connector_percent_matrix(csv_path: str = None, exclude_shell: bool = True,
613
612
  csv_path : str
614
613
  Path to the CSV file containing the connection data. The CSV should be an output from the bmtool.connector
615
614
  classes, specifically generated by the `save_connection_report()` function.
616
- exclude_shell : bool, optional, default=True
617
- If True, rows where 'Source' or 'Target' contain "shell" will be excluded from the analysis.
618
- exclude_assembly : bool, optional, default=False
619
- 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.
620
617
  title : str, optional, default='Percent connection matrix'
621
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.
622
621
 
623
622
  Returns:
624
623
  --------
625
624
  None
626
625
  Displays a heatmap plot of the connection matrix, showing the percentage of connected pairs between populations.
627
-
628
- Example:
629
- --------
630
- connector_percent_matrix('connections.csv', exclude_shell=True, exclude_assembly=False)
631
626
  """
632
627
  # Read the CSV data
633
628
  df = pd.read_csv(csv_path)
634
629
 
635
630
  # Choose the column to display
636
- selected_column = "Fraction of connected pairs in possible ones (%)" # Can change this for different column but this is best i think
637
-
638
- # Create an empty dictionary to store connection percentages
639
- connection_data = {}
631
+ selected_column = "Percent connectionivity within possible connections"
640
632
 
641
- 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):
642
635
  def process_string(string):
643
- # Use regex to extract 'FSI' or other match
644
- match = re.search(r"\[\'(.*?)\'\]", string) # the cell name from ['fsi']
645
- ints_in_string = re.findall(r'\d+', string) # get all ints in the string
646
-
647
- # Conditionally remove rows containing "shell"
648
- if exclude_shell and "shell" in string:
649
- return None # Mark row for removal
650
- else:
651
- if match:
652
- filtered_string = match.group(1)
653
-
654
- # Conditionally process "assembly" in the string
655
- if not exclude_assembly and "assembly" in string:
656
- assem_value = int(ints_in_string[0])
657
- filtered_string = filtered_string + str(f"-{assem_value}")
658
-
659
- 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:
660
642
  filtered_string = filtered_string + "-Gap"
661
- return filtered_string
662
- return string # If no match, return the original string
643
+ return filtered_string # Return matched string
663
644
 
664
- # Apply the filtering logic to the specified column
665
- df[column_name] = df[column_name].apply(process_string)
645
+ return string # If no match, return the original string
666
646
 
667
- # Remove rows where None was returned in the specified column
647
+ df[column_name] = df[column_name].apply(process_string)
668
648
  df = df.dropna(subset=[column_name])
669
-
670
649
  return df
671
650
 
672
- df = filter_dataframe(df,'Source')
673
- df = filter_dataframe(df,'Target')
674
- # Iterate over each row in the DataFrame
675
- for index, row in df.iterrows():
676
- source = row['Source']
677
- target = row['Target']
678
- selected_percentage = row[selected_column]
679
-
680
- # 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]
681
658
  if isinstance(selected_percentage, str):
682
- selected_percentage = selected_percentage.strip('[]').split()
683
- selected_percentage = [float(p) for p in selected_percentage] # Convert to float
684
-
685
- # Store the selected percentage(s) for the source-target pair
659
+ selected_percentage = [float(p) for p in selected_percentage.strip('[]').split()]
686
660
  connection_data[(source, target)] = selected_percentage
687
661
 
688
- # Prepare unique populations and create an empty matrix
662
+ # Determine population order
689
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
690
666
  num_populations = len(populations)
667
+
668
+ # Create an empty matrix and populate it
691
669
  connection_matrix = np.zeros((num_populations, num_populations), dtype=float)
692
-
693
- # Populate the matrix with the selected connection percentages
694
- for source, target in connection_data.keys():
695
- source_idx = populations.index(source)
696
- target_idx = populations.index(target)
697
- connection_probabilities = connection_data[(source, target)]
698
-
699
- # Use the first value for one-way connection from source to target
700
- connection_matrix[source_idx][target_idx] = connection_probabilities[0]
701
-
702
- # Check if the source and target are the same population
703
- if source == target:
704
- # Use the first value (uni-directional) and ignore the second value (bi-directional)
705
- continue
706
-
707
- # Check if there is a bidirectional connection and use the second value
708
- if len(connection_probabilities) > 1:
709
- connection_matrix[target_idx][source_idx] = connection_probabilities[1]
710
-
711
- # Replace NaN values with 0
712
- connection_matrix[np.isnan(connection_matrix)] = 0
713
-
714
- # 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
715
684
  fig, ax = plt.subplots(figsize=(10, 8))
716
685
  im = ax.imshow(connection_matrix, cmap='viridis', interpolation='nearest')
717
686
 
718
687
  # Add annotations
719
688
  for i in range(num_populations):
720
689
  for j in range(num_populations):
721
- text = ax.text(j, i, f"{connection_matrix[i, j]:.2f}%",
722
- 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')
723
691
 
724
692
  # Add colorbar
725
- plt.colorbar(im, label=f'Percentage of connected pairs ({selected_column})')
693
+ plt.colorbar(im, label=f'{selected_column}')
726
694
 
727
695
  # Set title and axis labels
728
696
  ax.set_title(title)
729
697
  ax.set_xlabel('Target Population')
730
698
  ax.set_ylabel('Source Population')
731
699
 
732
- # Set ticks and labels
700
+ # Set ticks and labels based on populations in specified order
733
701
  ax.set_xticks(np.arange(num_populations))
734
702
  ax.set_yticks(np.arange(num_populations))
735
703
  ax.set_xticklabels(populations, rotation=45, ha="right", size=12, weight='semibold')
@@ -922,7 +890,7 @@ def plot_3d_positions(config=None, populations_list=None, group_by=None, title=N
922
890
  if not is_notebook:
923
891
  plt.show()
924
892
 
925
- return
893
+ return ax
926
894
 
927
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):
928
896
  from scipy.spatial.transform import Rotation as R
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
 
@@ -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
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: bmtool
3
- Version: 0.5.9.8
3
+ Version: 0.6.0
4
4
  Summary: BMTool
5
5
  Home-page: https://github.com/cyneuro/bmtool
6
6
  Download-URL:
@@ -401,6 +401,7 @@ net.add_edges(**connector.edge_params())
401
401
  ### for a demo please see the notebook [here](examples/bmplot/bmplot.ipynb)
402
402
  - [total_connection_matrix](#total_connection_matrix)
403
403
  - [percent_connection_matrix](#percent_connection_matrix)
404
+ - [connector_percent_matrix](#connector_percent_matrix)
404
405
  - [convergence_connection_matrix](#convergence_connection_matrix)
405
406
  - [divergence_connection_matrix](#divergence_connection_matrix)
406
407
  - [gap_junction_matrix](#gap_junction_matrix)
@@ -416,6 +417,9 @@ net.add_edges(**connector.edge_params())
416
417
  ### percent_connection_matrix
417
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
418
419
 
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.
422
+
419
423
 
420
424
  ### convergence_connection_matrix
421
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
@@ -1,13 +1,13 @@
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=VoX-oXqu6dRb3JEUgGxWiX23JxUy9PeemE7z4f6hVbY,53177
5
- bmtool/connectors.py,sha256=QEaBGc6mEoQc-H3ltjvjn5-XWyYgnrhcfNRblVOUE2A,72228
4
+ bmtool/bmplot.py,sha256=vIknbCwBSJNsr4m53SymteKdvyE0Omn3Xv8udzroeKc,51825
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
@@ -16,9 +16,9 @@ bmtool/util/commands.py,sha256=zJF-fiLk0b8LyzHDfvewUyS7iumOxVnj33IkJDzux4M,64396
16
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.8.dist-info/LICENSE,sha256=qrXg2jj6kz5d0EnN11hllcQt2fcWVNumx0xNbV05nyM,1068
20
- bmtool-0.5.9.8.dist-info/METADATA,sha256=rrR39yoM5X0WSk15L0KZV3KoRFqwt5KAmwMXW-apI_c,18823
21
- bmtool-0.5.9.8.dist-info/WHEEL,sha256=R06PA3UVYHThwHvxuRWMqaGcr-PuniXahwjmQRFMEkY,91
22
- bmtool-0.5.9.8.dist-info/entry_points.txt,sha256=0-BHZ6nUnh0twWw9SXNTiRmKjDnb1VO2DfG_-oprhAc,45
23
- bmtool-0.5.9.8.dist-info/top_level.txt,sha256=gpd2Sj-L9tWbuJEd5E8C8S8XkNm5yUE76klUYcM-eWM,7
24
- bmtool-0.5.9.8.dist-info/RECORD,,
19
+ bmtool-0.6.0.dist-info/LICENSE,sha256=qrXg2jj6kz5d0EnN11hllcQt2fcWVNumx0xNbV05nyM,1068
20
+ bmtool-0.6.0.dist-info/METADATA,sha256=8qbBKGJWEedc2N_xdm9OYb66bCQScXxb2faMQvdJvsQ,19113
21
+ bmtool-0.6.0.dist-info/WHEEL,sha256=R06PA3UVYHThwHvxuRWMqaGcr-PuniXahwjmQRFMEkY,91
22
+ bmtool-0.6.0.dist-info/entry_points.txt,sha256=0-BHZ6nUnh0twWw9SXNTiRmKjDnb1VO2DfG_-oprhAc,45
23
+ bmtool-0.6.0.dist-info/top_level.txt,sha256=gpd2Sj-L9tWbuJEd5E8C8S8XkNm5yUE76klUYcM-eWM,7
24
+ bmtool-0.6.0.dist-info/RECORD,,