Skip to content

Commit

Permalink
Debugged autoprocess_to_pdf.m and export_depth_profiles.m to ensure t…
Browse files Browse the repository at this point in the history
…hat metafile processing with planes specified in the metafile works well.
  • Loading branch information
lpolerecky committed Aug 3, 2023
1 parent e296a96 commit 194dc94
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 76 deletions.
4 changes: 2 additions & 2 deletions src/fnc/export_data_from_input_files.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ function export_data_from_input_files(varnames, foutname, t1, t2)
% filename of the final output
fn = [foutname,'.dac'];

fprintf(1,'\nExporting data to %s ... \n',fn);
fid=fopen(fn,'w');
%fid=1;

Expand All @@ -25,4 +24,5 @@ function export_data_from_input_files(varnames, foutname, t1, t2)
fprintf(fid,fmt2, table2array(t2(ii,:)));
end
fclose(fid);
fprintf(1,'Done.\n');

fprintf(1,'NOTE: Complete data exported to %s\n',fn);
3 changes: 2 additions & 1 deletion src/fnc/getratiodata.m
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@

else
% cells are not defined, so take data for all cells
disp(['** Classification file ',fncells,' not found. All cells treated as equal (class "a").']);
fprintf(1, '** Classification file %s not found.\n', fncells);
fprintf(1, ' All cells treated as equal (class "a").\n');
ii=1; d=[];
d{ii} = r(:,4:5);
cellid{ii}=r(:,1);
Expand Down
18 changes: 18 additions & 0 deletions src/lookatnanosims.m
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,24 @@
% errors down the line (e.g., when one wanted
% to display lateral profiles). This bug has
% been fixed now.
LANS_version = '2023-08-03'; % Bugs in export_depth_profiles.m fixed.
% Now it is again possible, without errors, to
% use metafile processing for plotting depth
% profiles of ion counts and ion count ratios
% in ROIs. By default, depth profiles in all
% planes selected during the processing of the
% individual datasets are plotted (and exported).
% One can change this behaviour by including a
% range of planes (e.g., [5:25]) for each
% individual dataset in the metafile. The range
% should be added at the end of the
% corresponding line. Note that this range is
% also used when doing Auto-process datasets
% during metafile processing. In this case,
% when the data is reprocessed, the total ion
% counts, and the corresponding ion count ratios,
% will be calculated by accumulating only the
% specified planes.

% name of the external image file (empty by default)
EXTERNAL_IMAGEFILE = '';
Expand Down
104 changes: 72 additions & 32 deletions src/postprocess/autoprocess_to_pdf.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ function autoprocess_to_pdf(s, handles)

% get instructions from the meta file
all_cell_types = regexprep(s.cellclasses,' ','');
[id,fname,tmnt,ct,xyz,nf,all,plot3d, basedir, image_range]=getmetainstructions(s.metafile, all_cell_types, s.plot3d);
[id, fname, tmnt, ct, xyz, nf, all, plot3d, basedir, image_range] = ...
getmetainstructions(s.metafile, all_cell_types, s.plot3d);

% the output filename will have the same base-name as the metafile
if(~isempty(s.metafile))
Expand Down Expand Up @@ -105,13 +106,14 @@ function autoprocess_to_pdf(s, handles)
% exist, do accumulation based on the information in the
% main GUI.
prefsfile = [s.base_dir fname{k} filesep s.prefsfile];
if exist(prefsfile)
if exist(prefsfile,'file')

a=load(prefsfile);
fprintf(1,'Preferences loaded from %s\n',prefsfile);

images=[];
for j=1:length(p.mass)

switch j
case 1, ims = str2num(a.h.edit12.string); mname = a.h.edit3.string;
case 2, ims = str2num(a.h.edit12.string); mname = a.h.edit4.string;
Expand All @@ -122,11 +124,29 @@ function autoprocess_to_pdf(s, handles)
case 7, ims = str2num(a.h.edit12.string); mname = a.h.edit9.string;
case 8, ims = str2num(a.h.edit12.string); mname = a.h.edit74.string;
end
images{j}=ims;

if isempty(ims)
images{j} = p.planes;
else
images{j}=ims;
end

% force image_range from the metafile, if not empty
b=eval(image_range{k});
if ~isempty(b)
if j==1
fprintf(1,'WARNING: Updating planes that will be accumulated based on the value in the metafile.\n')
fprintf(1,' Original: [%d:%d]\n', min(images{j}), max(images{j}));
fprintf(1,' Updated: %s\n', image_range{k});
end
images{j}=b;
end

if ~strcmp(p.mass{j},mname)
fprintf(1,'WARNING: Mass %s in the loaded IM file renamed to %s based on info in %s\n',p.mass{j},mname,prefsfile);
p.mass{j} = mname;
end

end

find_alignments = a.h.checkbox7.value;
Expand All @@ -137,7 +157,8 @@ function autoprocess_to_pdf(s, handles)
if find_alignments
xyalignfile = [s.base_dir fname{k} filesep s.xyalignfile];

if exist(xyalignfile)
if exist(xyalignfile,'file')

% load the previously calculated and stored alignment data
b=load(xyalignfile);
fprintf(1,'XY-alignment loaded from %s\n',xyalignfile);
Expand All @@ -146,8 +167,10 @@ function autoprocess_to_pdf(s, handles)
end
if isfield(b,'tforms')
tforms = b.tforms;
end
end

