Beispiel #1
0
    def processGLMStats(self, trial_FR, trials, welltrain_window=[],correct_resp=[]):

        ### TODO: when variables are empty
        
        FR_scale=np.concatenate((trial_FR[:,(trials[:,5]==3) & welltrain_window & correct_resp ,:][self.row_sel_3,:,:],
        trial_FR[:,(trials[:,5]==6) & welltrain_window & correct_resp,:][self.row_sel_6,:,:]),axis=1)
        
        trial_perf_sel=np.concatenate((trials[(trials[:,5]==3) & welltrain_window & correct_resp,:],
                                       trials[(trials[:,5]==6) & welltrain_window & correct_resp,:]),axis=0)
        
        # S1=4 S2=8 T1=8 T2 =4
        trial_S1T1 = (trial_perf_sel[:, 2] == 4) & (trial_perf_sel[:, 3] == 8)
        trial_S1T2 = (trial_perf_sel[:, 2] == 4) & (trial_perf_sel[:, 3] == 4)
        trial_S2T1 = (trial_perf_sel[:, 2] == 8) & (trial_perf_sel[:, 3] == 8)
        trial_S2T2 = (trial_perf_sel[:, 2] == 8) & (trial_perf_sel[:, 3] == 4)
 
        self.S1T1=np.zeros((56,trial_FR.shape[2]))
        self.S1T2=np.zeros((56,trial_FR.shape[2]))
        self.S2T1=np.zeros((56,trial_FR.shape[2]))
        self.S2T2=np.zeros((56,trial_FR.shape[2]))
        
        
        for su_idx in range(trial_FR.shape[2]):
            onesu = np.squeeze(FR_scale[:, :, su_idx]).T

            (base_mean, base_std) = baselineVector(onesu)
            
            onesu=(onesu-base_mean)/base_std
            self.S1T1[:,su_idx] = np.mean(onesu[trial_S1T1,:],axis=0)
            self.S1T2[:,su_idx] = np.mean(onesu[trial_S1T2,:],axis=0)
            self.S2T1[:,su_idx] = np.mean(onesu[trial_S2T1,:],axis=0)
            self.S2T2[:,su_idx] = np.mean(onesu[trial_S2T2,:],axis=0)
Beispiel #2
0
    def addPairSelect(self, trial_FR, trial_sel):

        trial_sel_left_3 = np.logical_and(
            trial_sel[:, 2] != trial_sel[:, 3], trial_sel[:, 5] == 3
        )
        trial_sel_right_3 = np.logical_and(
            trial_sel[:, 2] == trial_sel[:, 3], trial_sel[:, 5] == 3
        )

        trial_sel_left_6 = np.logical_and(
            trial_sel[:, 2] != trial_sel[:, 3], trial_sel[:, 5] == 6
        )
        trial_sel_right_6 = np.logical_and(
            trial_sel[:, 2] == trial_sel[:, 3], trial_sel[:, 5] == 6
        )

        for su_idx in range(trial_FR.shape[2]):
            onesu = np.squeeze(trial_FR[:, :, su_idx]).T
            (base_mean, base_std) = baselineVector(onesu)
            left_trials_3 = onesu[
                            trial_sel_left_3, 20:52
                            ]  # 28 is test start, aka, -2s to +6s
            right_trials_3 = onesu[trial_sel_right_3, 20:52]

            left_trials_6 = onesu[trial_sel_left_6, 32:64]
            right_trials_6 = onesu[trial_sel_right_6, 32:64]

            left_trials = np.concatenate((left_trials_3, left_trials_6))
            right_trials = np.concatenate((right_trials_3, right_trials_6))

            self.pair_heatmapL.append(
                np.mean((left_trials - base_mean) / base_std, axis=0)
            )
            self.pair_heatmapR.append(
                np.mean((right_trials - base_mean) / base_std, axis=0)
            )

            self.pair_selectivity.append(
                self.gauss_average(
                    (np.mean(left_trials, axis=0) - np.mean(right_trials, axis=0))
                    / (
                            np.mean(right_trials, axis=0)
                            + np.mean(left_trials, axis=0)
                            + 0.25
                    )
                )
            )
            # pair stastic selective
            bins = np.ones(left_trials.shape[1])
            for bin_idx in range(left_trials.shape[1]):
                try:
                    (stat, p) = stats.mannwhitneyu(
                        left_trials[:, bin_idx].flatten(),
                        right_trials[:, bin_idx].flatten(),
                        alternative="two-sided",
                    )
                    bins[bin_idx] = p < 0.05
                except ValueError:
                    bins[bin_idx] = 0
            self.statistical_pair_selective.append(bins)
