Esempio n. 1
0
def main(template, subjectsdir, thresh = 0, run_eta = False):
    tdat = ni.load(template).get_data().squeeze()

    _, tname = os.path.split(template)
    tname = tname.split('.')[0]
    subfiles = get_subjects_files(subjectsdir)
    allresults = []
    for sf in subfiles:
        pth, nme = os.path.split(sf)
        nme = nme.split('.')[0]
        tmpdat = ni.load(sf).get_data().squeeze()
        if not tmpdat.shape == tdat.shape:
            raise IndexError('shape mismatch: '+\
                             'template:%s, data: %s'%(tdat.shape, 
                                                      tmpdat.shape))
        mask = tmpdat > 0
        maskd_template = tdat.copy()
        maskd_template[tdat <=thresh] = 0
        maskd_template[tdat > thresh] = 1
        gof = matching.calc_gof(tmpdat, maskd_template, mask)
        res = [nme, gof]
        print res
        if run_eta:
            eta = matching.calc_eta(tmpdat[mask], tdat[mask])
            res.append(eta)
        allresults.append(res)
    columns = ['name', 'gof']
    if run_eta:
        columns.append('eta')
    df = pandas.DataFrame(allresults, columns = columns)
    outf = os.path.join(subjectsdir, 'matching_%s_data.xls'%(tname))
    df.to_excel(outf)
    print 'wrote %s'%(outf)
Esempio n. 2
0
    for i in range(t):
        for j in metrics:
            level_tuples.append((str(i),j))
    row_index = pandas.MultiIndex.from_tuples(level_tuples, 
                                names=['Component', 'Metric']) #Level1 and Level2 names

    #Create empty dataframe to hold metric scores
    matchframe = pandas.DataFrame(index=row_index, columns=template_map.values())

    #Calculate matching metrics of all components with template networks  
    for cmpnt in range(t):  #Loop over all components in 4d ICA file
        icavol = icadat[:,:,:,cmpnt]

        for net in template_map.keys(): #Loop over all networks in 4d template
            tempvol = tempdat[:,:,:,(net - 1)]
            tempname = template_map[net]
            gof = matching.calc_gof(icavol, #Calc goodness of fit (Greicius 2004)
                                    tempvol,
                                    maskdat)
            (eta, (pear_r, pear_p)) = matching.calc_eta(icavol, #Calc Cohen's eta
                                                    tempvol, 
                                                    getr=True)
            matchframe.ix[str(cmpnt),'gof'][tempname] = gof
            matchframe.ix[str(cmpnt),'eta'][tempname] = eta
            matchframe.ix[str(cmpnt),'pear_r'][tempname] = pear_r
            matchframe.ix[str(cmpnt),'pear_p'][tempname] = pear_p

    saveout = os.path.join(outdir, outfile)
    matchframe.to_csv(saveout, header=True, index=True)   #Save to file