else

% if the xyalignfile does not exist, i.e., the im file has
% never been processed or was processed but without image
% alignment, autoalign images using the base mass
Expand All @@ -162,28 +185,29 @@ function autoprocess_to_pdf(s, handles)
[tforms, images, xyalign, ~, ~] = findimagealignments2(p.im{bm},[],[1:p.width],[1:p.height],0);

end

else
images={str2num(a.h.edit12.string)};
end

% align only selected planes based on info in metafile
if ~isempty(str2num(image_range{k}))
for ik=1:length(images)
images{ik} = str2num(image_range{k});
end
end
%if ~isempty(str2num(image_range{k}))
% for ik=1:length(images)
% images{ik} = str2num(image_range{k});
% end
%end

% align and accumulate masses
if ~p.planes_aligned && ~isempty(xyalign)
if ~isempty(tforms)
[p.accu_im, p.im]=accumulate_images2(p.im, tforms, p.mass, images, ones(1,length(p.mass)));
else
[p.accu_im, p.im]=accumulate_images(p.im, xyalign, p.mass, images, ones(1,length(p.mass)));
end
p.planes_aligned = 1;
else
[p.accu_im, p.im]=accumulate_images(p.im, xyalign, find_alignments, p.mass, images, zeros(1,length(p.mass)));
end
%if ~p.planes_aligned && ~isempty(xyalign)
% if ~isempty(tforms)
% [p.accu_im, p.im]=accumulate_images2(p.im, tforms, p.mass, images, ones(1,length(p.mass)));
% else
% [p.accu_im, p.im]=accumulate_images(p.im, xyalign, p.mass, images, ones(1,length(p.mass)));
% end
% p.planes_aligned = 1;
%else
% [p.accu_im, p.im]=accumulate_images(p.im, xyalign, find_alignments, p.mass, images, zeros(1,length(p.mass)));
%end

if isfield(a.h,'shift_columns_rows')
shift_columns_rows = a.h.shift_columns_rows;
Expand Down Expand Up @@ -211,24 +235,39 @@ function autoprocess_to_pdf(s, handles)
% [p.accu_im, p.im]=accumulate_images(p.im, xyalign, s.p.find_alignments, p.mass, {images}, ones(1,length(p.mass)));

% align and accumulate masses
if ~isempty(xyalign)
if ~isempty(tforms)
[p.accu_im, p.im]=accumulate_images2(p.im, tforms, p.mass, {images}, ones(1,length(p.mass)));
%[p.accu_im, p.im]=accumulate_images2(p.im, tforms, p.mass, [], ones(1,length(p.mass)));
else
[p.accu_im, p.im]=accumulate_images(p.im, xyalign, p.mass, {images}, ones(1,length(p.mass)));
%[p.accu_im, p.im]=accumulate_images(p.im, xyalign, p.mass, [], ones(1,length(p.mass)));
end
end
%if ~isempty(xyalign)
% if ~isempty(tforms)
% [p.accu_im, p.im]=accumulate_images2(p.im, tforms, p.mass, {images}, ones(1,length(p.mass)));
% %[p.accu_im, p.im]=accumulate_images2(p.im, tforms, p.mass, [], ones(1,length(p.mass)));
% else
% [p.accu_im, p.im]=accumulate_images(p.im, xyalign, p.mass, {images}, ones(1,length(p.mass)));
% %[p.accu_im, p.im]=accumulate_images(p.im, xyalign, p.mass, [], ones(1,length(p.mass)));
% end
%end

shift_columns_rows = [0 0 0 0];
shift_columns_rows = s.p.shift_columns_rows;

end

% shift columns or rows of the images, if needed, according to the
% information stored in shift_columns_rows flags
p.im = shift_columns_rows_images(p.im, shift_columns_rows);
p.accu_im = shift_columns_rows_images(p.accu_im, shift_columns_rows);
%p.accu_im = shift_columns_rows_images(p.accu_im, shift_columns_rows);

% align and accumulate masses
if ~p.planes_aligned && ~isempty(xyalign) && ~isempty(tforms)
if isempty(tforms)
% old algorithm
[p.accu_im, p.im]=accumulate_images(p.im, xyalign, p.mass, images, ones(1,length(p.mass)));
else
% new algorithm
[p.accu_im, p.im]=accumulate_images2(p.im, tforms, p.mass, images, ones(1,length(p.mass)));
end
p.planes_aligned = 1;
else
% by default, use old algorithm
[p.accu_im, p.im]=accumulate_images2(p.im, xyalign, p.mass, images, zeros(1,length(p.mass)));
end

else

Expand All @@ -254,7 +293,7 @@ function autoprocess_to_pdf(s, handles)

% load cells from disk, if the file exists, otherwise set cells to zero
cellfile = [s.base_dir fname{k} filesep s.cellfile];
if exist(cellfile)
if exist(cellfile, 'file')
a=load(cellfile);
Maskimg = a.Maskimg;
fprintf(1,'ROIs loaded from %s\n',cellfile);
Expand All @@ -269,6 +308,7 @@ function autoprocess_to_pdf(s, handles)
fig173 = 173; % "random" figure number where all the images will be displayed

% display and export all masses as PDF

% because there is no general information about the right scale,
% the images will be autoscaled in the same way as if the
% auto-scale function is chosen from the menu in the GUI
Expand Down
Loading

0 comments on commit 194dc94

Please sign in to comment.