Skip to content

Commit

Permalink
Merge pull request #15 from tincala91/nb_plugins
Browse files Browse the repository at this point in the history
Implementation of plugins
  • Loading branch information
tincala91 authored Aug 8, 2023
2 parents f7ab318 + a9e7c60 commit 801bc0d
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 12,443 deletions.
7 changes: 5 additions & 2 deletions COFFEE_BREAK_FDGPET.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
addpath(fullfile(baseDir, 'OTHER_FUNCTIONS', 'TFCE'));
addpath(fullfile(baseDir, 'OTHER_FUNCTIONS', 'export_fig-master'));

% Initialize plugins
%plugins.init()

%selects the directory containing only dicoms
dir_path = spm_select(1,'dir', 'Select directory where DICOM files are'); %% input directory

Expand Down Expand Up @@ -151,7 +154,7 @@
%creates render in MRIcron style
sub_info = I_SUV_GM_script(dir_path, sub_info);

K_Create_Report(dir_path, sub_info);
run_plugin('K', dir_path, sub_info);

end

Expand All @@ -160,7 +163,7 @@
rmpath(fullfile(baseDir, 'OTHER_FUNCTIONS', 'TFCE'));
rmpath(fullfile(baseDir, 'OTHER_FUNCTIONS', 'export_fig-master'));
cd(cur_path);
save('workspace_dump.m');
save('workspace_dump.mat');
rethrow(ME);
end

Expand Down
12,304 changes: 0 additions & 12,304 deletions MASK_TEMPLATES_HC/06_Template_PET_Report_neu.rtf

This file was deleted.

3 changes: 2 additions & 1 deletion OTHER_FUNCTIONS/ViewSUV3D.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ function ViewSUV3D(filename, sub_info)

%filename = 'wSUV_ScCh_19591229_20210510.nii'
%Load image
img_SUV = double(load_nii(filename).img);
nii = load_nii(filename);
img_SUV = double(nii.img);

%Get image shape
[xdim, ydim, zdim] = size(img_SUV);
Expand Down
10 changes: 0 additions & 10 deletions OTHER_FUNCTIONS/img2rtf.m

This file was deleted.

46 changes: 0 additions & 46 deletions OTHER_FUNCTIONS/replace_in_file.m

This file was deleted.

48 changes: 0 additions & 48 deletions OTHER_FUNCTIONS/replace_in_line.m

This file was deleted.

1 change: 1 addition & 0 deletions Plugins/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*/
3 changes: 3 additions & 0 deletions Plugins/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Place the plugins in this folder.

The folders in this directory will be added to path at runtime.
5 changes: 2 additions & 3 deletions private/E_STAT_script.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
function mat_file = E_STAT_script(files, render, mask, controls)
%declaring useful variables
global JOB_DIR
global xSPM

files = cellstr(files);
controls = cellstr(controls);
Expand Down Expand Up @@ -31,12 +30,12 @@
export_fig 'Hypo.jpg';

%spm_render_DOC(struct('XYZ', xSPM.XYZ, 't',xSPM.Z,'mat', xSPM.M,'dim', xSPM.DIM),1,render,1)
spm_render_DOC(get_renderer(xSPM),1,render,1)
spm_render_DOC(get_renderer(),1,render,1);
%saveas(gcf, 'Render_hypo_new.jpg');
export_fig 'Render_hypo_new.jpg';

%spm_render_DOC(struct('XYZ', xSPM.XYZ, 't',xSPM.Z,'mat', xSPM.M,'dim', xSPM.DIM),nan,render)
spm_render_DOC(get_renderer(xSPM),nan,render)
spm_render_DOC(get_renderer(),nan,render);
spm_figure('colormap','gray-cool');
%saveas(gcf, 'Render_hypo_old.jpg');
export_fig 'Render_hypo_old.jpg';
Expand Down
5 changes: 2 additions & 3 deletions private/E_STAT_script_addon.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
function files = E_STAT_script_addon(spm_mat_file, render, template)
%declaring useful variables
global JOB_DIR
global xSPM

[pth, ~, ~] = fileparts(spm_mat_file);
cur_dir = pwd();
Expand All @@ -23,11 +22,11 @@
export_fig 'Pres.jpg'

%spm_render_DOC(struct('XYZ', xSPM.XYZ, 't',xSPM.Z,'mat', xSPM.M,'dim', xSPM.DIM), 1, render, 0);
spm_render_DOC(get_renderer(xSPM), 1, render, 0);
spm_render_DOC(get_renderer(), 1, render, 0);
export_fig 'Render_pres_new.jpg'; %saves render as jpeg (get current figure!)

%spm_render_DOC(struct('XYZ', xSPM.XYZ, 't',xSPM.Z,'mat', xSPM.M,'dim', xSPM.DIM), nan, render);
spm_render_DOC(get_renderer(xSPM), nan, render);
spm_render_DOC(get_renderer(), nan, render);
export_fig 'Render_pres_old.jpg'

hypo_nii = 'spmT_0001_Hypo.nii';
Expand Down
19 changes: 0 additions & 19 deletions private/K_Create_Report.m

This file was deleted.

15 changes: 8 additions & 7 deletions OTHER_FUNCTIONS/get_renderer.m → private/get_renderer.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
function params = get_renderer(xSPM)

params.XYZ = xSPM.XYZ;
params.t = xSPM.Z;
params.mat = xSPM.M;
params.dim = xSPM.DIM;
end
function params = get_renderer()
global xSPM;

params.XYZ = xSPM.XYZ;
params.t = xSPM.Z;
params.mat = xSPM.M;
params.dim = xSPM.DIM;
end
42 changes: 42 additions & 0 deletions private/run_plugin.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
function run_plugin(index, varargin)
% Simple wrapper to run function from Plugins directory
% with same letter index and given parameters
%
% The plugin script must have same name as folder, including the index

cur_dir = pwd();
paths = path();
cleanup = onCleanup(@()restorePaths(paths, cur_dir));

pth = fileparts(mfilename('fullpath'));
plugins_path = fullfile(pth, '..', 'Plugins');

plugins = dir(fullfile(plugins_path, [index, '_*']));

if numel(plugins) == 0
return;
end

if numel(plugins) > 1
warning('Plugin %s: Found several plugins, will run only first', index);
end

plugin_path = fullfile(plugins(1).folder, plugins(1).name);
plugin_script = fullfile(plugin_path, 'plugin.m');
if ~exist(plugin_script, 'file')
warning('Plugin %s: Can''t find script plugin.m', index);
return;
end

fprintf('Plugin %s: Running from %s\n', index, plugin_path);

addpath(plugin_path);
plugin(varargin{:});

end


function restorePaths(search_paths, current_path)
path(search_paths);
cd(current_path);
end

0 comments on commit 801bc0d

Please sign in to comment.