def getTwoFrameKSStatByRegion(region, all_bin_frame, strong_bin_frame):
    best_stim = rc.getBestStimFromRegion(strong_bin_frame, region)
    all_bin_stim_frame = all_bin_frame[(all_bin_frame.stim_id == best_stim)
                                       & (all_bin_frame.region == region)]
    strong_bin_stim_frame = strong_bin_frame[
        (strong_bin_frame.stim_id == best_stim)
        & (strong_bin_frame.region == region)]
    corr_stat, corr_p_val = ks_2samp(all_bin_stim_frame.corr_coef,
                                     strong_bin_stim_frame.corr_coef)
    info_stat, info_p_val = ks_2samp(all_bin_stim_frame.mutual_info_qe,
                                     strong_bin_stim_frame.mutual_info_qe)
    return region, corr_stat, corr_p_val, info_stat, info_p_val
def getRegionToSampleDict(correlation_frame, bin_width, measure):
    region_to_sample = {}
    for region in rc.regions:
        best_stim = rc.getBestStimFromRegion(correlation_frame, region)
        region_bin_frame = correlation_frame[
            (correlation_frame.region == region)
            & (correlation_frame.bin_width == bin_width) &
            (correlation_frame.stim_id == best_stim)]
        print(dt.datetime.now().isoformat() + ' INFO: ' + 'Mean ' + measure +
              ' = ' + str(region_bin_frame[measure].mean()))
        print(dt.datetime.now().isoformat() + ' INFO: ' + 'Median ' + measure +
              ' = ' + str(region_bin_frame[measure].median()))
        region_to_sample[region] = region_bin_frame.loc[:, measure]
    return region_to_sample
Пример #3
0
def main():
    print(dt.datetime.now().isoformat() + ' INFO: ' +
          'Starting main function...')
    print(dt.datetime.now().isoformat() + ' INFO: ' +
          'Loading single and pairwise measurements...')
    firing_frame, pairwise_frame = getDataFrames(args.single_file,
                                                 args.paired_file,
                                                 args.bin_width)
    if args.plot_type == 'firing':
        for region in rc.regions:
            best_stim = rc.getBestStimFromRegion(firing_frame, region)
            firing_region_frame = firing_frame[
                (firing_frame.region == region)
                & (firing_frame.stim_id == best_stim)]
            pairwise_region_frame = pairwise_frame[
                (pairwise_frame.region == region)
                & (pairwise_frame.stim_id == best_stim)]
            working_frame = getWorkingFrame(firing_region_frame,
                                            pairwise_region_frame)
            working_frame.loc[:, 'geometric_mean'] = np.sqrt(
                working_frame.first_firing_rate *
                working_frame.second_firing_rate)
            plotMeasuresVsGeomMean(working_frame, region, best_stim,
                                   args.prefix)
    elif args.plot_type == 'pairwise':
        max_mi = pairwise_frame.mutual_info_qe.max()
        for region in rc.regions:
            best_stim = rc.getBestStimFromRegion(pairwise_frame, region)
            pairwise_region_frame = pairwise_frame[
                (pairwise_frame.region == region)
                & (pairwise_frame.stim_id == best_stim)]
            plotInfoVsCorr(pairwise_region_frame, region, max_mi, best_stim,
                           args.prefix)
    else:
        sys.exit(dt.datetime.now().isoformat() + 'ERROR: ' +
                 'Unrecognised measure type!')
    print(dt.datetime.now().isoformat() + ' INFO: ' + 'Done.')
Пример #4
0
def main():
    print(dt.datetime.now().isoformat() + ' INFO: ' +
          'Starting main function...')
    print(dt.datetime.now().isoformat() + ' INFO: ' +
          'Loading all_regions_stims_pairs_widths.csv...')
    correlation_frame = pd.read_csv(os.path.join(csv_dir, args.filename))
    if args.correlation_type == 'spike_count':
        for region in rc.regions:
            best_stim = rc.getBestStimFromRegion(correlation_frame, region)
            plotAbsCorrCoefByBinWidthForRegionStim(correlation_frame, region,
                                                   best_stim,
                                                   args.image_file_prefix,
                                                   args.x_axis_scale)
    elif args.correlation_type == 'signal':
        for region in rc.regions:
            plotAbsSignalCorrByBinWidth(correlation_frame, region,
                                        args.image_file_prefix,
                                        args.x_axis_scale)
    elif args.correlation_type == 'bifurcation':
        for region in rc.regions:
            best_stim = rc.getBestStimFromRegion(correlation_frame, region)
            plotBifurcatedCorrelationsByBinWidth(correlation_frame, region,
                                                 best_stim,
                                                 args.image_file_prefix,
                                                 args.x_axis_scale)
    elif args.correlation_type == 'mutual_info':
        plotMutualInfoByBinWidth(correlation_frame, args.image_file_prefix,
                                 args.x_axis_scale)
    elif args.correlation_type == 'firing_rate':
        plotFiringRateByBinWidth(correlation_frame, args.image_file_prefix)
    elif args.correlation_type == 'symm_unc':
        for region in rc.regions:
            plotSymmUncByBinWidth(correlation_frame, region,
                                  args.image_file_prefix, args.x_axis_scale)
    else:
        sys.exit(dt.datetime.now().isoformat() + ' ERROR: ' +
                 'Unrecognised correlation type.')
