Пример #1
0
import io_meld as io
import os

#parse commandline arguments pointing to subject_dir etc
parser = argparse.ArgumentParser(description='filter intrinsic curvature')
parser.add_argument('subject_dir', type=str, help='path to subject dir')
parser.add_argument('subject_ids',
                    type=str,
                    help='textfile containing list of subject ids')

args = parser.parse_args()

#save subjects dir and subject ids. import the text file containing subject ids
subject_dir = args.subject_dir
subject_ids_filename = args.subject_ids
subject_ids = np.loadtxt(subject_dir + subject_ids_filename, dtype='str')

hemis = ['lh', 'rh']

for h in hemis:
    for s in subject_ids:
        if not os.path.isfile(subject_dir + s + '/xhemi/surf_meld/' + h +
                              '.pial.K_filtered.mgh'):
            demo = nb.load(subject_dir + s + '/surf_meld/' + h + '.pial.K.mgh')
            curvature = io.load_mgh(subject_dir + s + '/surf_meld/' + h +
                                    '.pial.K.mgh')
            curvature = np.absolute(curvature)
            io.save_mgh(
                subject_dir + s + '/surf_meld/' + h + '.pial.K_filtered.mgh',
                curvature, demo)
Пример #2
0
#save subjects dir and subject ids. import the text file containing subject ids
subject_dir=args.subject_dir
subject_ids_filename=args.subject_ids
subject_ids=np.loadtxt(subject_dir+subject_ids_filename, dtype='str')

measures=['.thickness_z_on_lh.sm10.mgh', '.asym.thickness_z.sm10.mgh',
    '.w-g.pct_z_on_lh.sm10.mgh','.asym.w-g.pct_z.sm10.mgh',
    '.pial.K_filtered_2_z_on_lh.sm20.mgh','.asym.pial.K_filtered_2_z.sm20.mgh',
        '.curv_on_lh.mgh','.sulc_on_lh.mgh',
    '.gm_FLAIR_0.75_z_on_lh.sm10.mgh','.gm_FLAIR_0.5_z_on_lh.sm10.mgh',
    '.gm_FLAIR_0.25_z_on_lh.sm10.mgh','.gm_FLAIR_0_z_on_lh.sm10.mgh',
    '.wm_FLAIR_0.5_z_on_lh.sm10.mgh','.wm_FLAIR_1_z_on_lh.sm10.mgh',
    '.asym.gm_FLAIR_0.75_z.sm10.mgh','.asym.gm_FLAIR_0.5_z.sm10.mgh',
    '.asym.gm_FLAIR_0.25_z.sm10.mgh','.asym.gm_FLAIR_0_z.sm10.mgh',
'.asym.wm_FLAIR_0.5_z.sm10.mgh','.asym.wm_FLAIR_1_z.sm10.mgh']

hemis=['lh','rh']
demo=nb.load(subject_dir+subject_ids[0]+'/xhemi/surf/'+hemis[0]+measures[0])

for h in hemis:
    for m in measures:
        control_mu=io.load_mgh('template_control/'+h+'.mu'+m)
        control_std=io.load_mgh('template_control/'+h+'.std'+m)
        for s in subject_ids:
            subject_measure=io.load_mgh(subject_dir+s+'/xhemi/surf/'+h+m)
            z_measure=(subject_measure-control_mu)/control_std)
            io.save_mgh(subject_dir+s+'/xhemi/surf/'+h+'inter_z.'+m,z_measure,demo)


