morphgen-rates 0.4.0__py3-none-any.whl → 0.5.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.
morphgen_rates/data.py CHANGED
@@ -22,85 +22,82 @@ def _local_data_path(filename='morph_data', ext="csv"):
22
22
  return work_dir / f"{filename}.{ext}"
23
23
 
24
24
 
25
- def get_data(key):
25
+ def get_data(area, neuron_type):
26
26
  """
27
- Retrieve a dataset entry using a key-path of the form
28
- "<brain region>/<neuron class>/<subcellular section>".
27
+ Retrieve summary morphology statistics for a given brain area and neuron class.
29
28
 
30
- The argument `data_path` is interpreted as a slash-separated path of keys used
31
- to traverse a nested dataset dictionary. The selected dataset is expected to
32
- contain both Sholl-plot statistics and bifurcation statistics; when both are
33
- available, this function returns a standardized dictionary compatible with
34
- `compute_rates`.
29
+ This function loads a local CSV dataset, filters rows matching the requested
30
+ `area` and `neuron_type`, and aggregates statistics by `section_type`. The
31
+ output is a nested dictionary keyed by section type (e.g., soma, apical, basal),
32
+ containing:
33
+
34
+ - Summary statistics for bifurcation counts and total length
35
+ - Estimated number of primary neurites at the soma (Count0)
36
+ - Sholl plot summary statistics (bin size, mean counts, standard deviation)
35
37
 
36
38
  Parameters
37
39
  ----------
38
- key : str
39
- Dataset identifier expressed as a key path:
40
-
41
- "<brain region>/<neuron class>/<subcellular section>"
42
-
43
- Examples:
44
- - "CTX/pyr/apical"
45
- - "HPC/pyr/basal"
46
-
47
- Each component is used as a successive key lookup into the nested dataset
48
- container.
40
+ area : str
41
+ Brain region identifier used in the dataset (must match values in the
42
+ 'area' column of the CSV)
43
+ neuron_type : str
44
+ Neuron class identifier used in the dataset (must match values in the
45
+ 'neuron_type' column of the CSV)
49
46
 
50
47
  Returns
51
48
  -------
52
49
  dict
53
- If both Sholl and bifurcation information are present for the selected dataset,
54
- returns:
50
+ Nested dictionary structured as:
55
51
 
56
52
  data = {
57
- "sholl": {
58
- "bin_size": float,
59
- "mean": numpy.ndarray, # shape (K,)
60
- "var": numpy.ndarray, # shape (K,)
61
- },
62
- "bifurcations": {
63
- "mean": float,
64
- "var": float,
53
+ "<section_type>": {
54
+ "bifurcation_count": {"mean": ..., "std": ..., "min": ..., "max": ...},
55
+ "total_length": {"mean": ..., "std": ..., "min": ..., "max": ...},
56
+ "primary_count": {"mean": ..., "std": ..., "min": ..., "max": ...},
57
+ "sholl_plot": {
58
+ "bin_size": float,
59
+ "mean": list[float],
60
+ "std": list[float],
61
+ },
65
62
  },
63
+ ...
66
64
  }
67
65
 
68
- Where:
69
- - `data["sholl"]["bin_size"]` is the spatial bin size used to define Sholl shells
70
- - `data["sholl"]["mean"]` is the mean Sholl intersection count per radial bin
71
- - `data["sholl"]["var"]` is the variance of the Sholl intersection count per bin
72
- - `data["bifurcations"]["mean"]` is the mean bifurcation count
73
- - `data["bifurcations"]["var"]` is the variance of the bifurcation count
66
+ Notes on fields:
67
+ - `primary_count` corresponds to the row group labeled 'Count0'
68
+ - Sholl values are collected from rows whose metric name starts with 'Count'
69
+ (including 'Count0'); users may want to interpret/plot them as a function
70
+ of radial bin index multiplied by `bin_size`
74
71
 
75
72
  Raises
76
73
  ------
77
- KeyError
78
- If any key along `data_path` is missing (brain region, neuron class, or section)
79
- ValueError
80
- If the selected dataset does not contain both Sholl and bifurcation data, or
81
- if the provided arrays have incompatible shapes
74
+ AssertionError
75
+ If no rows match the requested `area` and `neuron_type`
82
76
 
83
77
  Notes
84
78
  -----
85
- - `data_path` is a *key path*, not a filesystem path
86
- - The function assumes the dataset entry referenced by `data_path` includes:
87
- - Sholl bin size, mean array, variance array
88
- - Bifurcation mean and variance
79
+ - The function expects the local CSV to include at least the following columns:
80
+ 'area', 'neuron_type', 'neuron_name', 'section_type', 'bin_size'
81
+ plus metric columns including:
82
+ - 'bifurcation_count'
83
+ - 'total_length'
84
+ - 'Count0', 'Count1', ... (Sholl counts per radial bin)
85
+ - Statistics are computed using `pandas.DataFrame.groupby(...).describe()`.
86
+ Only the summary columns 'mean', 'std', 'min', 'max' are retained.
89
87
 
90
88
  Examples
91
89
  --------
92
- >>> data = get("CTX/pyr/apical")
93
- >>> data["sholl"]["bin_size"]
90
+ >>> data = get_data("CTX", "pyr")
91
+ >>> data["apical"]["bifurcation_count"]["mean"]
92
+ 42.0
93
+ >>> data["apical"]["sholl_plot"]["bin_size"]
94
94
  50.0
95
- >>> data["bifurcations"]["mean"]
96
- 12.3
95
+ >>> len(data["apical"]["sholl_plot"]["mean"])
96
+ 20
97
97
  """
