clear 
%% Sessions
a1: Y:\Analysed Data\RF_Electrophisiology\VM01_Ham25\sleep_left_right_950MHz_min9dbm_3sOn2sOff_20Wamp_180807_124423\Smoothed_data\Figures\AllCellResponsesStim_1
a2: Y:\Analysed Data\RF_Electrophisiology\VM01_Ham25\sleep_left_right_950MHz_min9dbm_3sOn2sOff_20Wamp_180807_124423\Smoothed_data\Figures\AllCellResponsesStim_2
a3: Y:\Analysed Data\RF_Electrophisiology\VM01_Ham25\Ham25_Session23_181217_174342\amplifier64\Kilosort_2019-02-27_195420\Figures\Stim_1_1_singlePower
a4: Y:\Analysed Data\RF_Electrophisiology\VM01_Ham25\Ham25_Session23_181217_174342\amplifier64\Kilosort_2019-02-27_195420\Figures\Stim_1_3_singlePower
a5: Y:\Analysed Data\RF_Electrophisiology\VM01_Ham25\Ham25_Session23_181217_174342\amplifier64\Kilosort_2019-02-27_195420\Figures\Stim_3_singlePower
a6: Y:\Analysed Data\RF_Electrophisiology\VM01_Ham25\Ham25_Session23_181217_174342\amplifier64\Kilosort_2019-02-27_195420\Figures\Stim_4_singlePower
a7: Y:\Analysed Data\RF_Electrophisiology\VM01_Ham25\Ham25_Session23_181217_174342\amplifier64\Kilosort_2019-02-27_195420\Figures\Stim_5_singlePower
a8: Y:\Analysed Data\RF_Electrophisiology\PR01_22\PR01_22_Session1_180829_172602\amplifier\Analysis\AllCellsStim_1
a9: Y:\Analysed Data\RF_Electrophisiology\PR01_22\PR01_22_Session1_180829_172602\amplifier\Analysis\AllCellsStim_2
a10: Y:\Analysed Data\RF_Electrophisiology\PR02_21\PR02_21_Session7_181219_144440\amplifier64\Kilosort_2019-02-01_155741\Figures\AllCellResponsesStim_2
a11: Y:\Analysed Data\RF_Electrophisiology\PR02_21\PR02_21_Session7_181219_144440\amplifier64\Kilosort_2019-02-01_155741\Figures\AllCellResponsesStim_3
a12: Y:\Analysed Data\RF_Electrophisiology\PR02_21\PR02_21_Session7_181219_144440\amplifier64\Kilosort_2019-02-01_155741\Figures\AllCellResponsesStim_4
a13: Y:\Analysed Data\RF_Electrophisiology\PR02_21\PR02_21_Session7_181219_144440\amplifier64\Kilosort_2019-02-01_155741\Figures\AllCellResponsesStim_5
a14: Y:\Analysed Data\RF_Electrophisiology\VM05_HAM34\VM04_HAM34_Session1_Patch_190116_151645\amplifier\Kilosort_2019-01-16_202331\Anlysis\AllCellResponseStim_2
a15: Y:\Analysed Data\RF_Electrophisiology\VM05_HAM34\VM04_HAM34_Session1_Patch_190116_151645\amplifier\Kilosort_2019-01-16_202331\Anlysis\AllCellResponseStim_3
a16: Y:\Analysed Data\RF_Electrophisiology\VM04_Ham29\Ham29_Session8_181219_115654\amplifier64\Kilosort_2019-05-16_172928\Analysis



%%
Files=dir(['*.mat']);

AllSessions=[];
for i=1:length(Files)
   temp=load(Files(i).name); 
   AllSessions=[AllSessions struct2cell(temp)] ;
end
AllCellsStat=[];
for i=1:length(AllSessions)
    AllCellsStat=[AllCellsStat AllSessions{i}];
end

pval_all=[];
pval_int=[];
pval_pyr=[];
for i=1:length(AllCellsStat)
    if ~cellfun(@isempty,AllCellsStat(i)) & AllCellsStat{i}.meanFiringRatePerSecNoStim>=0.5
        pval_all=[pval_all AllCellsStat{i}.pSN];
        if AllCellsStat{i}.cellType=="pyr"
                pval_pyr=[pval_pyr AllCellsStat{i}.pSN];
        elseif AllCellsStat{i}.cellType=="int"
                pval_int=[pval_int AllCellsStat{i}.pSN];
        end
    end
end

SuppCell_p05={};
ExctCell_p05={};
for i=1:length(AllCellsStat)
    if ~cellfun(@isempty,AllCellsStat(i)) & AllCellsStat{i}.meanFiringRatePerSecNoStim>=0.5
        if AllCellsStat{i}.pSN<0.05
            if AllCellsStat{i}.meanFiringRatePerSecNoStim>AllCellsStat{i}.meanFiringRatePerSecStim
            SuppCell_p05=[SuppCell_p05 AllCellsStat{i}] ;
            elseif AllCellsStat{i}.meanFiringRatePerSecNoStim<AllCellsStat{i}.meanFiringRatePerSecStim
            ExctCell_p05=[ExctCell_p05 AllCellsStat{i}] ;
            
        end
        end
    end
end


perctage_allcells=length(find(pval_all<0.05))/length(pval_all)*100
perctage_intcells=length(find(pval_int<0.05))/length(pval_int)*100
perctage_pyrcells=length(find(pval_pyr<0.05))/length(pval_pyr)*100

totNumCells=length(pval_all);
affectedNumcells=length(find(pval_all<0.05));