Пример #5
0
def plotSymmUncByBinWidth(correlation_frame, region, prefix, x_axis_scale):
    best_stim = rc.getBestStimFromRegion(correlation_frame, region)
    region_stim_frame = correlation_frame[
        (correlation_frame.region == region)
        & (correlation_frame.stim_id == best_stim)]
    plotColumnByBinWidth(region_stim_frame,
                         'symm_unc_qe',
                         region,
                         x_axis_scale,
                         r'$U(X;Y)$ (a.u.)',
                         y_lim=[0, 1])
    filename = prefix + 'symm_unc_by_bin_width_' + region + '_' + str(
        best_stim) + '.png'
    print(dt.datetime.now().isoformat() + ' INFO: ' + 'Saving ' + filename +
          '...')
    plt.savefig(
        os.path.join(image_dir, 'symm_unc_vs_bin_width', x_axis_scale,
                     filename))
    plt.close()
Пример #6
0
def plotFiringRateByBinWidth(firing_frame, prefix):
    y_lim = [0, firing_frame.firing_rate_mean.max()]
    for region in rc.regions:
        best_stim = rc.getBestStimFromRegion(firing_frame, region)
        region_stim_frame = firing_frame[(firing_frame.region == region)
                                         & (firing_frame.stim_id == best_stim)]
        plotColumnByBinWidth(region_stim_frame,
                             'firing_rate_mean',
                             region,
                             'linear',
                             'Firing Rate (Hz)',
                             y_lim=y_lim)
        filename = prefix + 'firing_rate_by_bin_width_' + region + '_' + str(
            best_stim) + '.png'
        print(dt.datetime.now().isoformat() + ' INFO: ' + 'Saving ' +
              filename + '...')
        plt.savefig(
            os.path.join(image_dir, 'firing_rate_vs_bin_width', filename))
        plt.close()
def getBestStimsLims(corr_bin_frame,
                     strong_corr_bin_frame,
                     measure,
                     hist_range=None):
    hist_range = [0, corr_bin_frame[measure].max()
                  ] if hist_range == None else hist_range
    best_stims = np.zeros(len(rc.regions), dtype=int)
    top_count = 0
    max_bin = 0
    for i, region in enumerate(rc.regions):
        best_stims[i] = rc.getBestStimFromRegion(strong_corr_bin_frame, region)
        corr_region_bin_stim = corr_bin_frame[
            (corr_bin_frame.stim_id == best_stims[i])
            & (corr_bin_frame.region == region)]
        counts, bins = np.histogram(corr_region_bin_stim[measure],
                                    bins=25,
                                    range=hist_range)
        top_count = np.max([top_count, counts.max()])
        max_bin = np.max([max_bin, bins[-1]])
    return best_stims, [0, 10 * np.ceil(top_count / 10).astype(int)], max_bin
Пример #8
0
def plotMutualInfoByBinWidth(correlation_frame, prefix, x_axis_scale):
    y_lim = [0, correlation_frame.mutual_info_qe.max()]
    for region in rc.regions:
        best_stim = rc.getBestStimFromRegion(correlation_frame, region)
        region_stim_frame = correlation_frame[
            (correlation_frame.region == region)
            & (correlation_frame.stim_id == best_stim)]
        plotColumnByBinWidth(region_stim_frame,
                             'mutual_info_qe',
                             region,
                             x_axis_scale,
                             r'$I(X;Y)$ (bits)',
                             y_lim=y_lim)
        filename = prefix + 'mutual_info_by_bin_width_' + region + '_' + str(
            best_stim) + '.png'
        print(dt.datetime.now().isoformat() + ' INFO: ' + 'Saving ' +
              filename + '...')
        plt.savefig(
            os.path.join(image_dir, 'mutual_info_vs_bin_width', x_axis_scale,
                         filename))
        plt.close()