Пример #3
0
    elif '15T' in fs_id:
        f='15T'
    if os.path.isfile(subject_dir + fs_id + '/xhemi/surf_meld/lh.on_lh.intra_z.gm_FLAIR_0.75.sm10.mgh'):
        measures=['.on_lh.intra_z.thickness.sm10.mgh', '.asym.on_lh.intra_z.thickness.sm10.mgh',
              '.on_lh.intra_z.w-g.pct.sm10.mgh','.asym.on_lh.intra_z.w-g.pct.sm10.mgh',
              '.on_lh.intra_z.pial.K_filtered.sm20.mgh','.asym.on_lh.intra_z.pial.K_filtered.sm20.mgh',
              '.on_lh.curv.mgh','.on_lh.sulc.mgh',
              '.asym.on_lh.curv.mgh','.asym.on_lh.sulc.mgh',
              '.on_lh.intra_z.gm_FLAIR_0.75.sm10.mgh','.on_lh.intra_z.gm_FLAIR_0.5.sm10.mgh',
              '.on_lh.intra_z.gm_FLAIR_0.25.sm10.mgh','.on_lh.intra_z.gm_FLAIR_0.sm10.mgh',
              '.on_lh.intra_z.wm_FLAIR_0.5.sm10.mgh','.on_lh.intra_z.wm_FLAIR_1.sm10.mgh',
              '.asym.on_lh.intra_z.gm_FLAIR_0.75.sm10.mgh','.asym.on_lh.intra_z.gm_FLAIR_0.5.sm10.mgh',
              '.asym.on_lh.intra_z.gm_FLAIR_0.25.sm10.mgh','.asym.on_lh.intra_z.gm_FLAIR_0.sm10.mgh',
              '.asym.on_lh.intra_z.wm_FLAIR_0.5.sm10.mgh','.asym.on_lh.intra_z.wm_FLAIR_1.sm10.mgh']
    else:
        measures=['.on_lh.intra_z.thickness.sm10.mgh', '.asym.on_lh.intra_z.thickness.sm10.mgh',
              '.on_lh.intra_z.w-g.pct.sm10.mgh','.asym.on_lh.intra_z.w-g.pct.sm10.mgh',
              '.on_lh.intra_z.pial.K_filtered.sm20.mgh','.asym.on_lh.intra_z.pial.K_filtered.sm20.mgh',
              '.on_lh.curv.mgh','.on_lh.sulc.mgh',
                  '.asym.on_lh.curv.mgh','.asym.on_lh.sulc.mgh']
    demo=nb.load(subject_dir+fs_id+'/xhemi/surf_meld/'+hemis[0]+measures[0])
    for h in hemis:
        for m in measures:
            control_mu=io.load_mgh(os.path.join(control_dir,f,h+'.mu'+m))
            control_std=io.load_mgh(os.path.join(control_dir,f,h+'.std'+m))
            subject_measure=io.load_mgh(subject_dir+fs_id+'/xhemi/surf_meld/'+h+m)
            z_measure=np.divide((subject_measure-control_mu),control_std,out=np.zeros_like(subject_measure), where=control_std!=0)
            io.save_mgh(subject_dir+fs_id+'/xhemi/surf_meld/'+h+'.inter_z'+m,z_measure,demo)


hemis = ['lh', 'rh']
demo = nb.load(
    os.path.join(subject_dir, subject_ids[0], 'surf_meld',
                 hemis[0] + measures[0]))

for h in hemis:
    for s in subject_ids:
        demo = nb.load(
            os.path.join(subject_dir, s, 'surf_meld', h + measures[0]))
        cortex = nb.freesurfer.io.read_label(
            os.path.join(subject_dir, s, 'label', h + '.cortex.label'))
        for m in measures:
            if not os.path.isfile(
                    os.path.join(subject_dir, s, 'surf_meld',
                                 h + '.intra_z' + m)):
                subject_measure = io.load_mgh(
                    os.path.join(subject_dir, s, 'surf_meld', h + m))
                z_measure = (subject_measure - np.mean(
                    subject_measure[cortex])) / np.std(subject_measure[cortex])
                io.save_mgh(
                    os.path.join(subject_dir, s, 'surf_meld',
                                 h + '.intra_z' + m), z_measure, demo)
        #only do FLAIR measures if present
        if os.path.isfile(
                os.path.join(subject_dir, s, 'surf_meld',
                             h + flair_measures[0])):
            for m in flair_measures:
                if not os.path.isfile(
                        os.path.join(subject_dir, s, 'surf_meld',
                                     h + '.intra_z' + m)):
                    subject_measure = io.load_mgh(
                        os.path.join(subject_dir, s, 'surf_meld', h + m))
args = parser.parse_args()

#save subjects dir and subject ids. import the text file containing subject ids
subject_dir = args.subject_dir
subject_ids_filename = args.subject_ids
subject_ids = np.loadtxt(subject_dir + subject_ids_filename, dtype='str')

measures = [
    '.thickness.sm10.mgh', '.w-g.pct.sm10.mgh', '.pial.K_filtered_2.sm20.mgh',
    '.gm_FLAIR_0.sm10.mgh', '.gm_FLAIR_0.25.sm10.mgh',
    '.gm_FLAIR_0.5.sm10.mgh', '.gm_FLAIR_0.75.sm10.mgh',
    '.wm_FLAIR_0.5.sm10.mgh', '.wm_FLAIR_1.sm10.mgh'
]
hemis = ['lh', 'rh']
demo = nb.load(subject_dir + subject_ids[0] + '/xhemi/surf/' + hemis[0] +
               measures[0])

for h in hemis:
    for s in subject_ids:
        demo = nb.load(subject_dir + s + '/surf/' + h + measures[0])
        cortex = cortex_label = nb.freesurfer.io.read_label(subject_dir + s +
                                                            '/label/' + h +
                                                            '.label')
        for m in measures:
            subject_measure = io.load_mgh(subject_dir + s + '/xhemi/surf/' +
                                          h + m)
            z_measure = (subject_measure - np.mean(
                subject_measure[cortex])) / np.std(subject_measure[cortex])
            io.save_mgh(subject_dir + s + '/xhemi/surf/' + h + 'intra_z.' + m,
                        z_measure, demo)