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, out_path): """ Convert the clinical data of ADNI specified into the file clinical_specifications_adni.xlsx Args: clinical_data_dir: path to the clinical data directory out_path: path to the BIDS directory """ from os import path import os import pandas as pd import clinica.iotools.bids_utils as bids from clinica.utils.stream import cprint import clinica.iotools.converters.adni_to_bids.adni_utils as adni_utils clinic_specs_path = path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), 'data', 'clinical_specifications_adni.xlsx') try: os.path.exists(out_path) except IOError: print('BIDS folder not found.') raise bids_ids = bids.get_bids_subjs_list(out_path) bids_subjs_paths = bids.get_bids_subjs_paths(out_path) if not bids_ids: adni_merge_path = path.join(clinical_data_dir, 'ADNIMERGE.csv') adni_merge = pd.io.parsers.read_csv(adni_merge_path, sep=',') bids_ids = ['sub-ADNI' + subj.replace('_', '') for subj in list(adni_merge.PTID.unique())] bids_subjs_paths = [path.join(out_path, subj) for subj in bids_ids] # -- Creation of participant.tsv -- cprint("Creating participants.tsv...") participants_df = bids.create_participants_df('ADNI', clinic_specs_path, clinical_data_dir, bids_ids) # Replace the original values with the standard defined by the AramisTeam participants_df['sex'] = participants_df['sex'].replace('Male', 'M') participants_df['sex'] = participants_df['sex'].replace('Female', 'F') participants_df.to_csv(path.join(out_path, 'participants.tsv'), sep='\t', index=False, encoding='utf-8') # -- Creation of sessions.tsv -- cprint("Creating sessions files...") adni_utils.create_adni_sessions_dict(bids_ids, clinic_specs_path, clinical_data_dir, bids_subjs_paths) # -- Creation of scans files -- cprint('Creating scans files...') adni_utils.create_adni_scans_files(clinic_specs_path, bids_subjs_paths, bids_ids)
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)
def convert_clinical_data( self, clinical_data_dir: str, out_path: str, clinical_data_only: bool = False, subjects_list_path: Optional[str] = None, ): """Convert the clinical data of ADNI specified into the file clinical_specifications_adni.xlsx. Args: clinical_data_dir: path to the clinical data directory out_path: path to the BIDS directory """ import os from os import path import clinica.iotools.bids_utils as bids import clinica.iotools.converters.adni_to_bids.adni_utils as adni_utils from clinica.utils.stream import cprint clinic_specs_path = path.join( os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "data", "clinical_specifications_adni", ) try: os.path.exists(out_path) except IOError: print("BIDS folder not found.") raise conversion_path = path.join(out_path, "conversion_info") if clinical_data_only: bids_ids, bids_subjs_paths = get_bids_subjs_info( clinical_data_dir=clinical_data_dir, out_path=out_path, subjects_list_path=subjects_list_path, ) else: bids_ids = bids.get_bids_subjs_list(out_path) bids_subjs_paths = bids.get_bids_subjs_paths(out_path) # -- Creation of modality agnostic files -- cprint("Creating modality agnostic files...") bids.write_modality_agnostic_files("ADNI", out_path) # -- Creation of participant.tsv -- cprint("Creating participants.tsv...") participants_df = bids.create_participants_df( "ADNI", clinic_specs_path, clinical_data_dir, bids_ids ) # Replace the original values with the standard defined by the AramisTeam participants_df["sex"] = participants_df["sex"].replace("Male", "M") participants_df["sex"] = participants_df["sex"].replace("Female", "F") # Correction of diagnosis_sc for ADNI3 participants participants_df = adni_utils.correct_diagnosis_sc_adni3( clinical_data_dir, participants_df ) participants_df.to_csv( path.join(out_path, "participants.tsv"), sep="\t", index=False, encoding="utf-8", ) # -- Creation of sessions.tsv -- cprint("Creating sessions files...") adni_utils.create_adni_sessions_dict( bids_ids, clinic_specs_path, clinical_data_dir, bids_subjs_paths ) # -- Creation of scans files -- if os.path.exists(conversion_path): cprint("Creating scans files...") adni_utils.create_adni_scans_files(conversion_path, bids_subjs_paths)
def convert_clinical_data(self, clinical_data_dir, out_path): """Convert the clinical data of ADNI specified into the file clinical_specifications_adni.xlsx. Args: clinical_data_dir: path to the clinical data directory out_path: path to the BIDS directory """ import os from os import path import pandas as pd import clinica.iotools.bids_utils as bids import clinica.iotools.converters.adni_to_bids.adni_utils as adni_utils from clinica.utils.stream import cprint clinic_specs_path = path.join( os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "data", "clinical_specifications_adni.xlsx", ) try: os.path.exists(out_path) except IOError: print("BIDS folder not found.") raise bids_ids = bids.get_bids_subjs_list(out_path) bids_subjs_paths = bids.get_bids_subjs_paths(out_path) conversion_path = path.join(out_path, "conversion_info") if not bids_ids: adni_merge_path = path.join(clinical_data_dir, "ADNIMERGE.csv") adni_merge = pd.io.parsers.read_csv(adni_merge_path, sep=",") bids_ids = [ "sub-ADNI" + subj.replace("_", "") for subj in list(adni_merge.PTID.unique()) ] bids_subjs_paths = [path.join(out_path, subj) for subj in bids_ids] # -- Creation of modality agnostic files -- cprint("Creating modality agnostic files...") bids.write_modality_agnostic_files("ADNI", out_path) # -- Creation of participant.tsv -- cprint("Creating participants.tsv...") participants_df = bids.create_participants_df("ADNI", clinic_specs_path, clinical_data_dir, bids_ids) # Replace the original values with the standard defined by the AramisTeam participants_df["sex"] = participants_df["sex"].replace("Male", "M") participants_df["sex"] = participants_df["sex"].replace("Female", "F") # Correction of diagnosis_sc for ADNI3 participants participants_df = adni_utils.correct_diagnosis_sc_adni3( clinical_data_dir, participants_df) participants_df.to_csv( path.join(out_path, "participants.tsv"), sep="\t", index=False, encoding="utf-8", ) # -- Creation of sessions.tsv -- cprint("Creating sessions files...") adni_utils.create_adni_sessions_dict(bids_ids, clinic_specs_path, clinical_data_dir, bids_subjs_paths) # -- Creation of scans files -- cprint("Creating scans files...") adni_utils.create_adni_scans_files( conversion_path, bids_subjs_paths, )