def main():
    print(dt.datetime.now().isoformat() + ' INFO: ' +
          'Starting main function...')
    print(dt.datetime.now().isoformat() + ' INFO: ' +
          'Loading data from disc...')
    corr_bin_frame = getCorrFrame(args.filename, args.bin_width)
    strong_corr_bin_frame = getCorrFrame(args.strong_filename, args.bin_width)
    if args.measure_type == 'pairwise':
        corr_best_stims, corr_y_lim, corr_max_bin = getBestStimsLims(
            corr_bin_frame, strong_corr_bin_frame, 'corr_coef', [-1, 1])
        plotRegionalCorrelationHistograms(corr_bin_frame, corr_best_stims,
                                          corr_y_lim, args.use_title,
                                          args.prefix, args.bin_width)
        info_best_stims, info_y_lim, info_max_bin = getBestStimsLims(
            corr_bin_frame, strong_corr_bin_frame, 'mutual_info_qe')
        plotRegionalInformationHistograms(corr_bin_frame, info_best_stims,
                                          info_y_lim, info_max_bin,
                                          args.use_title, args.prefix,
                                          args.bin_width)
        symm_best_stims, symm_y_lim, symm_max_bin = getBestStimsLims(
            corr_bin_frame, strong_corr_bin_frame, 'symm_unc_qe', [0, 1])
        plotRegionalSymmUncHistograms(corr_bin_frame, symm_best_stims,
                                      symm_y_lim, args.use_title, args.prefix,
                                      args.bin_width)
    elif args.measure_type == 'single':
        firing_best_stims, firing_y_lim, firing_max_bin = getBestStimsLims(
            corr_bin_frame, strong_corr_bin_frame, 'firing_rate_mean')
        plotRegionalFiringRateHistograms(corr_bin_frame, firing_best_stims,
                                         firing_y_lim, firing_max_bin,
                                         args.use_title, args.prefix,
                                         args.bin_width)
    elif args.measure_type == 'correction':
        for region in rc.regions:
            best_stim = rc.getBestStimFromRegion(correlation_frame, region)
            plotCorrections(correlation_frame, region, best_stim,
                            args.bin_width, args.prefix)
    else:
        sys.exit(dt.datetime.now().isoformat() + 'ERROR: ' +
                 'Unrecognised measure type!')
    print(dt.datetime.now().isoformat() + ' INFO: ' + 'Done.')
pd.set_option('max_rows', 30)

def getDataFrames(single_file, paired_file, bin_width):
    firing_frame = pd.read_csv(os.path.join(csv_dir, args.single_file), usecols=lambda x: x != 'Unnamed: 0')
    pairwise_frame = pd.read_csv(os.path.join(csv_dir, args.paired_file), usecols=lambda x: x != 'Unnamed: 0')
    firing_frame = firing_frame[firing_frame.bin_width == bin_width]
    pairwise_frame = pairwise_frame[pairwise_frame.bin_width == bin_width]
    return firing_frame, pairwise_frame

pair = np.array(args.pair)
cell_info, id_adjustor = rc.loadCellInfo(csv_dir)
stim_info = loadmat(os.path.join(mat_dir, 'experiment2stimInfo.mat'))
firing_frame, pairwise_frame = getDataFrames(args.single_file, args.paired_file, args.bin_width)
region = firing_frame.loc[firing_frame.cell_id == pair[0]].region.unique()[0]
best_stim = rc.getBestStimFromRegion(pairwise_frame, region)
pairwise_region_frame = pairwise_frame[(pairwise_frame.region == region) & (pairwise_frame.stim_id == best_stim)]
stim_firing_frame = firing_frame.loc[firing_frame.stim_id == best_stim,:]
trials_info = rc.getStimTimesIds(stim_info, best_stim)
spike_time_dict = rc.loadSpikeTimes(posterior_dir, frontal_dir, pair, id_adjustor)
exp_frame = rc.getExperimentFrame(pair, trials_info, spike_time_dict, cell_info, 1.0)

corr = pairwise_region_frame.loc[(pairwise_region_frame.first_cell_id == pair[0]) & (pairwise_region_frame.second_cell_id == pair[1]), 'corr_coef'].iloc[0]
info = pairwise_region_frame.loc[(pairwise_region_frame.first_cell_id == pair[0]) & (pairwise_region_frame.second_cell_id == pair[1]), 'mutual_info_qe'].iloc[0]
first_firing_rate = stim_firing_frame.loc[firing_frame.cell_id == pair[0], 'firing_rate_mean'].iloc[0]
second_firing_rate = stim_firing_frame.loc[firing_frame.cell_id == pair[1], 'firing_rate_mean'].iloc[0]
geom_mean_firing_rate = np.sqrt(first_firing_rate * second_firing_rate)
first_responses = exp_frame.loc[exp_frame.cell_id == pair[0], 'num_spikes']
second_responses = exp_frame.loc[exp_frame.cell_id == pair[1], 'num_spikes']

plt.figure(figsize=(10,5))