Beispiel #1
0
def dailyfc_visual(files):

    for onefile in files:
        lfpdata, chnAreas, fs = lfp_extract([onefile])

        if lfpdata.shape[2] < 80:
            continue

        print(onefile)
        ciCOHs = calc_ciCOHs_rest(lfpdata)

        # permutation test: use the lfp data whose ciCOHs are the largest to get  distribution
        [i, j] = np.unravel_index(np.argmax(ciCOHs), shape=ciCOHs.shape)
        lfp1, lfp2 = lfpdata[i, :, :], lfpdata[j, :, :]
        _, mu, std = pval_permciCOH_rest(lfp1,
                                         lfp2,
                                         ciCOHs[i, j],
                                         shuffleN=1000)
        pvals = norm.sf(abs(ciCOHs), loc=mu, scale=std) * 2

        # multiple comparison correction, get weights
        reject, pval_corr = fdr_correction(pvals, alpha=0.05, method='indep')
        [rows, cols] = np.where(reject == True)
        weight = np.zeros(ciCOHs.shape)
        if len(rows) > 0:
            weight[rows, cols] = ciCOHs[rows, cols]

        # visual and save
        filename = os.path.basename(onefile)
        datestr = re.search('[0-9]{8}', filename).group()
        cond = re.search('_[a-z]*_[0-9]{8}', filename).group()[1:-9]
        freqstr = 'freq' + re.search('_filtered[0-9]*_[0-9]*',
                                     filename).group()[len('_filtered'):]

        save_prefix = 'all'
        saveFCGraph = os.path.join(
            savefolder,
            freqstr + '_' + cond + '_' + save_prefix + '_' + datestr + '.png')
        texts = dict()
        texts[cond + ',' + datestr] = [-80, 50, 15]
        weight_visual_save(weight,
                           chnInf=assign_coord2chnArea(
                               area_coord_file=area_coord_file,
                               chnAreas=chnAreas),
                           savefile=saveFCGraph,
                           texts=texts,
                           threds_edge=None)

        del texts, datestr, cond, weight
Beispiel #2
0
def subArea_dailyfc_visual(files):
    
    for onefile in files:
        lfpdata, chnAreas, fs = lfp_extract([onefile])

        if lfpdata.shape[2] < 80:
            continue


        print(onefile)
        ciCOHs = calc_ciCOHs_rest(lfpdata)




        # permutation test: use the lfp data whose ciCOHs are the largest to get  distribution
        [i, j] = np.unravel_index(np.argmax(ciCOHs), shape = ciCOHs.shape)
        lfp1, lfp2 = lfpdata[i, :, :], lfpdata[j, :, :]
        _, mu, std = pval_permciCOH_rest(lfp1, lfp2, ciCOHs[i, j], shuffleN = 1000)


        cond = re.search('_[a-z]*_[0-9]{8}', files[0]).group()[1:-9]
        datestr = re.search('[0-9]{8}', os.path.basename(onefile)).group()


        ### left thalamus and SMA/M1 ###
        save_prefix = 'leftThaCor_' 
        areas_used = ['lVA', 'lVLo/VPLo', 'lSMA', 'rSMA','M1']

        # subareas selection
        ciCOH_new, chnAreas_new = ciCOH_select(ciCOHs, chnAreas, areas_used)
        
        
        # multiple comparison correction, get weight matrix
        pvals = norm.sf(abs(ciCOH_new), loc = mu, scale = std) * 2
        reject, pval_corr = fdr_correction(pvals, alpha = 0.05, method='indep')
        [rows, cols]= np.where(reject == True)
        weight = np.zeros(ciCOH_new.shape)
        if len(rows) > 0:
            weight[rows, cols] = ciCOH_new[rows, cols]

        # visual and save
        saveFCGraph = os.path.join(savefolder, cond + '_' + save_prefix + '_' + datestr + '.png')
        texts = dict()
        texts[datestr] = [80, 50, 15]
        weight_visual_save(weight, chnInf = assign_coord2chnArea(area_coord_file, chnAreas_new), 
                            savefile = saveFCGraph, texts = None, threds_edge = None)
        del ciCOH_new, chnAreas_new, save_prefix, areas_used
        del saveFCGraph, weight
Beispiel #3
0
def pval_permciCOH_rest(lfp1, lfp2, actciCOH, shuffleN=1000):
    """
        

        Arg:
            lfp1, lfp2:  ntemp * nsegs(ntrials)

            shuffleN: the total shuffle times

            actciCOH: an actual ciCOH value (positive or negative)

        Return:
            pval: the p-value base on permutation test 
            mu, std: the mu and std of the fitted normal distribution
    """

    permlfp1, permlfp2 = lfp1.copy(), lfp2.copy()
    permciCOHs = np.zeros(shape=(shuffleN, ))
    for i in range(shuffleN):

        # shuffle permlfp2
        permlfp2 = np.transpose(permlfp2, axes=(1, 0))
        np.random.shuffle(permlfp2)
        permlfp2 = np.transpose(permlfp2, axes=(1, 0))

        permlfp = np.concatenate((np.expand_dims(
            permlfp1, axis=0), np.expand_dims(permlfp2, axis=0)),
                                 axis=0)

        ciCOHM = calc_ciCOHs_rest(permlfp)

        permciCOHs[i] = ciCOHM[0, 1]

        del ciCOHM, permlfp

    # Fit a normal distribution to the data:
    mu, std = norm.fit(permciCOHs)

    pval = norm.sf(abs(actciCOH), loc=mu, scale=std)

    return pval, mu, std
Beispiel #4
0
def segfc_visual(onefile):

    # lfpdata: nchns * ntemp * nsegs
    lfpdata, chnAreas, fs = lfp_extract([onefile])

    nchns, _, nsegs = lfpdata.shape
    seg_ciCOHs = np.zeros(shape=(nchns, nchns, nsegs))
    for segi in range(nsegs):
        seg_ciCOHs[:, :, segi] = calc_ciCOHs_rest(
            np.expand_dims(lfpdata[:, :, segi], axis=2))

    # permutation test: use the lfp data whose ciCOHs are the largest to get  distribution
    [i, j] = np.unravel_index(np.argmax(ciCOHs), shape=ciCOHs.shape)
    lfp1, lfp2 = lfpdata[i, :, :], lfpdata[j, :, :]
    _, mu, std = pval_permciCOH_rest(lfp1, lfp2, ciCOHs[i, j], shuffleN=1000)
    pvals = norm.sf(abs(ciCOHs), loc=mu, scale=std) * 2

    # multiple comparison correction, get weights
    reject, pval_corr = fdr_correction(pvals, alpha=0.05, method='indep')
    [rows, cols] = np.where(reject == True)
    weight = np.zeros(ciCOHs.shape)
    if len(rows) > 0:
        weight[rows, cols] = ciCOHs[rows, cols]

    # visual and save
    filename = os.path.basename(onefile)
    datestr = re.search('[0-9]{8}', filename).group()
    cond = re.search('_[a-z]*_[0-9]{8}', filename).group()[1:-9]

    save_prefix = 'all'
    saveFCGraph = os.path.join(
        savefolder, cond + '_' + save_prefix + '_' + datestr + '.png')
    weight_visual_save(weight,
                       chnInf=assign_coord2chnArea(
                           area_coord_file=area_coord_file, chnAreas=chnAreas),
                       savefile=saveFCGraph,
                       texts=None,
                       threds_edge=None)