pyLQT 1.0.dev5__py3-none-any.whl → 1.0.dev7__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.
pyLQT/cli.py CHANGED
@@ -42,6 +42,12 @@ def main():
42
42
  help='[str, default=syn] Registration type, from lesion space and atlas space to tract space'
43
43
  )
44
44
 
45
+ parser.add_argument(
46
+ "--spared_threshold",
47
+ default=5.0,
48
+ help='[float (0,inf), default=5.0] Defines threshold for distance filtering of tracts endpoints in structural connectivity computation.'
49
+ )
50
+
45
51
  parser.add_argument(
46
52
  "--spared_threshold",
47
53
  default=0.5,
@@ -10,8 +10,10 @@ def get_parcel_damage(
10
10
  atlas,
11
11
  atlas_labels,
12
12
  parcel_column,
13
+ out_col='Damage',
13
14
  out_path = None
14
15
  ):
16
+
15
17
  """Compute lesion damage for each parcel of an atlas.
16
18
 
17
19
  The lesion is resampled to the atlas grid, and the proportion of
@@ -32,6 +34,9 @@ def get_parcel_damage(
32
34
  parcel_column : str
33
35
  Name of the column in ``atlas_labels`` containing the parcel
34
36
  labels used in the atlas.
37
+ out_col : str
38
+ Name of the appended damage column, containing the proportion
39
+ of each parcel affected by the lesion.
35
40
  out_path : pathlib.Path | None, optional
36
41
  Directory where the parcel damage map and damage DataFrame are
37
42
  saved. If None, no files are saved.
@@ -39,7 +44,7 @@ def get_parcel_damage(
39
44
  Returns
40
45
  -------
41
46
  pandas.DataFrame
42
- Copy of ``atlas_labels`` with an additional ``PercentDamage``
47
+ Copy of ``atlas_labels`` with an additional ``out_col``
43
48
  column containing the proportion of each parcel affected by the
44
49
  lesion.
45
50
  """
@@ -56,10 +61,10 @@ def get_parcel_damage(
56
61
 
57
62
  for parcel in atlas_labels[parcel_column]:
58
63
  parcel_volume = atlas_volume == parcel
59
- parcel_damage = compute_parcel_damage(parcel_volume, lesion_volume)
64
+ parcel_damage = np.round(compute_parcel_damage(parcel_volume, lesion_volume), 5)
60
65
 
61
66
  parcel_damages.append(parcel_damage)
62
- parcel_damage_map[parcel_volume] = np.round(parcel_damage, 5)
67
+ parcel_damage_map[parcel_volume] = parcel_damage
63
68
 
64
69
  if out_path:
65
70
  out_path.mkdir(parents=True, exist_ok=True)
@@ -70,7 +75,7 @@ def get_parcel_damage(
70
75
  )
71
76
 
72
77
  damage_frame = atlas_labels.copy(deep=True)
73
- damage_frame["PercentDamage"] = parcel_damages
78
+ damage_frame[out_col] = parcel_damages
74
79
  if out_path:
75
80
  damage_frame.to_csv(out_path / 'parcel_damage_frame.csv', index=False)
76
81
 
@@ -1,49 +1,35 @@
1
1
  import numpy as np
2
2
  import networkx as nx
3
- import pickle
4
3
 
5
4
  from scipy.sparse import csr_matrix
6
5
  from scipy.sparse.csgraph import shortest_path
7
- from nibabel.processing import resample_from_to
8
- from .utils import create_structural_connectivity
9
6
 
10
7
  def get_parcel_wise_disconnection_severity(
11
- aggregated_tracts,
12
- aggregated_tracts_disconnected,
13
- atlas,
14
- out_path = None
15
- ):
8
+ structural_connectivity,
9
+ structural_connectivity_disconnected,
10
+ out_path=None
11
+ ):
16
12
  """Compute parcel-wise structural disconnection severity.
17
13
 
18
- Structural connectivity is computed for all streamlines and for
19
- disconnected streamlines separately. The disconnection severity is
20
- then calculated as the proportion of connections that are disconnected
21
- for each pair of atlas parcels.
14
+ The disconnection severity is calculated as the proportion of
15
+ connections that are disconnected for each pair of atlas parcels.
22
16
 
23
17
  Parameters
24
18
  ----------
25
- aggregated_tracts : StatefulTractogram
26
- Tractogram containing all aggregated streamlines.
27
- aggregated_tracts_disconnected : StatefulTractogram
28
- Tractogram containing the subset of aggregated streamlines that
29
- are disconnected.
30
- atlas : nib.Nifti1Image
31
- Parcellation atlas. The atlas is resampled to the tractogram
32
- reference grid using nearest-neighbor interpolation.
33
- out_path : Path | None, optional
19
+ structural_connectivity : numpy.ndarray
20
+ Structural connectivity matrix computed from all streamlines.
21
+ structural_connectivity_disconnected : numpy.ndarray
22
+ Structural connectivity matrix computed from disconnected
23
+ streamlines.
24
+ out_path : pathlib.Path | None, optional
34
25
  Directory where the structural connectivity matrices and
35
26
  disconnection measures are saved. If None, no files are saved.
36
27
 
37
28
  Returns
38
29
  -------
39
- tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray]
30
+ tuple[numpy.ndarray, numpy.ndarray]
40
31
  A tuple containing:
41
32
 
42
- - structural_connectivity : numpy.ndarray
43
- Structural connectivity matrix computed from all streamlines.
44
- - structural_connectivity_disconnected : numpy.ndarray
45
- Structural connectivity matrix computed from disconnected
46
- streamlines.
47
33
  - disconnections_severity : numpy.ndarray
48
34
  Proportion of connections that are disconnected for each
49
35
  pair of parcels.
@@ -51,49 +37,33 @@ def get_parcel_wise_disconnection_severity(
51
37
  Proportion of connections that remain spared for each pair
52
38
  of parcels.
53
39
  """
54
-
55
- if out_path:
56
- out_path.mkdir(parents=True, exist_ok=True)
57
- sc_path = out_path / "structural_connectivity"
58
- sc_disconnected_path = out_path / "structural_connectivity_disconnected"
59
- else:
60
- sc_path = None
61
- sc_disconnected_path = None
62
-
63
- atlas_resampled = resample_from_to(atlas,
64
- aggregated_tracts.space_attributes[1::-1],
65
- order=0)
66
-
67
- structural_connectivity = create_structural_connectivity(tract=aggregated_tracts,
68
- atlas_resampled=atlas_resampled,
69
- out_path=sc_path)
70
- structural_connectivity_disconnected = create_structural_connectivity(tract=aggregated_tracts_disconnected,
71
- atlas_resampled=atlas_resampled,
72
- out_path=sc_disconnected_path)
73
-
74
- disconnections_severity = np.divide(structural_connectivity_disconnected,
75
- structural_connectivity,
76
- out=np.zeros_like(structural_connectivity, dtype=float),
77
- where=structural_connectivity != 0
78
- )
79
-
40
+
41
+ disconnections_severity = np.divide(
42
+ structural_connectivity_disconnected,
43
+ structural_connectivity,
44
+ out=np.zeros_like(structural_connectivity, dtype=float),
45
+ where=structural_connectivity != 0
46
+ )
47
+
80
48
  per_spared_connections = np.divide(
81
- structural_connectivity-structural_connectivity_disconnected,
49
+ structural_connectivity - structural_connectivity_disconnected,
82
50
  structural_connectivity,
83
51
  out=np.zeros_like(structural_connectivity, dtype=float),
84
52
  where=structural_connectivity != 0
85
- )
86
-
53
+ )
54
+
87
55
  if out_path:
88
- np.save((out_path / "structural_connectivity.npy"), structural_connectivity)
89
- np.save((out_path / "structural_connectivity_disconnected.npy"), structural_connectivity_disconnected)
90
- np.save((out_path / "disconnections_severity.npy"), disconnections_severity)
91
- np.save((out_path / "per_spared_connections.npy"), per_spared_connections)
56
+ out_path.mkdir(parents=True, exist_ok=True)
57
+ np.save(
58
+ out_path / "disconnections_severity.npy",
59
+ disconnections_severity
60
+ )
61
+ np.save(
62
+ out_path / "per_spared_connections.npy",
63
+ per_spared_connections
64
+ )
92
65
 
93
- return (structural_connectivity,
94
- structural_connectivity_disconnected,
95
- disconnections_severity,
96
- per_spared_connections)
66
+ return disconnections_severity, per_spared_connections
97
67
 
98
68
 
99
69
  def get_sspl_increase(
@@ -120,7 +90,7 @@ def get_sspl_increase(
120
90
  per_spared_connections : numpy.ndarray
121
91
  Matrix containing the proportion of streamlines spared for each
122
92
  connection.
123
- out_path : Path | None, optional
93
+ out_path : pathlib.Path | None, optional
124
94
  Directory where the shortest path matrices and their differences
125
95
  are saved. If None, no files are saved.
126
96
  spared_threshold : float, optional
@@ -145,9 +115,6 @@ def get_sspl_increase(
145
115
  SSPL increase for indirect connections only. Direct connections
146
116
  are set to zero.
147
117
  """
148
-
149
-
150
- # fix inf values, maybe set them to max+1 as it is done for pathway that completely disconnects
151
118
 
152
119
  binary_structural_connectivity = structural_connectivity > 0
153
120
  binary_spared_connections = per_spared_connections > spared_threshold
@@ -162,6 +129,9 @@ def get_sspl_increase(
162
129
  directed=False,
163
130
  unweighted=True)
164
131
  max_SSPL = np.max(SSPL_full_connections[np.isfinite(SSPL_full_connections)])
132
+
133
+ # fix inf values, setting them to max+1 as it is done for pathway that completely disconnects
134
+ # this is relevant only for visualization perhaps
165
135
  SSPL_full_connections[
166
136
  np.isinf(SSPL_full_connections)
167
137
  ] = max_SSPL + 1
@@ -6,6 +6,7 @@ from scipy.spatial.distance import cdist
6
6
  from scipy import ndimage
7
7
  from dipy.io.stateful_tractogram import StatefulTractogram
8
8
 
9
+
9
10
  def create_structural_connectivity(
10
11
  tract,
11
12
  atlas_resampled,
@@ -15,12 +16,14 @@ def create_structural_connectivity(
15
16
  """Compute a structural connectivity matrix from a tractogram and atlas.
16
17
 
17
18
  Streamline endpoints are assigned to the first parcel crossed when
18
- following the streamline from the endpoint inward. Streamlines are
19
- only included if both endpoints are within ``threshold`` of a parcel.
19
+ following the streamline from each endpoint inward. If ``threshold``
20
+ is a number, streamlines are included only if both endpoints reach a
21
+ parcel within the specified distance. If ``threshold`` is None, both
22
+ actual streamline endpoints must lie inside parcels.
20
23
 
21
24
  Parameters
22
25
  ----------
23
- tract : StatefulTractogram
26
+ tract : dipy.io.stateful_tractogram.StatefulTractogram
24
27
  Tractogram containing the streamlines used to estimate structural
25
28
  connectivity.
26
29
  atlas_resampled : nibabel.Nifti1Image
@@ -28,7 +31,8 @@ def create_structural_connectivity(
28
31
  tractogram.
29
32
  threshold : float | None, optional
30
33
  Maximum distance along the streamline from each endpoint to the
31
- first crossed parcel. If None, no distance threshold is applied.
34
+ first crossed parcel. If None, both actual streamline endpoints
35
+ must lie inside parcels. Defaults to 5.0.
32
36
  out_path : pathlib.Path | None, optional
33
37
  Path where the structural connectivity matrix should be saved
34
38
  as a NumPy array. If None, the matrix is not saved.
@@ -41,21 +45,20 @@ def create_structural_connectivity(
41
45
  """
42
46
  atlas = atlas_resampled.get_fdata().astype(int)
43
47
  atlas_affine_inv = np.linalg.inv(atlas_resampled.affine)
44
-
45
48
  n_parcels = int(np.max(atlas))
46
-
47
49
  sc = np.zeros((n_parcels, n_parcels), dtype=np.int32)
48
50
 
49
51
  for streamline in tract.streamlines:
50
-
51
52
  points = np.asarray(streamline)
52
53
  points_h = np.column_stack((points, np.ones(len(points))))
53
-
54
54
  voxel_coords = (atlas_affine_inv @ points_h.T).T[:, :3]
55
55
  voxel_coords = np.rint(voxel_coords).astype(int)
56
56
 
57
- # Keep only points inside the atlas volume
58
- valid = np.all((voxel_coords >= 0) & (voxel_coords < np.array(atlas.shape)), axis=1)
57
+ valid = np.all(
58
+ (voxel_coords >= 0)
59
+ & (voxel_coords < np.array(atlas.shape)),
60
+ axis=1
61
+ )
59
62
 
60
63
  parcel_labels = np.zeros(len(points), dtype=int)
61
64
  parcel_labels[valid] = atlas[
@@ -64,41 +67,54 @@ def create_structural_connectivity(
64
67
  voxel_coords[valid, 2]
65
68
  ]
66
69
 
67
- endpoints = []
70
+ if threshold is None:
71
+ p1 = parcel_labels[0]
72
+ p2 = parcel_labels[-1]
73
+
74
+ if p1 == 0 or p2 == 0:
75
+ continue
76
+ else:
77
+ endpoints = []
68
78
 
69
- for indices in (range(len(points)), range(len(points) - 1, -1, -1)):
79
+ for indices in (
80
+ range(len(points)),
81
+ range(len(points) - 1, -1, -1)
82
+ ):
83
+ distance = 0.0
84
+ parcel = 0
85
+ previous = None
70
86
 
71
- distance = 0.0
72
- parcel = 0
73
- previous = None
87
+ for i in indices:
88
+ if previous is not None:
89
+ distance += np.linalg.norm(
90
+ points[i] - points[previous]
91
+ )
74
92
 
75
- for i in indices:
76
- if previous is not None:
77
- distance += np.linalg.norm(
78
- points[i] - points[previous]
79
- )
80
- if parcel_labels[i] > 0:
81
- parcel = parcel_labels[i]
82
- break
83
- previous = i
84
- endpoints.append((parcel, distance))
93
+ if parcel_labels[i] > 0:
94
+ parcel = parcel_labels[i]
95
+ break
85
96
 
86
- p1, d1 = endpoints[0]
87
- p2, d2 = endpoints[1]
97
+ previous = i
88
98
 
89
- if p1 == 0 or p2 == 0:
90
- continue
91
- if threshold is not None and (d1 > threshold or d2 > threshold):
92
- continue
99
+ endpoints.append((parcel, distance))
100
+
101
+ p1, d1 = endpoints[0]
102
+ p2, d2 = endpoints[1]
103
+
104
+ if p1 == 0 or p2 == 0:
105
+ continue
106
+
107
+ if d1 > threshold or d2 > threshold:
108
+ continue
109
+
110
+ sc[p1-1, p2-1] += 1
93
111
 
94
- p1 -= 1
95
- p2 -= 1
96
- sc[p1, p2] += 1
97
112
  if p1 != p2:
98
- sc[p2, p1] += 1
113
+ sc[p2-1, p1-1] += 1
99
114
 
100
115
  if out_path:
101
116
  np.save(out_path, sc)
102
117
 
103
118
  return sc
104
119
 
120
+
@@ -9,7 +9,7 @@ def atlas_cfg_read(atlas_cfg_path):
9
9
 
10
10
  Parameters
11
11
  ----------
12
- atlas_cfg_path : Path
12
+ atlas_cfg_path : pathlib.Path
13
13
  Path to the .json atlas configuration file. The configuration must
14
14
  contain the following fields:
15
15
 
@@ -57,7 +57,7 @@ def tracts_cfg_read(tracts_cfg_path):
57
57
 
58
58
  Parameters
59
59
  ----------
60
- tracts_cfg_path : Path
60
+ tracts_cfg_path : pathlib.Path
61
61
  Path to the .json tracts configuration file. The configuration must
62
62
  contain the following fields:
63
63
 
@@ -102,7 +102,7 @@ def lesion_cfg_read(lesion_cfg_path: Path):
102
102
 
103
103
  Parameters
104
104
  ----------
105
- tracts_cfg_path : Path
105
+ tracts_cfg_path : pathlib.Path
106
106
  Path to the .json tracts configuration file. The configuration must
107
107
  contain the following fields:
108
108
 
@@ -24,19 +24,19 @@ def create_tract_list(
24
24
 
25
25
  Parameters
26
26
  ----------
27
- references_folder : Path
27
+ references_folder : pathlib.Path
28
28
  Root directory containing the NIfTI reference images.
29
- tracts_folder : Path
29
+ tracts_folder : pathlib.Path
30
30
  Root directory containing the tractogram files.
31
31
 
32
32
  Returns
33
33
  -------
34
- tuple[list[Path], list[Path]]
34
+ tuple[list[pathlib.Path], list[pathlib.Path]]
35
35
  Two lists containing:
36
36
 
37
- - tracts_pathlist : list[Path]
37
+ - tracts_pathlist : list[pathlib.Path]
38
38
  Paths to the tractogram files.
39
- - references_pathlist : list[Path]
39
+ - references_pathlist : list[pathlib.Path]
40
40
  Paths to the corresponding NIfTI reference images.
41
41
 
42
42
  Only tractograms with a corresponding NIfTI reference are included.
@@ -96,6 +96,7 @@ def create_tract_list(
96
96
  # Verify that all NIfTIs are on the same grid
97
97
  reference = None
98
98
 
99
+ # TODO too simple check, should be based on affine with real world coordinates.
99
100
  for nifti_path in references_pathlist:
100
101
  nifti = nib.nifti1.load(nifti_path)
101
102
 
@@ -117,14 +118,14 @@ def uncompress_trk_gz(
117
118
 
118
119
  Parameters
119
120
  ----------
120
- trk_path : Path
121
+ trk_path : pathlib.Path
121
122
  Path to the input .trk or compressed .trk.gz file.
122
- out_path : Path
123
+ out_path : pathlib.Path
123
124
  Path where the uncompressed .trk file is saved.
124
125
 
125
126
  Returns
126
127
  -------
127
- Path
128
+ pathlib.Path
128
129
  Path to the resulting .trk file.
129
130
  """
130
131
  if trk_path.suffix == ".gz":
@@ -143,7 +144,6 @@ def default_atlas_download(out_folder: Path):
143
144
  atlas_path = atlas_cfg_folder / "glasser360_MNI152NLin2009cAsym.nii.gz"
144
145
  atlas_labels_path = atlas_cfg_folder / "glasser360_labels.csv"
145
146
  atlas_labels_path_txt = atlas_labels_path.with_suffix(".txt")
146
- atlas_cfg_path = atlas_cfg_folder / "glasser360_config.json"
147
147
 
148
148
  if atlas_path.exists():
149
149
  warnings.warn(
@@ -189,7 +189,7 @@ def default_atlas_download(out_folder: Path):
189
189
  config = {
190
190
  "name": "glasser360",
191
191
  "atlas": "glasser360_MNI152NLin2009cAsym.nii.gz",
192
- "atlas_labels": "glasser360_labels.csv",
192
+ "labels": "glasser360_labels.csv",
193
193
  "space": "MNI152NLin2009cAsym"
194
194
  }
195
195
 
@@ -205,9 +205,8 @@ def default_tracts_download(out_folder: Path):
205
205
  """Download the default HCP1065 tractography dataset and create its configuration.
206
206
 
207
207
  The function downloads the HCP1065 average tractograms and their
208
- corresponding NIfTI reference images, extracts them into the output
209
- directory, and creates a JSON configuration file describing the
210
- downloaded dataset. Existing folders are reused.
208
+ corresponding NIfTI reference images and creates a default configuration
209
+ file. Existing folders are reused.
211
210
 
212
211
  Parameters
213
212
  ----------
@@ -306,7 +305,7 @@ def get_ref_space_tf(space: str, res: int = 1):
306
305
  Returns
307
306
  -------
308
307
  nibabel.Nifti1Image
309
- T1w template with voxels outside the brain mask set to zero.
308
+ T1w brain mask template.
310
309
  """
311
310
  t1w_ref_path = tf.get(space, resolution=res, desc=None, suffix="T1w")
312
311
  brain_mask_path = tf.get(space, resolution=res, desc="brain", suffix="mask")
@@ -23,7 +23,7 @@ def register_affine(
23
23
 
24
24
  Returns
25
25
  -------
26
- AffineMap
26
+ dipy.align.imaffine.AffineMap
27
27
  Affine mapping from the moving image space to the static image space.
28
28
  """
29
29
 
@@ -91,7 +91,7 @@ def register_syn(
91
91
 
92
92
  Returns
93
93
  -------
94
- DiffeomorphicMap
94
+ dipy.align.imwarp.DiffeomorphicMap
95
95
  Diffeomorphic mapping from the moving image space to the static
96
96
  image space.
97
97
  """
@@ -20,19 +20,19 @@ def get_tracts_disconnections_severity(
20
20
 
21
21
  Parameters
22
22
  ----------
23
- tracts_path : list[Path]
23
+ tracts_path : list[pathlib.Path]
24
24
  Paths to the tractogram files in order.
25
- references_path : list[Path] | Path
25
+ references_path : list[pathlib.Path] | pathlib.Path
26
26
  Paths to the NIfTI reference images corresponding to the tractograms.
27
27
  If a single path is provided, it is used as the reference for all
28
28
  tractograms. If a list, it should be in the same order as tracts_path.
29
- lesion : nib.Nifti1Image
29
+ lesion : nibabel.Nifti1Image
30
30
  NIfTI lesion mask. Voxels with values greater than zero are considered
31
31
  part of the lesion.
32
- disc_tracts_out_path : Path | None, optional
32
+ disc_tracts_out_path : pathlib.Path | None, optional
33
33
  Directory where tractograms containing the disconnected streamlines
34
34
  are saved. If None, disconnected tractograms are not saved.
35
- disc_frame_out_path : Path | None, optional
35
+ disc_frame_out_path : pathlib.Path | None, optional
36
36
  Directory where the resulting CSV file containing the disconnection
37
37
  severity for each tract is saved. If None, the results are not saved.
38
38
 
@@ -93,7 +93,7 @@ def get_tracts_disconnections_severity(
93
93
 
94
94
  if disc_frame_out_path:
95
95
  disc_frame_out_path.mkdir(parents=True, exist_ok=True)
96
- out_csv = disc_frame_out_path / "percent_discon_tract.csv"
96
+ out_csv = disc_frame_out_path / "ratio_discon_tract.csv"
97
97
  disconnections_frame.to_csv(out_csv, index=False)
98
98
 
99
99
  return disconnections_frame
@@ -112,32 +112,32 @@ def get_tracts_disconnections_map(
112
112
 
113
113
  Parameters
114
114
  ----------
115
- tracts : StatefulTractogram
115
+ tracts : dipy.io.stateful_tractogram.StatefulTractogram
116
116
  Tractogram containing all streamlines.
117
- tracts_disconnected : StatefulTractogram
117
+ tracts_disconnected : dipy.io.stateful_tractogram.StatefulTractogram
118
118
  Tractogram containing the streamlines disconnected.
119
- out_path : Path | None, optional
119
+ out_path : pathlib.Path | None, optional
120
120
  Directory where the TDI images and disconnection map are saved.
121
121
  If None, no files are saved.
122
122
 
123
123
  Returns
124
124
  -------
125
- tuple[nib.Nifti1Image, nib.Nifti1Image, nib.Nifti1Image]
125
+ tuple[nibabel.Nifti1Image, nibabel.Nifti1Image, nibabel.Nifti1Image]
126
126
  A tuple containing:
127
127
 
128
- - disconnections_map : nib.Nifti1Image
128
+ - disconnections_map : nibabel.Nifti1Image
129
129
  Voxel-wise ratio of disconnected to total streamline density.
130
- - tdi_aggregated : nib.Nifti1Image
130
+ - tdi_aggregated : nibabel.Nifti1Image
131
131
  Track density image of all streamlines.
132
- - tdi_disconnected : nib.Nifti1Image
132
+ - tdi_disconnected : nibabel.Nifti1Image
133
133
  Track density image of disconnected streamlines.
134
134
  """
135
135
 
136
136
 
137
137
  if out_path:
138
138
  out_path.mkdir(parents=True, exist_ok=True)
139
- tdi_path = out_path / "tdi_mask.nii.gz"
140
- tdi_disconnected_path = out_path / "tdi_disconnected_mask.nii.gz"
139
+ tdi_path = out_path / "tdi.nii.gz"
140
+ tdi_disconnected_path = out_path / "tdi_disconnected.nii.gz"
141
141
  else:
142
142
  tdi_path = None
143
143
  tdi_disconnected_path = None
@@ -17,16 +17,16 @@ def get_tract(
17
17
 
18
18
  Parameters
19
19
  ----------
20
- tract_path : Path
20
+ tract_path : pathlib.Path
21
21
  Path to the tractogram file.
22
- reference_path : Path | None, optional
22
+ reference_path : pathlib.Path | None, optional
23
23
  Path to a NIfTI image to use as the tractogram reference.
24
24
  If provided, the tractogram is reconstructed in RASMM space
25
25
  using this reference.
26
26
 
27
27
  Returns
28
28
  -------
29
- StatefulTractogram
29
+ dipy.io.stateful_tractogram.StatefulTractogram
30
30
  Loaded tractogram, optionally associated with the provided
31
31
  reference image.
32
32
  """
@@ -51,18 +51,18 @@ def get_aggregated_tracts(
51
51
 
52
52
  Parameters
53
53
  ----------
54
- tracts_pathlist : list[Path]
54
+ tracts_pathlist : list[pathlib.Path]
55
55
  Paths to the tractogram files to aggregate.
56
- reference_path : Path | None, optional
56
+ reference_path : pathlib.Path | None, optional
57
57
  Path to a NIfTI image to use as the reference for all tractograms.
58
58
  If not provided, the first loaded tractogram is used as the reference.
59
- out_path : Path | None, optional
59
+ out_path : pathlib.Path | None, optional
60
60
  Path where the aggregated tractogram should be saved. If None,
61
61
  the tractogram is not saved.
62
62
 
63
63
  Returns
64
64
  -------
65
- StatefulTractogram
65
+ dipy.io.stateful_tractogram.StatefulTractogram
66
66
  Aggregated tractogram containing the streamlines from all input
67
67
  tractograms, clipped to the reference image grid.
68
68
  """
@@ -102,16 +102,16 @@ def clip_streamline_to_grid(
102
102
 
103
103
  Parameters
104
104
  ----------
105
- streamline : ndarray
105
+ streamline : numpy.ndarray
106
106
  Streamline coordinates in world space.
107
- inv_affine : ndarray
107
+ inv_affine : numpy.ndarray
108
108
  Inverse affine transformation from world space to voxel space.
109
109
  shape : tuple
110
110
  Shape of the reference image grid.
111
111
 
112
112
  Returns
113
113
  -------
114
- ndarray
114
+ numpy.ndarray
115
115
  Streamline containing only the points that fall within the voxel grid.
116
116
  """
117
117
 
@@ -136,13 +136,13 @@ def clip_tractogram_to_grid(tract):
136
136
 
137
137
  Parameters
138
138
  ----------
139
- tract : StatefulTractogram
139
+ tract : dipy.io.stateful_tractogram.StatefulTractogram
140
140
  Tractogram to clip. Its streamlines are expected to be in the
141
141
  same world space as its reference image.
142
142
 
143
143
  Returns
144
144
  -------
145
- StatefulTractogram
145
+ dipy.io.stateful_tractogram.StatefulTractogram
146
146
  Tractogram containing only streamline points within the reference
147
147
  voxel grid. Streamlines with fewer than two remaining points are
148
148
  removed.
@@ -180,10 +180,10 @@ def get_streamlines_disconnection(
180
180
  ----------
181
181
  tract : dipy.io.stateful_tractogram.StatefulTractogram
182
182
  Tractogram from which to identify intersecting streamlines.
183
- lesion : nib.Nifti1Image
183
+ lesion : nibabel.Nifti1Image
184
184
  NIfTI lesion. Converted to binary mask where voxels with values
185
185
  greater than zero are considered part of the lesion.
186
- out_path : Path | None, optional
186
+ out_path : pathlib.Path | None, optional
187
187
  Path where the disconnected streamlines should be saved. If None,
188
188
  the tractogram is not saved.
189
189
 
@@ -223,15 +223,15 @@ def get_tdi(
223
223
 
224
224
  Parameters
225
225
  ----------
226
- tract : StatefulTractogram
226
+ tract : dipy.io.stateful_tractogram.StatefulTractogram
227
227
  Tractogram from which to compute the track density image.
228
- out_path : Path | None, optional
228
+ out_path : pathlib.Path | None, optional
229
229
  Path where the TDI NIfTI image should be saved. If None, the image
230
230
  is not saved.
231
231
 
232
232
  Returns
233
233
  -------
234
- nib.Nifti1Image
234
+ nibabel.Nifti1Image
235
235
  NIfTI image containing the number of streamlines passing through
236
236
  each voxel.
237
237
  """
pyLQT/pipeline.py CHANGED
@@ -1,12 +1,14 @@
1
1
  from pyLQT.lesion_metrics.white_matter.metrics import get_tracts_disconnections_severity, get_tracts_disconnections_map
2
2
  from pyLQT.lesion_metrics.white_matter.utils import get_streamlines_disconnection, get_aggregated_tracts, clip_tractogram_to_grid
3
3
  from pyLQT.lesion_metrics.network.metrics import get_sspl_increase, get_parcel_wise_disconnection_severity
4
- from pyLQT.lesion_metrics.gray_matter.metrics import get_parcel_damage
4
+ from pyLQT.lesion_metrics.network.utils import create_structural_connectivity
5
+ from pyLQT.lesion_metrics.grey_matter.metrics import get_parcel_damage
5
6
  from pyLQT.lesion_metrics.utils.configs import atlas_cfg_read, tracts_cfg_read, lesion_cfg_read
6
7
  from pyLQT.lesion_metrics.utils.downloads import default_tracts_download, default_atlas_download, create_tract_list, uncompress_trk_gz, get_ref_space_tf
7
8
  from pyLQT.lesion_metrics.utils.registration import register_affine, register_syn
8
9
  from pathlib import Path
9
10
 
11
+ import numpy as np
10
12
  import nibabel as nib
11
13
  import shutil
12
14
  import tempfile
@@ -17,6 +19,7 @@ def run_pyLQT(
17
19
  atlas_cfg=None,
18
20
  tracts_cfg=None,
19
21
  registration_type="syn",
22
+ sc_distance_threshold=5.0,
20
23
  spared_threshold=0.5,
21
24
  delete_tmp=False,
22
25
  ):
@@ -36,6 +39,9 @@ def run_pyLQT(
36
39
  tractography dataset is downloaded.
37
40
  registration_type : {"affine", "syn"}, default="syn"
38
41
  Registration method used to map the lesion and atlas to tract space.
42
+ sc_distance_threshold : float, default=5.0
43
+ Threshold in (0, inf) for distance filtering of tracts endpoints in
44
+ structural connectivity computation.
39
45
  spared_threshold : float, default=0.5
40
46
  Threshold in (0, 1) for spared parcel-to-parcel connectivity.
41
47
  delete_tmp : bool, default=False
@@ -83,7 +89,7 @@ def run_pyLQT(
83
89
  tracts_ref_space = nib.load(tracts_space)
84
90
  else:
85
91
  tracts_ref_space = get_ref_space_tf(tracts_space)
86
-
92
+
87
93
  registrator = (register_affine if registration_type == "affine" else register_syn)
88
94
 
89
95
  lesion_tracts_mapping = registrator(lesion_ref_space, tracts_ref_space)
@@ -115,6 +121,13 @@ def run_pyLQT(
115
121
  tracts_pathlist=tracts_pathlist,
116
122
  out_path=aggregated_tracts_path,
117
123
  )
124
+
125
+ structural_connectivity_aggregated = create_structural_connectivity(
126
+ tract=aggregated_tracts,
127
+ atlas_resampled=atlas_trans,
128
+ out_path=out_folder
129
+ )
130
+ np.save(out_folder / f"{tracts_name}_structural_connectivity.npy", structural_connectivity_aggregated)
118
131
 
119
132
  for lesion_path in lesion_folder.glob("*.nii*"):
120
133
  lesion_name = lesion_path.name.removesuffix(".nii.gz").removesuffix(".nii")
@@ -140,6 +153,13 @@ def run_pyLQT(
140
153
  out_path=aggregated_tracts_disconnected_path,
141
154
  )
142
155
  aggregated_tracts_disconnected = clip_tractogram_to_grid(aggregated_tracts_disconnected)
156
+ structural_connectivity_disconnected = create_structural_connectivity(
157
+ tract=aggregated_tracts_disconnected,
158
+ atlas_resampled=atlas_trans,
159
+ out_path=out_dir
160
+ )
161
+ (out_dir / "parcel_wise_disconnection_severity").mkdir(parents=True, exist_ok=True)
162
+ np.save(out_dir / "parcel_wise_disconnection_severity" / "structural_connectivity_disconnected.npy", structural_connectivity_disconnected)
143
163
 
144
164
  get_parcel_damage(
145
165
  lesion=lesion_trans,
@@ -163,17 +183,16 @@ def run_pyLQT(
163
183
  out_path=out_dir / "wm_disconnections_map",
164
184
  )
165
185
 
166
- structural_connectivity, _, _, per_spared_connections = (
186
+ _, per_spared_connections = (
167
187
  get_parcel_wise_disconnection_severity(
168
- aggregated_tracts=aggregated_tracts,
169
- aggregated_tracts_disconnected=aggregated_tracts_disconnected,
170
- atlas=atlas_trans,
188
+ structural_connectivity=structural_connectivity_aggregated,
189
+ structural_connectivity_disconnected=structural_connectivity_disconnected,
171
190
  out_path=out_dir / "parcel_wise_disconnection_severity",
172
191
  )
173
192
  )
174
193
 
175
194
  get_sspl_increase(
176
- structural_connectivity=structural_connectivity,
195
+ structural_connectivity=structural_connectivity_aggregated,
177
196
  per_spared_connections=per_spared_connections,
178
197
  out_path=out_dir / "sspl_increase",
179
198
  spared_threshold=spared_threshold,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyLQT
3
- Version: 1.0.dev5
3
+ Version: 1.0.dev7
4
4
  Summary: Python version of LQT from Griffis et al. 2021 (https://www.sciencedirect.com/science/article/pii/S2213158221000838)
5
5
  Author-email: Antonin HUDRY <hudryantoninm@gmail.com>
6
6
  License-Expression: GPL-3.0-only
@@ -107,6 +107,9 @@ pyLQT --lesion_cfg <path/to/lesion_config> --out_folder <path/to/outputs>
107
107
  | `--spared_threshold` | `0.5` | Float between `0` and `1` | Threshold used to define spared parcel-to-parcel connectivity. |
108
108
  | `--delete_tmp` | `True` | `True`, `False` | Whether to delete temporary files generated during processing. |
109
109
 
110
+ ## Outputs
111
+
112
+ TODO
110
113
 
111
114
  ## Dependencies
112
115
 
@@ -0,0 +1,23 @@
1
+ pyLQT/__init__.py,sha256=y4DvjD5OqKInZ-wJary448UmEBajl8gNbZv50dgabwI,58
2
+ pyLQT/cli.py,sha256=vygYi7RgTPWshEPUuMzo2b34WGnUSkSstEYMwN1Nqbc,2125
3
+ pyLQT/pipeline.py,sha256=ftCeVXENUxAxA4hakIimPpgTwOFf-maPYTSEqlLr2lY,8399
4
+ pyLQT/lesion_metrics/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ pyLQT/lesion_metrics/grey_matter/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ pyLQT/lesion_metrics/grey_matter/metrics.py,sha256=IDMxnitRetgGUgNZRSG2hlmM790iVggvPLOdNPD7wgE,2770
7
+ pyLQT/lesion_metrics/grey_matter/utils.py,sha256=czxyAESP0neVCue424L0hon-5Tdbsl0pN0zJHWG5HiQ,840
8
+ pyLQT/lesion_metrics/network/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
+ pyLQT/lesion_metrics/network/metrics.py,sha256=kEhn7ZTJqI0FtBiGqib9fAC-TRgRMIDrEv5ecO6loZY,6254
10
+ pyLQT/lesion_metrics/network/utils.py,sha256=UIxyt5f5lAFxjrQm-h8OWJrh5dT7pVtLtg6a5X2TKZM,3756
11
+ pyLQT/lesion_metrics/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
+ pyLQT/lesion_metrics/utils/configs.py,sha256=TJ6dg93NlHl8cIQFh0hzbvsEaVhah4c54KABOjkZa-E,4985
13
+ pyLQT/lesion_metrics/utils/downloads.py,sha256=nKYlDdkzySMTGCGkU1SmlHTpADwX_KbUJ8hG357XfXk,10539
14
+ pyLQT/lesion_metrics/utils/registration.py,sha256=rSZbzEPw4K2R-wASXdTeG7_sJAjyaXxwK0emEGbxiQM,3345
15
+ pyLQT/lesion_metrics/white_matter/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
+ pyLQT/lesion_metrics/white_matter/metrics.py,sha256=aBe350-cQIGuqOy08GOeNTD03SP30byVslVAWFVIgRs,6275
17
+ pyLQT/lesion_metrics/white_matter/utils.py,sha256=iuu2-03E4di4Yc2PcxDNEr58xiSd-suSejkfzqN2e5c,7309
18
+ pylqt-1.0.dev7.dist-info/licenses/LICENSE,sha256=IwGE9guuL-ryRPEKi6wFPI_zOhg7zDZbTYuHbSt_SAk,35823
19
+ pylqt-1.0.dev7.dist-info/METADATA,sha256=ajHTKSCY0abLdJunchkm7wMd60JVKZQeVYkegnXfFug,5246
20
+ pylqt-1.0.dev7.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
21
+ pylqt-1.0.dev7.dist-info/entry_points.txt,sha256=GHGfSFJ0r77qGtkRMJeCuNj2YHm5aynNxdi3JXxyyCc,41
22
+ pylqt-1.0.dev7.dist-info/top_level.txt,sha256=TwID1Q-SuDZ2HjBLKSwruNTXKrRGgAh16rMZ5pjUk4U,6
23
+ pylqt-1.0.dev7.dist-info/RECORD,,
@@ -1,23 +0,0 @@
1
- pyLQT/__init__.py,sha256=y4DvjD5OqKInZ-wJary448UmEBajl8gNbZv50dgabwI,58
2
- pyLQT/cli.py,sha256=gN8m2oVAphtFk17b_aToRtFj2nbYN8XRL6AUgp7fjcw,1887
3
- pyLQT/pipeline.py,sha256=bw11MQ2Owk_3xTPQLCYL1JuCrsqkk9EOI9MIxtEC_uM,7355
4
- pyLQT/lesion_metrics/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
- pyLQT/lesion_metrics/gray_matter/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
- pyLQT/lesion_metrics/gray_matter/metrics.py,sha256=38R3etfmmKo3hFHkYh7Jw2EUrXbW7I0Jkl8So_-5JWA,2616
7
- pyLQT/lesion_metrics/gray_matter/utils.py,sha256=czxyAESP0neVCue424L0hon-5Tdbsl0pN0zJHWG5HiQ,840
8
- pyLQT/lesion_metrics/network/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
- pyLQT/lesion_metrics/network/metrics.py,sha256=Ka3G8_dIq-8H3b8mvRR96QM7p_gR2yFLKUxQOLYMWM4,8281
10
- pyLQT/lesion_metrics/network/utils.py,sha256=fcakfKSMortNIE3TfJP8zwanzBiT1McsYnHcTgwbxE4,3283
11
- pyLQT/lesion_metrics/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
- pyLQT/lesion_metrics/utils/configs.py,sha256=FFur04Sh48IlxUTmz4kRkyLKWffi7bvzyw8B2GclpRU,4961
13
- pyLQT/lesion_metrics/utils/downloads.py,sha256=dXmB_bjt3uEPjJfGThkXw0lojidTTSm_Rx08wyJYafk,10567
14
- pyLQT/lesion_metrics/utils/registration.py,sha256=iqD9qIPLSxsmAPkGbnvyPZBAeVGfnG5_9P0UYZ0JGIg,3307
15
- pyLQT/lesion_metrics/white_matter/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
- pyLQT/lesion_metrics/white_matter/metrics.py,sha256=sujuHry19XpVWFNo52Ntq7h3JkWEcgsZ1-rNFr7E940,6155
17
- pyLQT/lesion_metrics/white_matter/utils.py,sha256=oo492yzxsPACMvHEyYhoYVqgVRrv8mpqP7FOf5OU_Ms,7087
18
- pylqt-1.0.dev5.dist-info/licenses/LICENSE,sha256=IwGE9guuL-ryRPEKi6wFPI_zOhg7zDZbTYuHbSt_SAk,35823
19
- pylqt-1.0.dev5.dist-info/METADATA,sha256=lDt08i-jBH9KuDiFpoX2zaifhB_GI5SjFK6IKgph3f8,5226
20
- pylqt-1.0.dev5.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
21
- pylqt-1.0.dev5.dist-info/entry_points.txt,sha256=GHGfSFJ0r77qGtkRMJeCuNj2YHm5aynNxdi3JXxyyCc,41
22
- pylqt-1.0.dev5.dist-info/top_level.txt,sha256=TwID1Q-SuDZ2HjBLKSwruNTXKrRGgAh16rMZ5pjUk4U,6
23
- pylqt-1.0.dev5.dist-info/RECORD,,