%2022-02-16

% % Plotting # of cell bodies counted at PI (large cell bodies only,
% excluding posterior cell body pair that is not at PI and small cell
% bodies that are along SMP but not neurosecretory based on size)

% !! Raw data are in N11, p56 !!

R19G10_C = [10,10,6,10,10,10,11];
R19G10_E = [10,11,10,10,9,9,10];
R19G10_Cad = [0,9,9,6,7,0,0,0]; % data added 9/2/22, N11, p148-149
labels = {'Unexposed','Summiting','Cadaver'};

plotData = {R19G10_C,R19G10_E,R19G10_Cad};

figure;
hold on;

for i = 1:numel(plotData)
    p = sort(plotData{i});
    up = unique(p);
    xval = NaN(1,length(p));
    for j = 1:numel(up)
        xshift = histc(p,up(j));
        low = i-0.2;
        high = i+0.2;
        int = (high-low)/(xshift-1);
        if xshift>2
            xval(p==up(j))=low:int:high;
        elseif xshift>1
            xval(p==up(j))=[low,high];
        else
            xval(p==up(j))=i;
        end
    end
    scatter(xval,sort(plotData{i}),'MarkerFaceColor','b','MarkerEdgeColor','b','MarkerFaceAlpha',0.5,'MarkerEdgeAlpha',0.5)
end

%%
% scatter(repmat(1,1,length(R19G10_C)),R19G10_C,'jitter','on','jitterAmount',0.05,'MarkerFaceColor','b','MarkerEdgeColor','b','MarkerFaceAlpha',0.5);
% scatter(repmat(2,1,length(R19G10_E)),R19G10_E,'jitter','on','jitterAmount',0.05,'MarkerFaceColor','r','MarkerEdgeColor','r','MarkerFaceAlpha',0.5);
% scatter(repmat(3,1,length(R19G10_Cad)),R19G10_Cad,'jitter','on','jitterAmount',0.05,'MarkerFaceColor','k','MarkerEdgeColor','k','MarkerFaceAlpha',0.5);

[h,p]=ttest2(R19G10_C,R19G10_E)
[h,p]=ttest2(R19G10_E,R19G10_Cad)
[h,p]=ttest2(R19G10_C,R19G10_Cad)

% % Plot means and stdev
% scatter(1,nanmean(R19G10_E),'MarkerFaceColor','r','MarkerEdgeColor','k');
% scatter(2,nanmean(R19G10_C),'MarkerFaceColor','b','MarkerEdgeColor','k');
% scatter(3,nanmean(R19G10_Dead),'MarkerFaceColor','k','MarkerEdgeColor','k');
% errorbar(1,nanmean(R19G10_E),nanstd(R19G10_E),'k');
% errorbar(2,nanmean(R19G10_C),nanstd(R19G10_E),'k');
% errorbar(3,nanmean(R19G10_Dead),nanstd(R19G10_Dead),'k');

xlim([0.5 3.5]);
ylim([0 15]);

set(gca,'xtick',1:3,'xticklabel',labels,'TickLength',[0 0],'FontSize',18);
ylabel('PI cell bodies');

imgDir = "D:\Harvard\Manuscripts\Summit paper\Figures\Figure 5\";
%set(gcf,'PaperUnits','inches','PaperPosition',[0 0 5.6 4]);
set(gcf,'PaperUnits','inches','PaperPosition',[0 0 4.8 3]);
print(strcat(imgDir,'R19G10 cell body count.pdf'),'-dpdf');
close;

%[h,p] = ttest2(R19G10_C, R19G10_E);