Skip to content

Commit

Permalink
debugged: export of depth profiles of ion counts and ion count ratios…
Browse files Browse the repository at this point in the history
… in ROIs via metafile processing (Tools -> Export depth profiles for each variable and ROI)
  • Loading branch information
lpolerecky committed Aug 2, 2023
1 parent 4b34c44 commit 0049855
Show file tree
Hide file tree
Showing 5 changed files with 204 additions and 109 deletions.
13 changes: 3 additions & 10 deletions src/fnc/accumulate_masses_in_cells.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
a = mplane(ind);
indN = find(isfinite(a));
rcell(ii,jj) = sum(a(indN));
end;
end

else

Expand Down Expand Up @@ -124,16 +124,9 @@
% ratio calculation
m_out{kk} = rcell;

% because of the Poisson statistics, the percentage Poisson error of the mass
% should be equal to 100%/sqrt(mass), and so the Poisson error should
% be mass/sqrt(mass)
warning('off');
dm{kk} = rcell./sqrt(rcell);
warning('on');
% because of the Poisson statistics, the Poisson error is equal to sqrt(mass)
dm{kk} = sqrt(rcell);

ind = find(rcell==0);
dm{kk}(ind) = zeros(size(ind));

end

m=m_out;
Expand Down
36 changes: 25 additions & 11 deletions src/fnc/load_masses_parameters.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@
eval(s);
p.imscale{jj}=str2num(s);

end;
end

end;
end

if length(p.images)<length(p.mass)
for ii=(length(p.images)+1):length(p.mass)
Expand All @@ -78,7 +78,7 @@

if ii<=4, k1=ii+19; k2=ii+24;
else, k1=ii+48; k2=ii+65;
end;
end

% fill expression string:
s=['s=my_get(handles.edit',num2str(k1),',''string'');'];
Expand All @@ -96,12 +96,12 @@
p.special_scale{jj}=str2num(s);
else
p.special_scale{jj}=s;
end;
end;
end
end

end;
end

end;
end

%% fill other parameters
p.ext = 'eps';
Expand All @@ -115,8 +115,22 @@
p.maxalignment = str2num(my_get(handles.edit46,'string'));
else
p.maxalignment = 1;
end;
end

p.shift_columns_rows = [0 0 0 0];
if strcmp(get(handles.shift_first_column_end,'checked'),'on')
p.shift_columns_rows(1) = 1;
end
if strcmp(get(handles.shift_last_column_beginning,'checked'),'on')
p.shift_columns_rows(2) = 1;
end
if strcmp(get(handles.shift_first_row_end,'checked'),'on')
p.shift_columns_rows(3) = 1;
end
if strcmp(get(handles.shift_last_row_beginning,'checked'),'on')
p.shift_columns_rows(4) = 1;
end

%% add ext to the list of masses, if the relevant image file exists, but only if it has not been done before
global EXTERNAL_IMAGEFILE;
if ~isempty(EXTERNAL_IMAGEFILE)
Expand All @@ -127,8 +141,8 @@
p.images{Nim+1}=p.images{Nim};
p.imscale{Nim+1}='[0 255]';
fprintf(1,'Loading parameters for the external image.\n');
end;
end;
end;
end
end
end


22 changes: 11 additions & 11 deletions src/fnc/shift_columns_rows_images.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,34 @@
height = size(a,1);
if shift_columns_rows(4)
a=[a(:,2:width) a(:,1)];
end;
end
if shift_columns_rows(3)
a=[a(:,width),a(:,1:width-1)];
end;
end
if shift_columns_rows(2)
a=[a(2:height,:); a(1,:)];
end;
end
if shift_columns_rows(1)
a=[a(height,:); a(1:height-1,:)];
end;
end
im{ii}(:,:,jj) = a;
end;
end;
end
end

if shift_columns_rows(4)
fprintf(1,'WARNING: In all images the 1st data column was shifted as the right-most one.\n');
end;
end

