code: def select_from_index(
      urls,
      inclusion_filters=None,
      exclusion_filters=None,
      n_subjects=None,
  ):
      """Select subset of urls with given filters.
  
      Parameters
      ----------
      urls : :obj:`list` of :obj:`str`
          List of dataset urls obtained from index download.
  
      inclusion_filters : :obj:`list` of :obj:`str`, optional
          List of unix shell-style wildcard strings
          that will be used to filter the url list.
          If a filter matches the url it is retained for download.
          Multiple filters work on top of each other.
          Like an "and" logical operator, creating a more restrictive query.
          Inclusion and exclusion filters apply together.
          For example the filter '*task-rest*'' would keep only urls
          that contain the 'task-rest' string.
  
      exclusion_filters : :obj:`list` of :obj:`str`, optional
          List of unix shell-style wildcard strings
          that will be used to filter the url list.
          If a filter matches the url it is discarded for download.
          Multiple filters work on top of each other.
          Like an "and" logical operator, creating a more restrictive query.
          Inclusion and exclusion filters apply together.
          For example the filter '*task-rest*' would discard all urls
          that contain the 'task-rest' string.
  
      n_subjects : :obj:`int`, optional
          Number of subjects to download from the dataset. All by default.
  
      Returns
      -------
      urls : :obj:`list` of :obj:`str`
          Sorted list of filtered dataset directories.
  
      """
      inclusion_filters = inclusion_filters or []
      exclusion_filters = exclusion_filters or []
      # We apply filters to the urls
      for exclusion in exclusion_filters:
          urls = [
              url for url in urls if not fnmatch.fnmatch(url, exclusion)
          ]
      for inclusion in inclusion_filters:
          urls = [
              url for url in urls if fnmatch.fnmatch(url, inclusion)
          ]
  
      # subject selection filter
      # from the url list we infer all available subjects like 'sub-xxx/'
      subject_regex = "sub-[a-z|A-Z|0-9]*[_./]"
  
      def infer_subjects(urls):
          subjects = set()
          for url in urls:
              if "sub-" in url:
                  subjects.add(re.search(subject_regex, url)[0][:-1])
          return sorted(subjects)
  
      # We get a list of subjects (for the moment the first n subjects)
      selected_subjects = set(infer_subjects(urls)[:n_subjects])
      # We exclude urls of subjects not selected
      urls = [
          url
          for url in urls
          if "sub-" not in url
          or re.search(subject_regex, url)[0][:-1] in selected_subjects
      ]
      return urls
  
imports: import fnmatch
  import glob
  import json
  import numbers
  import os
  import re
  import warnings
  from io import BytesIO
  from pathlib import Path
  import nibabel
  import nibabel
  import numpy
  import pandas
  from scipy.io import loadmat
  from sklearn.utils import Bunch
  from nilearn.image import get_data
  from .._utils import check_niimg, fill_doc
  from .._utils.numpy_conversions import csv_to_array
  from ._utils import fetch_files, fetch_single_file, filter_columns, get_dataset_descr, get_dataset_dir, read_md5_sum_file, tree, uncompress_file
label_desc: Use image node_id 26 for calling a global function with example usage: select_from_index(urls, inclusion_filters, exclusion_filters, n_subjects) and returns: urls, sorted