function [stats] = estimate_cell_concentration(files) if iscell(files) stats = cell(length(files),1); for i=1:length(files) stats{i} = estimate_cell_concentration(files{i}); end stats = [files(:) stats]; return; elseif (isdir(files)) content = dir(files); newfiles = cell(length(content),1); for i=1:length(content) if content(i).name(1) ~= '.' newfiles{i} = fullfile(files, content(i).name); end end newfiles = newfiles(~cellfun('isempty', newfiles)); stats = []; if numel(newfiles) > 0 stats = estimate_cell_concentration(newfiles); end return; end [dir, name, ext] = fileparts(files); if (~strncmp(ext, '.fcs', 4)) stats = []; return; end [r,h,d]=fca_readfcs(files); startt = ((str2num(h.starttime(1:2))*60 + str2num(h.starttime(4:5)))*60 + str2num(h.starttime(7:8)))*1000 + str2num(h.starttime(10:11)); stopt = ((str2num(h.stoptime(1:2))*60 + str2num(h.stoptime(4:5)))*60 + str2num(h.stoptime(7:8)))*1000 + str2num(h.stoptime(10:11)); % Seems to yield second like this hits = sort(r(:,end) / 10); bins = [floor(min(hits)*0.95):ceil(max(hits)*1.05)]; [counts] = hist(hits, bins); outliers = (counts < mean(counts)/3); cleaned = counts(~outliers); for nneigh = 5:5:15 F = ones(1,2*nneigh+1); F = F/sum(F); smoothed = conv(counts(1, :), F, 'same'); counts = [counts; smoothed]; smoothed = conv(cleaned(1, :), F, 'same'); cleaned = [cleaned; smoothed]; end stats = cat(3,[mean(counts, 2) median(counts, 2), std(counts, 0, 2)], [mean(cleaned, 2) median(cleaned, 2), std(cleaned, 0, 2)]); figure;plot(bins, counts);title(files); figure;plot(bins(~outliers), cleaned);title(files); %keyboard return; end