clc
clearvars

 filename = 'filt_neurons.mat'; %UPDATE this for each experiment. 

load(filename)
%%
output_dir=fullfile('figs','QC_cpc_plot');
mkdir(output_dir)

max_color_lim = 120;

slices = unique(filt_neurons.slice);
genes_per_cell = sum(filt_neurons.expmat>0,2);
counts_per_cell = full(sum(filt_neurons.expmat,2));
%%
figure('Position',[0, 0, 1200, 1200]);
hold on;
for i=1:numel(slices)



in_slice=filt_neurons.slice==slices(i);

subplot(4,4,i); hold on;
title(['slice ',num2str(slices(i))])
%    plot all neurons color coded by count
scatter(filt_neurons.pos(in_slice&counts_per_cell>1,1), ...
filt_neurons.pos(in_slice&counts_per_cell>1,2), ...
2, ...
counts_per_cell(in_slice&counts_per_cell>1),...
'filled', ...
 'MarkerFaceAlpha', 0.5,...
'MarkerEdgeAlpha', 0.5...
);

xl=xlim;
yl=ylim;
set(gca, ...
    'ydir','reverse' ...
    );
axis off
pbaspect([range(xl),range(yl),1]);

 colormap(gca,'parula');
 clim([0 max_color_lim]);
 colorbar

        
      
%       print(gcf,fullfile(output_dir,[UUID,'_Slice_',num2str(s),'_', gene_to_plot,'_counts.svg']),'-dsvg');
       % close all;
end
    
%%
exportgraphics(gcf,fullfile(output_dir,['Counts_per_cell.png']),'ContentType','Image','Resolution',300);