Repository: nilearn/nilearn

Issue:
extract dataset IDs in separate functions
This isn't related to reformatting but I'm wondering whether we should have helper functions whose only responsibility is to return the list of ids for a given dataset fetcher.

So basically something like this:

```python
# In the fetcher
ids = _get_nki_ids()

# Helper function
def _get_nki_ids():
    return [....]
```

 It's not super important, but these massive lists are breaking the function logic and force the reader to scroll up and down which can be annoying...
WDYT ?

_Originally posted by @NicolasGensollen in https://github.com/nilearn/nilearn/pull/3695#discussion_r1170921752_
            


Discussion:
a function or a global constant

Resolving patch:
diff --git a/nilearn/datasets/func.py b/nilearn/datasets/func.py
--- a/nilearn/datasets/func.py
+++ b/nilearn/datasets/func.py
@@ -217,46 +217,9 @@ def fetch_haxby(
     )
 
 
-@fill_doc
-def fetch_adhd(n_subjects=30, data_dir=None, url=None, resume=True, verbose=1):
-    """Download and load the ADHD resting-state dataset.
-
-    See :footcite:`ADHDdataset`.
-
-    Parameters
-    ----------
-    n_subjects : int, optional
-        The number of subjects to load from maximum of 40 subjects.
-        By default, 30 subjects will be loaded. If None is given,
-        all 40 subjects will be loaded. Default=30.
-    %(data_dir)s
-    %(url)s
-    %(resume)s
-    %(verbose)s
-
-    Returns
-    -------
-    data : sklearn.datasets.base.Bunch
-        Dictionary-like object, the interest attributes are :
-
-         - 'func': Paths to functional resting-state images
-         - 'phenotypic': Explanations of preprocessing steps
-         - 'confounds': CSV files containing the nuisance variables
-
-    References
-    ----------
-    .. footbibliography::
-
-    """
-    if url is None:
-        url = "https://www.nitrc.org/frs/download.php/"
-
-    # Preliminary checks and declarations
-    dataset_name = "adhd"
-    data_dir = _get_dataset_dir(
-        dataset_name, data_dir=data_dir, verbose=verbose
-    )
-    ids = [
+def adhd_ids():
+    """Return subject ids for the ADHD dataset."""
+    return [
         "0010042",
         "0010064",
         "0010128",
@@ -298,6 +261,48 @@ def fetch_adhd(n_subjects=30, data_dir=None, url=None, resume=True, verbose=1):
         "9744150",
         "9750701",
     ]
+
+
+@fill_doc
+def fetch_adhd(n_subjects=30, data_dir=None, url=None, resume=True, verbose=1):
+    """Download and load the ADHD resting-state dataset.
+
+    See :footcite:`ADHDdataset`.
+
+    Parameters
+    ----------
+    n_subjects : int, optional
+        The number of subjects to load from maximum of 40 subjects.
+        By default, 30 subjects will be loaded. If None is given,
+        all 40 subjects will be loaded. Default=30.
+    %(data_dir)s
+    %(url)s
+    %(resume)s
+    %(verbose)s
+
+    Returns
+    -------
+    data : sklearn.datasets.base.Bunch
+        Dictionary-like object, the interest attributes are :
+
+         - 'func': Paths to functional resting-state images
+         - 'phenotypic': Explanations of preprocessing steps
+         - 'confounds': CSV files containing the nuisance variables
+
+    References
+    ----------
+    .. footbibliography::
+
+    """
+    if url is None:
+        url = "https://www.nitrc.org/frs/download.php/"
+
+    # Preliminary checks and declarations
+    dataset_name = "adhd"
+    data_dir = _get_dataset_dir(
+        dataset_name, data_dir=data_dir, verbose=verbose
+    )
+    ids = adhd_ids()
     nitrc_ids = range(7782, 7822)
     max_subjects = len(ids)
     if n_subjects is None:
@@ -367,6 +372,51 @@ def fetch_adhd(n_subjects=30, data_dir=None, url=None, resume=True, verbose=1):
     )
 
 
