def _filter_files(self, keywords: Optional[Union[(str, list[str])]]=None, hemisphere: Optional[str]=None, stimulation: Optional[str]=None, medication: Optional[str]=None, exclude: Optional[Union[(str, list[str])]]=None) -> None:
    'Filter filepaths for given parameters.'
    filtered_files = self.files
    if exclude:
        if (not isinstance(exclude, list)):
            exclude = [exclude]
        filtered_files = [file for file in filtered_files if (not any(((item in file) for item in exclude)))]
    if keywords:
        if (not isinstance(keywords, list)):
            keywords = [keywords]
        filtered_files = self._keyword_search(filtered_files, keywords)
    if stimulation:
        if (stimulation.lower() in 'stimon'):
            stim = 'StimOn'
        elif (stimulation.lower() in 'stimoff'):
            stim = 'StimOff'
        else:
            raise ValueError('Keyword for stimulation not valid.')
        filtered_files = self._keyword_search(filtered_files, [stim])
    if medication:
        if (medication.lower() in 'medon'):
            med = 'MedOn'
        elif (medication.lower() in 'medoff'):
            med = 'MedOff'
        else:
            raise ValueError('Keyword for medication not valid.')
        filtered_files = self._keyword_search(filtered_files, [med])
    if hemisphere:
        matching_files = []
        for file in filtered_files:
            subject = mne_bids.get_entities_from_fname(file)['subject']
            if ((subject not in self.hemispheres) or (self.hemispheres[subject] is None)):
                raise HemisphereNotSpecifiedError(subject, self.hemispheres)
            hem = (self.hemispheres[subject] + '_')
            if ((hemisphere.lower() in 'ipsilateral') and (hem in file)):
                matching_files.append(file)
            if ((hemisphere.lower() in 'contralateral') and (hem not in file)):
                matching_files.append(file)
        filtered_files = matching_files
    self.files = filtered_files
Filter filepaths for given parameters.
def _filter_files(self, keywords: Optional[Union[(str, list[str])]]=None, hemisphere: Optional[str]=None, stimulation: Optional[str]=None, medication: Optional[str]=None, exclude: Optional[Union[(str, list[str])]]=None) -> None:
    
    filtered_files = self.files
    if exclude:
        if (not isinstance(exclude, list)):
            exclude = [exclude]
        filtered_files = [file for file in filtered_files if (not any(((item in file) for item in exclude)))]
    if keywords:
        if (not isinstance(keywords, list)):
            keywords = [keywords]
        filtered_files = self._keyword_search(filtered_files, keywords)
    if stimulation:
        if (stimulation.lower() in 'stimon'):
            stim = 'StimOn'
        elif (stimulation.lower() in 'stimoff'):
            stim = 'StimOff'
        else:
            raise ValueError('Keyword for stimulation not valid.')
        filtered_files = self._keyword_search(filtered_files, [stim])
    if medication:
        if (medication.lower() in 'medon'):
            med = 'MedOn'
        elif (medication.lower() in 'medoff'):
            med = 'MedOff'
        else:
            raise ValueError('Keyword for medication not valid.')
        filtered_files = self._keyword_search(filtered_files, [med])
    if hemisphere:
        matching_files = []
        for file in filtered_files:
            subject = mne_bids.get_entities_from_fname(file)['subject']
            if ((subject not in self.hemispheres) or (self.hemispheres[subject] is None)):
                raise HemisphereNotSpecifiedError(subject, self.hemispheres)
            hem = (self.hemispheres[subject] + '_')
            if ((hemisphere.lower() in 'ipsilateral') and (hem in file)):
                matching_files.append(file)
            if ((hemisphere.lower() in 'contralateral') and (hem not in file)):
                matching_files.append(file)
        filtered_files = matching_files
    self.files = filtered_files