if shift_columns_rows(3)
fprintf(1,'WARNING: In all images the last data column was shifted as the 1st one.\n');
end;
end

if shift_columns_rows(2)
fprintf(1,'WARNING: In all images the 1st data row was shifted as the lower-most one.\n');
end;
end

if shift_columns_rows(1)
fprintf(1,'WARNING: In all images the last data row was shifted as the 1st one.\n');
end;
end

end;
end
108 changes: 85 additions & 23 deletions src/postprocess/display_depth_profiles_ROIS.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,54 +4,66 @@

counts = m;
dcounts = dm;
Nrois = length(cid);
plane_range = images{1};
if isempty(plane_range)
plane_range = 1:size(m{1},2);
end

out=[];
pdfout=[];
pdfout=[];out_counts = zeros(length(plane_range), 2*Nrois);

out_counts = zeros(length(masses), length(plane_range), 2*Nrois);
out_ratios = zeros(length(ratios), length(plane_range), 2*Nrois);

MAX_GRAPHS=9;

for ii=1:length(ratios)

[formula, PoissErr, mass_index] = parse_formula_lans(ratios{ii},masses);
[formula, PoissErr, mass_index] = parse_formula_lans(ratios{ii}, masses);

if ~isempty(mass_index)

f30{ii}=figure(30+ii);
sz = get( 0, 'ScreenSize' );
fp = get(f30{ii},'Position');
set(f30{ii},'Position',[sz(3)/2 1 sz(3)/2 sz(4)]);

Nrois = length(cid);
set(f30{ii},'Position',[sz(3)/2 1 sz(3)/2 sz(4)]);

nrows = ceil(MAX_GRAPHS/3);

if Nrois>MAX_GRAPHS
fprintf(1,'*** WARNING: Number of ROIs>%d. Depth profiles for only the first %d ROIs will be displayed.\n',MAX_GRAPHS,MAX_GRAPHS);
end;
end

ll = 0;
for jj=1:Nrois

y=[];
for kk=1:length(mass_index)
y(:,kk) = counts{mass_index(kk)}(jj,plane_range);
end;
end

ROIsize=length(find(Maskimg==jj));
y=y/ROIsize;

m=[];
for kk=1:length(masses)
m{kk}=counts{kk}(jj,plane_range);
end;

% store accoumulated counts per ROI for later export
if ii==1
out_counts(kk, :, 2*(jj-1)+[1 2]) = [m{kk}(:) sqrt(m{kk}(:))];
end
end

% calculate depth profile of the ratio
eval(formula);
r_profile = r;
eval(PoissErr);
dr_profile = per;
values = [r(:) per(:).*r(:)];
values(isnan(values)) = 0;
out_ratios(ii, :, 2*(jj-1)+[1 2]) = values;

% calculate correction for variance in r due to Poisson contribution
% NOTE: the formula only works for a *simple ratio of two* variables (R/S), i.e.,
Expand All @@ -77,15 +89,15 @@
m=[];
for kk=1:length(masses)
m{kk}=sum(counts{kk}(jj,plane_range));
end;
end
eval(formula);
out{ii}(jj,:) = [r out1];