Beispiel #3
0
    def addSampleSelect(self, trial_FR, trial_sel):
        trial_sel_left = trial_sel[:, 2] == 4
        trial_sel_right = trial_sel[:, 2] == 8

        trial_sel_test_left = trial_sel[:, 3] == 4
        trial_sel_test_right = trial_sel[:, 3] == 8

        trial_sel_3 = trial_sel[:, 5] == 3
        trial_sel_6 = trial_sel[:, 5] == 6

        for su_idx in range(trial_FR.shape[2]):
            onesu = np.squeeze(trial_FR[:, :, su_idx]).T
            (base_mean, base_std) = baselineVector(onesu)

            left_3_trials = onesu[np.logical_and(trial_sel_left, trial_sel_3), :][:, self.row_sel_3]
            left_6_trials = onesu[np.logical_and(trial_sel_left, trial_sel_6), :][:, self.row_sel_6]

            right_3_trials = onesu[np.logical_and(trial_sel_right, trial_sel_3), :][:, self.row_sel_3]
            right_6_trials = onesu[np.logical_and(trial_sel_right, trial_sel_6), :][:, self.row_sel_6]

            left_trials = np.concatenate((left_3_trials, left_6_trials))
            right_trials = np.concatenate((right_3_trials, right_6_trials))

            left_3_test_trials = onesu[np.logical_and(trial_sel_test_left, trial_sel_3), :][:, self.row_sel_3]
            left_6_test_trials = onesu[np.logical_and(trial_sel_test_left, trial_sel_6), :][:, self.row_sel_6]

            right_3_test_trials = onesu[np.logical_and(trial_sel_test_right, trial_sel_3), :][:, self.row_sel_3]
            right_6_test_trials = onesu[np.logical_and(trial_sel_test_right, trial_sel_6), :][:, self.row_sel_6]

            left_test_trials = np.concatenate((left_3_test_trials, left_6_test_trials))
            right_test_trials = np.concatenate((right_3_test_trials, right_6_test_trials))

            delay_3s_trials = onesu[trial_sel_3, :][:, self.row_sel_3]
            delay_6s_trials = onesu[trial_sel_6, :][:, self.row_sel_6]

            scaled_FR = np.concatenate((delay_3s_trials, delay_6s_trials))

            self.modulation.append(
                np.abs(np.mean((scaled_FR - base_mean) / base_std, axis=0))
            )

            self.heatmapL.append(np.mean((left_trials - base_mean) / base_std, axis=0))
            self.heatmapR.append(np.mean((right_trials - base_mean) / base_std, axis=0))

            self.test_heatmapL.append(np.mean((left_test_trials - base_mean) / base_std, axis=0))
            self.test_heatmapR.append(np.mean((right_test_trials - base_mean) / base_std, axis=0))

            self.selectivity.append(
                self.gauss_average(
                    (np.mean(right_trials, axis=0) - np.mean(left_trials, axis=0))
                    / (
                            np.mean(right_trials, axis=0)
                            + np.mean(left_trials, axis=0)
                            + 0.25
                    )
                )
            )
