def convert_clinical_data(self, clinical_data_dir, bids_dir): """ Convert the clinical data defined inside the clinical_specifications.xlx into BIDS Args: clinical_data_dir: path to the folder with the original clinical data bids_dir: path to the bids directory """ import clinica.iotools.bids_utils as bids from os import path import os import numpy as np print('Converting clinical data...') bids_ids = bids.get_bids_subjs_list(bids_dir) iotools_folder = os.path.dirname( os.path.dirname(os.path.dirname(__file__))) clinic_specs_path = path.join(iotools_folder, 'data', 'clinical_specifications.xlsx') # --Create participants.tsv-- participants_df = bids.create_participants_df('OASIS', clinic_specs_path, clinical_data_dir, bids_ids) # Replace the values of the diagnosis_bl column participants_df['diagnosis_bl'].replace([0.0, np.nan], 'CN', inplace=True) participants_df['diagnosis_bl'].replace([0.5, 1.0, 1.5, 2.0], 'AD', inplace=True) # Following line has no sense # participants_df['diagnosis_bl'].replace(participants_df['diagnosis_bl']>0.0, 'AD', inplace=True) participants_df.to_csv(path.join(bids_dir, 'participants.tsv'), sep='\t', index=False, encoding='utf-8') # --Create sessions files-- sessions_dict = bids.create_sessions_dict(clinical_data_dir, 'OASIS', clinic_specs_path, bids_ids, 'ID') for y in bids_ids: if sessions_dict[y]['M00']['diagnosis'] > 0: sessions_dict[y]['M00']['diagnosis'] = 'AD' else: sessions_dict[y]['M00']['diagnosis'] = 'CN' bids.write_sessions_tsv(bids_dir, sessions_dict) # --Create scans files-- # Note: We have no scans information for OASIS scans_dict = bids.create_scans_dict(clinical_data_dir, 'OASIS', clinic_specs_path, bids_ids, 'ID') bids.write_scans_tsv(bids_dir, bids_ids, scans_dict)
def convert_clinical_data(self, clinical_data_dir, bids_dir): """Convert the clinical data defined inside the clinical_specifications.xlx into BIDS. Args: clinical_data_dir: path to the folder with the original clinical data bids_dir: path to the BIDS directory """ import os from os import path import numpy as np import clinica.iotools.bids_utils as bids from clinica.utils.stream import cprint cprint("Converting clinical data...") bids_ids = bids.get_bids_subjs_list(bids_dir) iotools_folder = os.path.dirname( os.path.dirname(os.path.dirname(__file__))) clinic_specs_path = path.join(iotools_folder, "data", "clinical_specifications") # -- Creation of modality agnostic files -- bids.write_modality_agnostic_files("OASIS-1", bids_dir) # --Create participants.tsv-- participants_df = bids.create_participants_df("OASIS", clinic_specs_path, clinical_data_dir, bids_ids) # Replace the values of the diagnosis_bl column participants_df["diagnosis_bl"].replace([0.0, np.nan], "CN", inplace=True) participants_df["diagnosis_bl"].replace([0.5, 1.0, 1.5, 2.0], "AD", inplace=True) # Following line has no sense # participants_df['diagnosis_bl'].replace(participants_df['diagnosis_bl']>0.0, 'AD', inplace=True) participants_df = participants_df.fillna("n/a") participants_df.to_csv( path.join(bids_dir, "participants.tsv"), sep="\t", index=False, encoding="utf-8", ) # --Create sessions files-- sessions_dict = bids.create_sessions_dict_OASIS( clinical_data_dir, bids_dir, "OASIS", clinic_specs_path, bids_ids, "ID") for y in bids_ids: if sessions_dict[y]["M00"]["diagnosis"] > 0: sessions_dict[y]["M00"]["diagnosis"] = "AD" else: sessions_dict[y]["M00"]["diagnosis"] = "CN" bids.write_sessions_tsv(bids_dir, sessions_dict) # --Create scans files-- # Note: We have no scans information for OASIS scans_dict = bids.create_scans_dict( clinical_data_dir, "OASIS", clinic_specs_path, bids_ids, "ID", "", sessions_dict, ) bids.write_scans_tsv(bids_dir, bids_ids, scans_dict)