% display depth profiles of the ion_counts/pixel and of the ratio
% in the ROI, but only if its class is member of the
% cellclasses specified by the user
% NOTE: both ion counts and ratios will be normalized to mean
% to highlight the variability
% NOTE: both ion counts and ratios will be *normalized* by the
% mean value to better highlight the variability over depth
if sum(ismember(cellclasses,cid(jj))) > 0
ll=ll+1;
if ll<=MAX_GRAPHS
Expand Down Expand Up @@ -130,23 +142,29 @@
set(get(ax(1),'Ylabel'),'String', sprintf('(%s) / %.2e',ratios{ii},r));
xlabel('plane')
title(sprintf('ROI %d (%c) [CV=%2.1f%c (z:%2.0f%c)]',cnum(jj),cid(jj),...
out1(1)/r*100, '%', (out1(3)/out1(1))^2*100, '%'));
out1(1)/r*100, '%', (out1(3)/out1(1))^2*100, '%'), 'color','b');
set(ax(1),'FontSize',additional_settings.defFontSize);
set(ax(2),'FontSize',additional_settings.defFontSize);
mcols = 'gbmc';
%mcols = 'gbmc';
mcols = 'x+';
for kk=1:length(h2)
set(h2(kk),'linestyle','none','Marker','.',...
'MarkerSize',12,'Color',mcols(kk));
end;
set(h1,'linestyle','-','Marker','x','Color','r');
%set(h2(kk),'linestyle','none','Marker','.',...
% 'MarkerSize',12,'Color',mcols(kk));
set(h2(kk),'linestyle','none','Marker',mcols(kk),...
'MarkerSize',8,'Color','k');
end
set(h1,'linestyle','-','Marker','*','MarkerSize',8,'Color','r');
set(ax(1),'ylim',[minr maxr],'xlim',[min(plane_range)-1 max(plane_range)],...
'ytick',linspace(minr,maxr,2));
'ytick',[minr, 1, maxr]); %linspace(minr,maxr,2));
set(get(ax(1),'YLabel'),'Position', [min(plane_range)-3, mean([minr, maxr]), -1]);
set(ax(2),'ylim',[miny maxy],'xlim',[min(plane_range)-1 max(plane_range)],...
'ytick',linspace(miny,maxy,2));
'ytick',[]); %linspace(miny,maxy,2));
set(get(ax(2),'Ylabel'),'String', sprintf('%s(%s), %s(%s)',masses{mass_index(1)}, mcols(1), masses{mass_index(2)}, mcols(2)));
set(get(ax(2),'Ylabel'),'Position', [max(plane_range)+1, mean([miny, maxy]), -1]);
a=0;
end;
end;
end;
end
end
end

[fdir, fn, fext] = fileparts(fname);
set(f30{ii},'name',fn);
Expand All @@ -161,7 +179,51 @@

%a=0;
%close(f30);


% export depth profiles of ion counts
if ii==1
for kk=1:length(masses)
fout = [fname delimiter 'dat' delimiter masses{kk} '-z.dat'];
fid = fopen(fout, 'w');
fprintf(fid, '# %s/: %s\n', fname, masses{kk});
fprintf(fid, '# cell');
for jj=1:Nrois
fprintf(fid, '\tMEAN%d\tPoiss_E%d', jj,jj);
end
fprintf(fid,'\n# plane');
fmt = '%d';
for jj=1:Nrois
fprintf(fid, '\tPOL=NaN\t');
fmt = [fmt, '\t%.3e\t%.3e'];
end
fmt = [fmt, '\n'];
fprintf(fid,'\n');
fprintf(fid, fmt, [plane_range(:) squeeze(out_counts(kk,:,:))]');
fclose(fid);
fprintf(1,'Depth profiles of %s ion counts per ROI exported to %s\n', masses{kk}, fout);
end
end

% export depth profile of ion count ratios
fout = [fname delimiter 'dat' delimiter convert_string_for_texoutput(ratios{ii}) '-z.dat'];
fid = fopen(fout, 'w');
fprintf(fid, '# %s/: %s\n', fname, ratios{ii});
fprintf(fid, '# cell');
for jj=1:Nrois
fprintf(fid, '\tMEAN%d\tPoiss_E%d', jj,jj);
end
fprintf(fid,'\n# plane\t');
fmt = '%d';
for jj=1:Nrois
fprintf(fid, '\tPOL=NaN');
fmt = [fmt, '\t%.3e\t%.3e'];
end
fmt = [fmt, '\n'];
fprintf(fid,'\n');
fprintf(fid, fmt, [plane_range(:) squeeze(out_ratios(ii,:,:))]');
fclose(fid);
fprintf(1,'Depth profiles of %s ratios in ROIs exported to %s\n', ratios{ii}, fout);

else

out{ii} = [];
Expand Down
Loading

0 comments on commit 0049855

Please sign in to comment.