Beispiel #4
0
    def get_normalized_fr(self, trial_FR, trials, welltrain_window=None, correctResp=None):

        ### TODO: get normalized FR for epys scaling
        for su_idx in range(trial_FR.shape[2]):
            onesu = np.squeeze(trial_FR[:, (welltrain_window
                                            & correctResp
                                            & (trials[:, 5] == 6)), su_idx]).T
            (base_mean, base_std) = baselineVector(onesu)
            allbins = np.mean((onesu - base_mean) / base_std, axis=0)
            self.modulation.append(
                np.abs([np.mean(allbins[i:i + 4]) for i in np.arange(4, 56, 4)])
            )
        return np.array(self.modulation).T
    def processCTDStats(self, trial_FR, trials, welltrain_window=None, correct_resp=None):
        shifted_trial = np.vstack((np.zeros(6), trials[:-1, :]))

        ### TODO: when variables are empty

        FR_D3_S1_S1 = trial_FR[:, np.all(np.vstack(
            (trials[:, 5] == 3, trials[:, 2] == 4, shifted_trial[:, 2] == 4, welltrain_window, correct_resp,)),
            axis=0, ), :, ]
        FR_D3_S2_S1 = trial_FR[
                      :, np.all(np.vstack(
            (trials[:, 5] == 3, trials[:, 2] == 8, shifted_trial[:, 2] == 4, welltrain_window, correct_resp,)),
            axis=0, ), :,
                      ]
        FR_D3_S1_S2 = trial_FR[
                      :, np.all(np.vstack(
            (trials[:, 5] == 3, trials[:, 2] == 4, shifted_trial[:, 2] == 8, welltrain_window, correct_resp,)),
            axis=0, ), :,
                      ]
        FR_D3_S2_S2 = trial_FR[
                      :, np.all(np.vstack(
            (trials[:, 5] == 3, trials[:, 2] == 8, shifted_trial[:, 2] == 8, welltrain_window, correct_resp,)),
            axis=0, ), :,
                      ]

        FR_D6_S1_S1 = trial_FR[
                      :, np.all(np.vstack(
            (trials[:, 5] == 6, trials[:, 2] == 4, shifted_trial[:, 2] == 4, welltrain_window, correct_resp,)),
            axis=0, ), :,
                      ]
        FR_D6_S2_S1 = trial_FR[
                      :, np.all(np.vstack(
            (trials[:, 5] == 6, trials[:, 2] == 8, shifted_trial[:, 2] == 4, welltrain_window, correct_resp,)),
            axis=0, ), :,
                      ]

        FR_D6_S1_S2 = trial_FR[
                      :, np.all(np.vstack(
            (trials[:, 5] == 6, trials[:, 2] == 4, shifted_trial[:, 2] == 8, welltrain_window, correct_resp,)),
            axis=0, ), :,
                      ]
        FR_D6_S2_S2 = trial_FR[
                      :, np.all(np.vstack(
            (trials[:, 5] == 6, trials[:, 2] == 8, shifted_trial[:, 2] == 8, welltrain_window, correct_resp,)),
            axis=0, ), :,
                      ]

        for su_idx in range(trial_FR.shape[2]):
            (mm, std) = baselineVector(
                np.squeeze(trial_FR[:, np.logical_and(welltrain_window, correct_resp), su_idx]))

            if std > 0 and np.all([x.shape[1] >= 2 for x in (
                    FR_D3_S1_S1,
                    FR_D3_S1_S2,
                    FR_D3_S2_S1,
                    FR_D3_S2_S2,
                    FR_D6_S1_S1,
                    FR_D6_S1_S2,
                    FR_D6_S2_S1,
                    FR_D6_S2_S2,
            )]):
                self.su_list.append(
                    {
                        "S1_S1_3m": self.splitMean(FR_D3_S1_S1, su_idx, mm, std),
                        "S1_S2_3m": self.splitMean(FR_D3_S1_S2, su_idx, mm, std),
                        "S2_S1_3m": self.splitMean(FR_D3_S2_S1, su_idx, mm, std),
                        "S2_S2_3m": self.splitMean(FR_D3_S2_S2, su_idx, mm, std),
                        "S1_S1_6m": self.splitMean(FR_D6_S1_S1, su_idx, mm, std),
                        "S1_S2_6m": self.splitMean(FR_D6_S1_S2, su_idx, mm, std),
                        "S2_S1_6m": self.splitMean(FR_D6_S2_S1, su_idx, mm, std),
                        "S2_S2_6m": self.splitMean(FR_D6_S2_S2, su_idx, mm, std),
                    }
                )
                self.avail.append(True)
            else:
                self.avail.append(False)