+def miyawaki2008_file_mask():
+    """Return file listing for the miyawaki 2008 dataset."""
+    return [
+        "mask.nii.gz",
+        "LHlag0to1.nii.gz",
+        "LHlag10to11.nii.gz",
+        "LHlag1to2.nii.gz",
+        "LHlag2to3.nii.gz",
+        "LHlag3to4.nii.gz",
+        "LHlag4to5.nii.gz",
+        "LHlag5to6.nii.gz",
+        "LHlag6to7.nii.gz",
+        "LHlag7to8.nii.gz",
+        "LHlag8to9.nii.gz",
+        "LHlag9to10.nii.gz",
+        "LHV1d.nii.gz",
+        "LHV1v.nii.gz",
+        "LHV2d.nii.gz",
+        "LHV2v.nii.gz",
+        "LHV3A.nii.gz",
+        "LHV3.nii.gz",
+        "LHV4v.nii.gz",
+        "LHVP.nii.gz",
+        "RHlag0to1.nii.gz",
+        "RHlag10to11.nii.gz",
+        "RHlag1to2.nii.gz",
+        "RHlag2to3.nii.gz",
+        "RHlag3to4.nii.gz",
+        "RHlag4to5.nii.gz",
+        "RHlag5to6.nii.gz",
+        "RHlag6to7.nii.gz",
+        "RHlag7to8.nii.gz",
+        "RHlag8to9.nii.gz",
+        "RHlag9to10.nii.gz",
+        "RHV1d.nii.gz",
+        "RHV1v.nii.gz",
+        "RHV2d.nii.gz",
+        "RHV2v.nii.gz",
+        "RHV3A.nii.gz",
+        "RHV3.nii.gz",
+        "RHV4v.nii.gz",
+        "RHVP.nii.gz",
+    ]
+
+
 @fill_doc
 def fetch_miyawaki2008(data_dir=None, url=None, resume=True, verbose=1):
     """Download and loads Miyawaki et al. 2008 dataset (153MB).
@@ -448,51 +498,10 @@ def fetch_miyawaki2008(data_dir=None, url=None, resume=True, verbose=1):
     ]
 
     # Masks
-
     file_mask = [
-        "mask.nii.gz",
-        "LHlag0to1.nii.gz",
-        "LHlag10to11.nii.gz",
-        "LHlag1to2.nii.gz",
-        "LHlag2to3.nii.gz",
-        "LHlag3to4.nii.gz",
-        "LHlag4to5.nii.gz",
-        "LHlag5to6.nii.gz",
-        "LHlag6to7.nii.gz",
-        "LHlag7to8.nii.gz",
-        "LHlag8to9.nii.gz",
-        "LHlag9to10.nii.gz",
-        "LHV1d.nii.gz",
-        "LHV1v.nii.gz",
-        "LHV2d.nii.gz",
-        "LHV2v.nii.gz",
-        "LHV3A.nii.gz",
-        "LHV3.nii.gz",
-        "LHV4v.nii.gz",
-        "LHVP.nii.gz",
-        "RHlag0to1.nii.gz",
-        "RHlag10to11.nii.gz",
-        "RHlag1to2.nii.gz",
-        "RHlag2to3.nii.gz",
-        "RHlag3to4.nii.gz",
-        "RHlag4to5.nii.gz",
-        "RHlag5to6.nii.gz",
-        "RHlag6to7.nii.gz",
-        "RHlag7to8.nii.gz",
-        "RHlag8to9.nii.gz",
-        "RHlag9to10.nii.gz",
-        "RHV1d.nii.gz",
-        "RHV1v.nii.gz",
-        "RHV2d.nii.gz",
-        "RHV2v.nii.gz",
-        "RHV3A.nii.gz",
-        "RHV3.nii.gz",
-        "RHV4v.nii.gz",
-        "RHVP.nii.gz",
+        (os.path.join("mask", m), url, opts) for m in miyawaki2008_file_mask()
     ]
 
-    file_mask = [(os.path.join("mask", m), url, opts) for m in file_mask]
-
     file_names = (
         func_figure + func_random + label_figure + label_random + file_mask
     )
@@ -1478,57 +1487,9 @@ def fetch_megatrawls_netmats(
     )
 
 
-@fill_doc
-def fetch_surf_nki_enhanced(
-    n_subjects=10, data_dir=None, url=None, resume=True, verbose=1
-):
-    """Download and load the NKI enhanced resting-state dataset, \
-    preprocessed and projected to the fsaverage5 space surface.
-
-    See :footcite:`Nooner2012`.
-
-    Direct download link :footcite:`NKIdataset`.
-
-    .. versionadded:: 0.3
-
-    Parameters
-    ----------
-    n_subjects : int, optional
-        The number of subjects to load from maximum of 102 subjects.
-        By default, 10 subjects will be loaded. If None is given,
-        all 102 subjects will be loaded. Default=10.
-    %(data_dir)s
-    %(url)s
-    %(resume)s
-    %(verbose)s
-
-    Returns
-    -------
-    data : sklearn.datasets.base.Bunch
-        Dictionary-like object, the interest attributes are :
-
-        - 'func_left': Paths to Gifti files containing resting state
-                        time series left hemisphere
-        - 'func_right': Paths to Gifti files containing resting state
-                         time series right hemisphere
-        - 'phenotypic': array containing tuple with subject ID, age,
-                         dominant hand and sex for each subject.
-        - 'description': data description of the release and references.
-
-    References
-    ----------
-    .. footbibliography::
-
-    """
-    if url is None:
-        url = "https://www.nitrc.org/frs/download.php/"
-
-    # Preliminary checks and declarations
-    dataset_name = "nki_enhanced_surface"
-    data_dir = _get_dataset_dir(
-        dataset_name, data_dir=data_dir, verbose=verbose
-    )
-    ids = [
+def nki_ids():
+    """Return the subject ids of the NKI dataset."""
+    return [
         "A00028185",
         "A00033747",
         "A00035072",
@@ -1633,7 +1594,60 @@ def fetch_surf_nki_enhanced(
         "A00056949",
     ]
 
+
+@fill_doc
+def fetch_surf_nki_enhanced(
+    n_subjects=10, data_dir=None, url=None, resume=True, verbose=1
+):
+    """Download and load the NKI enhanced resting-state dataset, \
+    preprocessed and projected to the fsaverage5 space surface.
+
+    See :footcite:`Nooner2012`.
+
+    Direct download link :footcite:`NKIdataset`.
+
+    .. versionadded:: 0.3
+
+    Parameters
+    ----------
+    n_subjects : int, optional
+        The number of subjects to load from maximum of 102 subjects.
+        By default, 10 subjects will be loaded. If None is given,
+        all 102 subjects will be loaded. Default=10.
+    %(data_dir)s
+    %(url)s
+    %(resume)s
+    %(verbose)s
+
+    Returns
+    -------
+    data : sklearn.datasets.base.Bunch
+        Dictionary-like object, the interest attributes are :
+
+        - 'func_left': Paths to Gifti files containing resting state
+                        time series left hemisphere
+        - 'func_right': Paths to Gifti files containing resting state
+                         time series right hemisphere
+        - 'phenotypic': array containing tuple with subject ID, age,
+                         dominant hand and sex for each subject.
+        - 'description': data description of the release and references.
+
+    References
+    ----------
+    .. footbibliography::
+
+    """
+    if url is None:
+        url = "https://www.nitrc.org/frs/download.php/"
+
+    # Preliminary checks and declarations
+    dataset_name = "nki_enhanced_surface"
+    data_dir = _get_dataset_dir(
+        dataset_name, data_dir=data_dir, verbose=verbose
+    )
+
     nitrc_ids = range(8260, 8464)
+    ids = nki_ids()
     max_subjects = len(ids)
     if n_subjects is None:
         n_subjects = max_subjects
diff --git a/nilearn/datasets/struct.py b/nilearn/datasets/struct.py
--- a/nilearn/datasets/struct.py
+++ b/nilearn/datasets/struct.py
@@ -546,6 +546,53 @@ def fetch_icbm152_brain_gm_mask(
     return gm_mask_img
 
 
+def oasis_missing_subjects():
+    """Return list of missing subjects in OASIS dataset."""
+    return [
+        8,
+        24,
+        36,
+        48,
+        89,
+        93,
+        100,
+        118,
+        128,
+        149,
+        154,
+        171,
+        172,
+        175,
+        187,
+        194,
+        196,
+        215,
+        219,
+        225,
+        242,
+        245,
+        248,
+        251,
+        252,
+        257,
+        276,
+        297,
+        306,
+        320,
+        324,
+        334,
+        347,
+        360,
+        364,
+        391,
+        393,
+        412,
+        414,
+        427,
+        436,
+    ]
+
+
 @fill_doc
 def fetch_oasis_vbm(
     n_subjects=None,
@@ -689,49 +736,7 @@ def fetch_oasis_vbm(
     opts = {"uncompress": True}
 
     # missing subjects create shifts in subjects ids
-    missing_subjects = [
-        8,
-        24,
-        36,
-        48,
-        89,
-        93,
-        100,
-        118,
-        128,
-        149,
-        154,
-        171,
-        172,
-        175,
-        187,
-        194,
-        196,
-        215,
-        219,
-        225,
-        242,
-        245,
-        248,
-        251,
-        252,
-        257,
-        276,
-        297,
-        306,
-        320,
-        324,
-        334,
-        347,
-        360,
-        364,
-        391,
-        393,
-        412,
-        414,
-        427,
-        436,
-    ]
+    missing_subjects = oasis_missing_subjects()
 
     if dartel_version:
         # DARTEL produces outliers that are hidden by nilearn API


Test patch: