Пример #1
0
    def load_candidates_from_bids(self):
        """
        Loads the list of candidates from the BIDS study. List of
        participants and their information will be stored in participants_info.

        :return: list of dictionaries with participant information from BIDS
         :rtype: list
        """

        if self.verbose:
            print('Grepping candidates from the BIDS layout...')

        # grep the participant.tsv file and parse it
        participants_info = None
        for file in self.bids_layout.get(suffix='participants',
                                         return_type='filename'):
            # note file[0] returns the path to participants.tsv
            if 'participants.tsv' in file:
                participants_info = utilities.read_tsv_file(file)
            else:
                continue

        self.candidates_list_validation(participants_info)

        if self.verbose:
            print('\t=> List of participants found:')
            for participant in participants_info:
                print('\t\t' + participant['participant_id'])
            print('\n')

        return participants_info
Пример #2
0
    def __init__(self, scans_tsv_file, acquisition_file, verbose):
        """
        Constructor method for the ScansTSV class

        :param scans_tsv_file  : path to the BIDS sub-XXX_scans.tsv file
         :type scans_tsv_file  : str
        :param acquisition_file: path to the acquisition file (.nii, .set, .edf...)
         :type acquisition_file: str
        """

        self.verbose = verbose

        # store files' paths
        self.scans_tsv_file = scans_tsv_file
        self.acquisition_file = acquisition_file

        # read the TSV file and store the header names and data
        self.tsv_entries = utilities.read_tsv_file(self.scans_tsv_file)
        self.tsv_headers = self.tsv_entries[0]

        # get the acquisition information for the acquisition file
        self.acquisition_data = self.find_acquisition_data()
Пример #3
0
    def fetch_and_insert_event_file(self,
                                    physiological_file_id,
                                    derivatives=None):
        """
        Gather raw channel file information to insert into
        physiological_task_event. Once all the information has been gathered,
        it will call Physiological.insert_event_file that will perform the
        insertion into physiological_task_event, linking it to the
        PhysiologicalFileID already registered.

        :param physiological_file_id: PhysiologicalFileID of the associated
                                      physiological file already inserted into
                                      the physiological_file table
         :type physiological_file_id: int
        :param derivatives: dictionary with derivative folder information if
                            the event file to insert is a derivative file.
                            Set by default to None when inserting raw file.
         :type derivatives: dict

        :return: channel file path in the /DATA_DIR/bids_import directory
         :rtype: str
        """

        # load the Physiological object that will be used to insert the
        # physiological data into the database
        physiological = Physiological(self.db, self.verbose)

        # check if inserting derivatives to use the derivative_pattern to
        # grep for the eeg file
        derivative_pattern = None
        derivative_path = None
        if derivatives:
            derivative_pattern = derivatives['derivative_name'] + "/sub-"
            derivative_path = self.get_derivatives_path(derivatives)

        event_file = BidsReader.grep_file(
            files_list=self.events_files,
            match_pattern='events.tsv',
            derivative_pattern=derivative_pattern)

        if not event_file:
            message = "WARNING: no events file associated with " \
                      "physiological file ID " + str(physiological_file_id)
            print(message)
            return None
        else:
            result = physiological.grep_event_from_physiological_file_id(
                physiological_file_id)
            event_path = result[0]['FilePath'] if result else None
            event_data = utilities.read_tsv_file(event_file)
            if not result:
                # copy the event file to the LORIS BIDS import directory
                event_path = self.copy_file_to_loris_bids_dir(
                    event_file, derivative_path)
                # get the blake2b hash of the task events file
                blake2 = blake2b(event_file.encode('utf-8')).hexdigest()
                # insert event data in the database
                physiological.insert_event_file(event_data, event_path,
                                                physiological_file_id, blake2)

        return event_path