98
+
98
99
  data = {}
99
100
 
100
- # split the key
101
- parts = tuple(p.strip() for p in key.split("/") if p.strip())
102
- if len(parts) != 2:
103
- raise ValueError(f"Expected key like 'area/neuron_type', got: {key!r}")
104
101
  area, neuron_type = parts
105
102
 
106
103
  # load data
@@ -108,6 +105,9 @@ def get_data(key):
108
105
 
109
106
  # select specific area and neuron type
110
107
  df = df[(df['area'] == area) & (df['neuron_type'] == neuron_type)]
108
+
109
+ # ensure that there are area and neuron_type in the df
110
+ assert df.shape[0] > 0, "The area {area} or neuron class {neuron_type} are not known"
111
111
 
112
112
  # neuron name unnecessary
113
113
  df.drop(['area', 'neuron_type', 'neuron_name'], axis=1, inplace=True)
@@ -122,8 +122,6 @@ def get_data(key):
122
122
  for section_type, row in df.iterrows():
123
123
  data[section_type] = {}
124
124
 
125
- print()
126
-
127
125
  # get statistics
128
126
  for data_type in ['bifurcation_count', 'total_length']:
129
127
  tmp = row.loc[row.index.get_level_values(0) == data_type, :]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: morphgen-rates
3
- Version: 0.4.0
3
+ Version: 0.5.0
4
4
  Summary: Compute bifurcation and annihilation rates from morphology data
5
5
  Author-email: Francesco Cavarretta <fcavarretta@ualr.edu>
6
6
  Requires-Python: >=3.9
@@ -0,0 +1,9 @@
1
+ morphgen_rates/__init__.py,sha256=UE8YWsulDIfeYhGb5GHdkakUIFx4j9H3ZkoKoaDCd_0,179
2
+ morphgen_rates/data.py,sha256=Onc2dRlB_QXpgScDzHCE7DRtg6PLtFld5W91QGuDkYo,4518
3
+ morphgen_rates/init_count.py,sha256=PhYlp0-CzRdf8opTKb-om3cFIKSv5M8eTcyKy1_IFMI,7283
4
+ morphgen_rates/rates.py,sha256=2Gn3Ew2uVJ7c_LdYJogxS-jAM9q-039y0maWi4CNpTM,6442
5
+ morphgen_rates-0.5.0.dist-info/licenses/LICENSE,sha256=VONsnKVXQRcWwCaHWHuwMtemIj9jNJSmpunazxlyvOk,670
6
+ morphgen_rates-0.5.0.dist-info/METADATA,sha256=xYYNva-7mn6Vk-iFKKJJUg3jw_phgW-iZvHeSd4z7gk,1178
7
+ morphgen_rates-0.5.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
8
+ morphgen_rates-0.5.0.dist-info/top_level.txt,sha256=UYPGC2dGp9xD_4iVxVVTkKaizBA4XeDNM7OBC_DCWRk,15
9
+ morphgen_rates-0.5.0.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- morphgen_rates/__init__.py,sha256=UE8YWsulDIfeYhGb5GHdkakUIFx4j9H3ZkoKoaDCd_0,179
2
- morphgen_rates/data.py,sha256=yj_GT3ks6ukwtALfC4Bklcwu3MeTOr-2BGGo5W0ZxM0,4330
3
- morphgen_rates/init_count.py,sha256=PhYlp0-CzRdf8opTKb-om3cFIKSv5M8eTcyKy1_IFMI,7283
4
- morphgen_rates/rates.py,sha256=2Gn3Ew2uVJ7c_LdYJogxS-jAM9q-039y0maWi4CNpTM,6442
5
- morphgen_rates-0.4.0.dist-info/licenses/LICENSE,sha256=VONsnKVXQRcWwCaHWHuwMtemIj9jNJSmpunazxlyvOk,670
6
- morphgen_rates-0.4.0.dist-info/METADATA,sha256=Xb088-i11lgv8rY4jVvQ3ghYDpyliSw83yjC-kfYANw,1178
7
- morphgen_rates-0.4.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
8
- morphgen_rates-0.4.0.dist-info/top_level.txt,sha256=UYPGC2dGp9xD_4iVxVVTkKaizBA4XeDNM7OBC_DCWRk,15
9
- morphgen_rates-0.4.0.dist-info/RECORD,,