junifer 0.0.4.dev598__py3-none-any.whl → 0.0.4.dev603__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.
junifer/_version.py CHANGED
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '0.0.4.dev598'
16
- __version_tuple__ = version_tuple = (0, 0, 4, 'dev598')
15
+ __version__ = version = '0.0.4.dev603'
16
+ __version_tuple__ = version_tuple = (0, 0, 4, 'dev603')
@@ -127,6 +127,13 @@ for n_rois in range(100, 1001, 100):
127
127
  "kong_networks": 17,
128
128
  "space": "MNI152NLin6Asym",
129
129
  }
130
+ # Add Brainnetome parcellation info
131
+ for threshold in [0, 25, 50]:
132
+ _available_parcellations[f"Brainnetome_thr{threshold}"] = {
133
+ "family": "Brainnetome",
134
+ "threshold": threshold,
135
+ "space": "MNI152NLin6Asym",
136
+ }
130
137
 
131
138
 
132
139
  def register_parcellation(
@@ -523,6 +530,9 @@ def _retrieve_parcellation(
523
530
  Number of Yeo networks to use (default None).
524
531
  ``kong_networks`` : {17}, optional
525
532
  Number of Kong networks to use (default None).
533
+ * Brainnetome :
534
+ ``threshold`` : {0, 25, 50}
535
+ Threshold for the probabilistic maps of subregion.
526
536
 
527
537
  Returns
528
538
  -------
@@ -586,6 +596,12 @@ def _retrieve_parcellation(
586
596
  resolution=resolution,
587
597
  **kwargs,
588
598
  )
599
+ elif family == "Brainnetome":
600
+ parcellation_fname, parcellation_labels = _retrieve_brainnetome(
601
+ parcellations_dir=parcellations_dir,
602
+ resolution=resolution,
603
+ **kwargs,
604
+ )
589
605
  else:
590
606
  raise_error(
591
607
  f"The provided parcellation name {family} cannot be retrieved."
@@ -1555,6 +1571,122 @@ def _retrieve_yan(
1555
1571
  return parcellation_fname, labels
1556
1572
 
1557
1573
 
1574
+ def _retrieve_brainnetome(
1575
+ parcellations_dir: Path,
1576
+ resolution: Optional[float] = None,
1577
+ threshold: Optional[int] = None,
1578
+ ) -> Tuple[Path, List[str]]:
1579
+ """Retrieve Brainnetome parcellation.
1580
+
1581
+ Parameters
1582
+ ----------
1583
+ parcellations_dir : pathlib.Path
1584
+ The path to the parcellation data directory.
1585
+ resolution : {1.0, 1.25, 2.0}, optional
1586
+ The desired resolution of the parcellation to load. If it is not
1587
+ available, the closest resolution will be loaded. Preferably, use a
1588
+ resolution higher than the desired one. By default, will load the
1589
+ highest one (default None). Available resolutions for this
1590
+ parcellation are 1mm, 1.25mm and 2mm.
1591
+ threshold : {0, 25, 50}, optional
1592
+ The threshold for the probabilistic maps of subregion (default None).
1593
+
1594
+ Returns
1595
+ -------
1596
+ pathlib.Path
1597
+ File path to the parcellation image.
1598
+ list of str
1599
+ Parcellation labels.
1600
+
1601
+ Raises
1602
+ ------
1603
+ RuntimeError
1604
+ If there is a problem fetching files.
1605
+ ValueError
1606
+ If invalid value is provided for ``threshold``.
1607
+
1608
+ """
1609
+ logger.info("Parcellation parameters:")
1610
+ logger.info(f"\tresolution: {resolution}")
1611
+ logger.info(f"\tthreshold: {threshold}")
1612
+
1613
+ # Check resolution
1614
+ _valid_resolutions = [1.0, 1.25, 2.0]
1615
+ resolution = closest_resolution(resolution, _valid_resolutions)
1616
+
1617
+ # Check threshold value
1618
+ _valid_threshold = [0, 25, 50]
1619
+ if threshold not in _valid_threshold:
1620
+ raise_error(
1621
+ f"The parameter `threshold` ({threshold}) needs to be one of the "
1622
+ f"following: {_valid_threshold}"
1623
+ )
1624
+ # Correct resolution for further stuff
1625
+ if resolution in [1.0, 2.0]:
1626
+ resolution = int(resolution)
1627
+
1628
+ parcellation_fname = (
1629
+ parcellations_dir
1630
+ / "BNA246"
1631
+ / f"BNA-maxprob-thr{threshold}-{resolution}mm.nii.gz"
1632
+ )
1633
+
1634
+ # Check for existence of parcellation
1635
+ if not parcellation_fname.exists():
1636
+ # Set URL
1637
+ url = f"http://neurovault.org/media/images/1625/BNA-maxprob-thr{threshold}-{resolution}mm.nii.gz"
1638
+
1639
+ logger.info(f"Downloading Brainnetome from {url}")
1640
+ # Make HTTP request
1641
+ try:
1642
+ resp = httpx.get(url, follow_redirects=True)
1643
+ resp.raise_for_status()
1644
+ except httpx.HTTPError as exc:
1645
+ raise_error(
1646
+ f"Error response {exc.response.status_code} while "
1647
+ f"requesting {exc.request.url!r}",
1648
+ klass=RuntimeError,
1649
+ )
1650
+ else:
1651
+ # Create local directory if not present
1652
+ parcellation_fname.parent.mkdir(parents=True, exist_ok=True)
1653
+ # Create file if not present
1654
+ parcellation_fname.touch(exist_ok=True)
1655
+ # Open file and write bytes
1656
+ parcellation_fname.write_bytes(resp.content)
1657
+
1658
+ # Load labels
1659
+ labels = (
1660
+ sorted([f"SFG_L(R)_7_{i}" for i in range(1, 8)] * 2)
1661
+ + sorted([f"MFG_L(R)_7_{i}" for i in range(1, 8)] * 2)
1662
+ + sorted([f"IFG_L(R)_6_{i}" for i in range(1, 7)] * 2)
1663
+ + sorted([f"OrG_L(R)_6_{i}" for i in range(1, 7)] * 2)
1664
+ + sorted([f"PrG_L(R)_6_{i}" for i in range(1, 7)] * 2)
1665
+ + sorted([f"PCL_L(R)_2_{i}" for i in range(1, 3)] * 2)
1666
+ + sorted([f"STG_L(R)_6_{i}" for i in range(1, 7)] * 2)
1667
+ + sorted([f"MTG_L(R)_4_{i}" for i in range(1, 5)] * 2)
1668
+ + sorted([f"ITG_L(R)_7_{i}" for i in range(1, 8)] * 2)
1669
+ + sorted([f"FuG_L(R)_3_{i}" for i in range(1, 4)] * 2)
1670
+ + sorted([f"PhG_L(R)_6_{i}" for i in range(1, 7)] * 2)
1671
+ + sorted([f"pSTS_L(R)_2_{i}" for i in range(1, 3)] * 2)
1672
+ + sorted([f"SPL_L(R)_5_{i}" for i in range(1, 6)] * 2)
1673
+ + sorted([f"IPL_L(R)_6_{i}" for i in range(1, 7)] * 2)
1674
+ + sorted([f"PCun_L(R)_4_{i}" for i in range(1, 5)] * 2)
1675
+ + sorted([f"PoG_L(R)_4_{i}" for i in range(1, 5)] * 2)
1676
+ + sorted([f"INS_L(R)_6_{i}" for i in range(1, 7)] * 2)
1677
+ + sorted([f"CG_L(R)_7_{i}" for i in range(1, 8)] * 2)
1678
+ + sorted([f"MVOcC _L(R)_5_{i}" for i in range(1, 6)] * 2)
1679
+ + sorted([f"LOcC_L(R)_4_{i}" for i in range(1, 5)] * 2)
1680
+ + sorted([f"LOcC_L(R)_2_{i}" for i in range(1, 3)] * 2)
1681
+ + sorted([f"Amyg_L(R)_2_{i}" for i in range(1, 3)] * 2)
1682
+ + sorted([f"Hipp_L(R)_2_{i}" for i in range(1, 3)] * 2)
1683
+ + sorted([f"BG_L(R)_6_{i}" for i in range(1, 7)] * 2)
1684
+ + sorted([f"Tha_L(R)_8_{i}" for i in range(1, 9)] * 2)
1685
+ )
1686
+
1687
+ return parcellation_fname, labels
1688
+
1689
+
1558
1690
  def merge_parcellations(
1559
1691
  parcellations_list: List["Nifti1Image"],
1560
1692
  parcellations_names: List[str],
@@ -16,6 +16,7 @@ from numpy.testing import assert_array_almost_equal, assert_array_equal
16
16
 
17
17
  from junifer.data.parcellations import (
18
18
  _retrieve_aicha,
19
+ _retrieve_brainnetome,
19
20
  _retrieve_parcellation,
20
21
  _retrieve_schaefer,
21
22
  _retrieve_shen,
@@ -955,6 +956,77 @@ def test_retrieve_yan_incorrect_kong_networks(tmp_path: Path) -> None:
955
956
  )
956
957
 
957
958
 
959
+ @pytest.mark.parametrize(
960
+ "resolution, threshold",
961
+ [
962
+ (1.0, 0),
963
+ (1.0, 25),
964
+ (1.0, 50),
965
+ (1.25, 0),
966
+ (1.25, 25),
967
+ (1.25, 50),
968
+ (2, 0),
969
+ (2, 25),
970
+ (2, 50),
971
+ ],
972
+ )
973
+ def test_brainnetome(
974
+ tmp_path: Path,
975
+ resolution: float,
976
+ threshold: int,
977
+ ) -> None:
978
+ """Test Brainnetome parcellation.
979
+
980
+ Parameters
981
+ ----------
982
+ tmp_path : pathlib.Path
983
+ The path to the test directory.
984
+ resolution : float
985
+ The parametrized resolution values.
986
+ threshold : int
987
+ The parametrized threshold values.
988
+
989
+ """
990
+ parcellations = list_parcellations()
991
+ parcellation_name = f"Brainnetome_thr{threshold}"
992
+ assert parcellation_name in parcellations
993
+
994
+ # Fix resolution
995
+ if resolution in [1.0, 2.0]:
996
+ resolution = int(resolution)
997
+
998
+ parcellation_file = f"BNA-maxprob-thr{threshold}-{resolution}mm.nii.gz"
999
+ # Load parcellation
1000
+ img, label, img_path, space = load_parcellation(
1001
+ name=parcellation_name,
1002
+ parcellations_dir=tmp_path,
1003
+ resolution=resolution,
1004
+ )
1005
+ assert img is not None
1006
+ assert img_path.name == parcellation_file
1007
+ assert space == "MNI152NLin6Asym"
1008
+ assert len(label) == 246
1009
+ assert_array_equal(
1010
+ img.header["pixdim"][1:4], 3 * [resolution] # type: ignore
1011
+ )
1012
+
1013
+
1014
+ def test_retrieve_brainnetome_incorrect_threshold(tmp_path: Path) -> None:
1015
+ """Test retrieve Brainnetome with incorrect threshold.
1016
+
1017
+ Parameters
1018
+ ----------
1019
+ tmp_path : pathlib.Path
1020
+ The path to the test directory.
1021
+
1022
+ """
1023
+ with pytest.raises(ValueError, match="The parameter `threshold`"):
1024
+ _retrieve_brainnetome(
1025
+ parcellations_dir=tmp_path,
1026
+ threshold=100,
1027
+ )
1028
+
1029
+
958
1030
  def test_merge_parcellations() -> None:
959
1031
  """Test merging parcellations."""
960
1032
  # load some parcellations for testing
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: junifer
3
- Version: 0.0.4.dev598
3
+ Version: 0.0.4.dev603
4
4
  Summary: JUelich NeuroImaging FEature extractoR
5
5
  Author-email: Fede Raimondo <f.raimondo@fz-juelich.de>, Synchon Mandal <s.mandal@fz-juelich.de>
6
6
  Maintainer-email: Fede Raimondo <f.raimondo@fz-juelich.de>, Synchon Mandal <s.mandal@fz-juelich.de>
@@ -1,5 +1,5 @@
1
1
  junifer/__init__.py,sha256=x1UR2jUcrUdm2HNl-3Qvyi4UUrU6ms5qm2qcmNY7zZk,391
2
- junifer/_version.py,sha256=0b-6T03LCF9KSbMRM19VUFB2BftKmDOcGOSs97KkCe8,428
2
+ junifer/_version.py,sha256=PL4nZxv7MRGWSMu4CtYS0p4UOpsK0lmE7i-MK05lcpk,428
3
3
  junifer/stats.py,sha256=sU5IZ2qFZWbzgSutQS_z42miIVItpSGmQYBn6KkD5fA,6162
4
4
  junifer/api/__init__.py,sha256=YILu9M7SC0Ri4CVd90fELH2OnK_gvCYAXCoqBNCFE8E,257
5
5
  junifer/api/cli.py,sha256=T6FTW3vDRlsdkSYerbQD7Q05uA9bV6f8oHvK1jxGUa8,12882
@@ -45,7 +45,7 @@ junifer/configs/juseless/datagrabbers/tests/test_ukb_vbm.py,sha256=b9hjc1mgO--PS
45
45
  junifer/data/__init__.py,sha256=1E6JtzpnjjA0IutkJkarEik9NhCP9PPI6K0-37XDZVg,602
46
46
  junifer/data/coordinates.py,sha256=SG3nSDBoH5oDsvo6qjqg3X8rHK86vYQRa3bpfZ0e4zE,12833
47
47
  junifer/data/masks.py,sha256=81v3GhAf9lc_CobV9f6n_vMK1jWZCbeANmopa02XZOQ,17744
48
- junifer/data/parcellations.py,sha256=FB-cx4ZKl9BhsOEl6PCsWRGAL0emjTJKC0KMKqARL18,58205
48
+ junifer/data/parcellations.py,sha256=o10afxUnQXdClW2thFFz5mAED6ptMkvSVRaj0LxiwKc,63312
49
49
  junifer/data/template_spaces.py,sha256=fHuihkPCq816rhvI72Us57cSnEPqDf7gWpVZIhOkoMY,4862
50
50
  junifer/data/utils.py,sha256=Jmbc7SLzy4nLP_zkWv_aJzb1MZ27tutJ98ifsECCamM,1295
51
51
  junifer/data/VOIs/meta/AutobiographicalMemory_VOIs.txt,sha256=9af38naeL18Tlt_gy_ep6vyTAxOB336JYjbo5FvP8PQ,686
@@ -73,7 +73,7 @@ junifer/data/masks/vickery-patil/GMprob0.2_cortex_3mm_NA_rm.nii.gz,sha256=jfMe_4
73
73
  junifer/data/tests/test_coordinates.py,sha256=BNkz9qFbnwAI0oVlIm_XrT-z4Vsia_rMtMVaoFXT6mU,4328
74
74
  junifer/data/tests/test_data_utils.py,sha256=_DaiC8K79gs9HFHxr-udNeE2YTM6JA0-1i-K2cqK9qA,1087
75
75
  junifer/data/tests/test_masks.py,sha256=wZ7nsY55on6LpJdRm7VXp1qqQQlENmSK6bNOgiMTE4M,14572
76
- junifer/data/tests/test_parcellations.py,sha256=3Tk0bU4xT9TJfdrDWcUMq6ns-IPJUpZzkiR-PEbmM6M,36212
76
+ junifer/data/tests/test_parcellations.py,sha256=aUq6t1s6yP_Sw-Ur8mZMkODYgE8VTQ36Y3l3UGprUdk,38001
77
77
  junifer/data/tests/test_template_spaces.py,sha256=EDsGYBAwjqjOANDNssXaaXPkNv9P658JRtCN2vUulf8,2258
78
78
  junifer/datagrabber/__init__.py,sha256=pZHJIY8nAlbVngsyRScE6a6GKbytiwjJB7SdJNqIbl4,680
79
79
  junifer/datagrabber/base.py,sha256=clErdDX5jz8LTjwPTQPCv3jfELCJ2vObg7ks8imAx8Y,6224
@@ -236,10 +236,10 @@ junifer/utils/logging.py,sha256=T0HgiCI6cS2tp9nbI4cM3nVzMMjiVzgoxuyo5Y1rCyY,9124
236
236
  junifer/utils/tests/test_fs.py,sha256=WQS7cKlKEZ742CIuiOYYpueeAhY9PqlastfDVpVVtvE,923
237
237
  junifer/utils/tests/test_helpers.py,sha256=k5qqfxK8dFyuewTJyR1Qn6-nFaYNuVr0ysc18bfPjyU,929
238
238
  junifer/utils/tests/test_logging.py,sha256=l8oo-AiBV7H6_IzlsNcj__cLeZBUvgIGoaMszD9VaJg,7754
239
- junifer-0.0.4.dev598.dist-info/AUTHORS.rst,sha256=rmULKpchpSol4ExWFdm-qu4fkpSZPYqIESVJBZtGb6E,163
240
- junifer-0.0.4.dev598.dist-info/LICENSE.md,sha256=MqCnOBu8uXsEOzRZWh9EBVfVz-kE9NkXcLCrtGXo2yU,34354
241
- junifer-0.0.4.dev598.dist-info/METADATA,sha256=8L1jlWDrOGYFyV51oVzGLMDkm7_lZE-rRgJ0pFoCT7A,8128
242
- junifer-0.0.4.dev598.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
243
- junifer-0.0.4.dev598.dist-info/entry_points.txt,sha256=DxFvKq0pOqRunAK0FxwJcoDfV1-dZvsFDpD5HRqSDhw,48
244
- junifer-0.0.4.dev598.dist-info/top_level.txt,sha256=4bAq1R2QFQ4b3hohjys2JBvxrl0GKk5LNFzYvz9VGcA,8
245
- junifer-0.0.4.dev598.dist-info/RECORD,,
239
+ junifer-0.0.4.dev603.dist-info/AUTHORS.rst,sha256=rmULKpchpSol4ExWFdm-qu4fkpSZPYqIESVJBZtGb6E,163
240
+ junifer-0.0.4.dev603.dist-info/LICENSE.md,sha256=MqCnOBu8uXsEOzRZWh9EBVfVz-kE9NkXcLCrtGXo2yU,34354
241
+ junifer-0.0.4.dev603.dist-info/METADATA,sha256=Q5Qnoq5I2Z_1m4_jHDe9rRFTys4nTi5X8JsyzpTM3n0,8128
242
+ junifer-0.0.4.dev603.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
243
+ junifer-0.0.4.dev603.dist-info/entry_points.txt,sha256=DxFvKq0pOqRunAK0FxwJcoDfV1-dZvsFDpD5HRqSDhw,48
244
+ junifer-0.0.4.dev603.dist-info/top_level.txt,sha256=4bAq1R2QFQ4b3hohjys2JBvxrl0GKk5LNFzYvz9VGcA,8
245
+ junifer-0.0.4.dev603.dist-info/RECORD,,