Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
brosscle committed Apr 30, 2019
2 parents 2dfdf68 + 564d44d commit 905d3be
Show file tree
Hide file tree
Showing 115 changed files with 4,425 additions and 735 deletions.
Binary file modified MP3.fig
Binary file not shown.
222 changes: 130 additions & 92 deletions MP3.m

Large diffs are not rendered by default.

Binary file modified MP3_pipeline/MP3_pipeline.fig
Binary file not shown.
74 changes: 65 additions & 9 deletions MP3_pipeline/MP3_pipeline.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

% Edit the above text to modify the response to help MP3_pipeline

% Last Modified by GUIDE v2.5 05-Mar-2019 14:45:07
% Last Modified by GUIDE v2.5 30-Apr-2019 12:05:27

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
Expand Down Expand Up @@ -110,6 +110,7 @@ function MP3_pipeline_OpeningFcn(hObject, eventdata, handles, varargin)
%handles.MP3_pipeline_Unique_Values_Selection =
handles.MP3_pipeline_TagsToPrint = {'Patient', 'Tp', 'SequenceName'};
handles.Remove_Tags_listing = {'NoMoreTags'};
handles.Select_Number_Workers.String = 'Max';
handles.Remove_selected = handles.Remove_Tags_listing{1};
%handles.MP3_data.database.IsRaw = categorical(handles.MP3_data.database.IsRaw);

Expand Down Expand Up @@ -723,6 +724,21 @@ function MP3_pipeline_module_parameters_Callback(hObject, eventdata, handles)
table.columnName = handles.new_module.opt.table.PSOM_Fields{parameter_selected};
table.editable = true;
end
case 'check'
Temp = {getfield(handles.new_module.opt.Module_settings, handles.new_module.opt.table.PSOM_Fields{parameter_selected})};
if ~iscell(Temp{1})
Params = handles.new_module.opt.table.Default(parameter_selected);
%table.data = Params;

table.data(1:numel(Params{1}),1) = cellstr(Params{1});
table.data(1:numel(Params{1}),2) = {false};
else
Params = {getfield(handles.new_module.opt.Module_settings, handles.new_module.opt.table.PSOM_Fields{parameter_selected})};
table.data = Params{1};
end
table.columnName = {'SequenceName', 'Select Input'};
table.editable = [false true];
table.ColumnFormat = {'char'};
otherwise
table.ColumnFormat = {'char'};
table.data = '';
Expand Down Expand Up @@ -921,7 +937,7 @@ function MP3_pipeline_parameter_setup_table_CellEditCallback(hObject, eventdata,
parameter_selected = get(handles.MP3_pipeline_module_parameters,'Value');

%table_data = get(handles.MP3_pipeline_parameter_setup_table, 'Data');
if strcmp(handles.new_module.opt.table.Type{parameter_selected}, 'XScan') || strcmp(handles.new_module.opt.table.Type{parameter_selected}, 'XScanOrXROI') || strcmp(handles.new_module.opt.table.Type{parameter_selected}, 'XROI') || strcmp(handles.new_module.opt.table.Type{parameter_selected}, 'XCluster')
if strcmp(handles.new_module.opt.table.Type{parameter_selected}, 'XScan') || strcmp(handles.new_module.opt.table.Type{parameter_selected}, 'XScanOrXROI') || strcmp(handles.new_module.opt.table.Type{parameter_selected}, 'XROI') || strcmp(handles.new_module.opt.table.Type{parameter_selected}, 'XCluster')
%handles.new_module.opt.parameter_default{parameter_selected} = handles.MP3_pipeline_parameter_setup_table.Data{cell2mat(handles.MP3_pipeline_parameter_setup_table.Data(:,2)),1};
handles.new_module.opt.table.Default{parameter_selected} = handles.MP3_pipeline_parameter_setup_table.Data;
elseif strcmp(handles.new_module.opt.table.Type{parameter_selected}, '1Scan') || strcmp(handles.new_module.opt.table.Type{parameter_selected}, '1ScanOr1ROI') || strcmp(handles.new_module.opt.table.Type{parameter_selected}, '1ROI') || strcmp(handles.new_module.opt.table.Type{parameter_selected}, '1Cluster')
Expand Down Expand Up @@ -968,6 +984,8 @@ function MP3_pipeline_parameter_setup_table_CellEditCallback(hObject, eventdata,
end
% end
%handles.new_module.opt.table.Default{parameter_selected} = handles.MP3_pipeline_parameter_setup_table.Data;
elseif strcmp(handles.new_module.opt.table.Type{parameter_selected}, 'check')
handles.new_module.opt.Module_settings = setfield(handles.new_module.opt.Module_settings, handles.new_module.opt.table.PSOM_Fields{parameter_selected},handles.MP3_pipeline_parameter_setup_table.Data);
else
handles.new_module.opt.Module_settings = setfield(handles.new_module.opt.Module_settings, handles.new_module.opt.table.PSOM_Fields{parameter_selected},handles.MP3_pipeline_parameter_setup_table.Data{1,1});
%handles.new_module.opt.table.Default{parameter_selected} = handles.MP3_pipeline_parameter_setup_table.Data{1,1};
Expand Down Expand Up @@ -1496,6 +1514,8 @@ function MP3_pipeline_module_listbox_Callback(hObject, eventdata, handles)
else
if ~strcmp(handles.module_parameters_fields{i}, '') && isnumeric(handles.new_module.opt.Module_settings.(handles.module_parameters_fields{i}))
ActualValues{i} = num2str(handles.new_module.opt.Module_settings.(handles.module_parameters_fields{i}));
elseif any(contains(handles.new_module.opt.table.Type{i}, 'check'))
ActualValues{i} = char('');
elseif any(contains(handles.new_module.opt.table.Type{i}, 'Scan')) || any(contains(handles.new_module.opt.table.Type{i}, 'ROI'))
if isempty(handles.new_module.opt.table.Default{i})
Scan = [];
Expand Down Expand Up @@ -1937,19 +1957,25 @@ function MP3_pipeline_execute_button_Callback(hObject, eventdata, handles)
% hObject handle to MP3_pipeline_execute_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% for now we clean all PSOM files (old execution) in order to decrease
% potential bugs
if exist([handles.MP3_data.database.Properties.UserData.MP3_data_path, 'PSOM'], 'dir') == 7
rmdir([handles.MP3_data.database.Properties.UserData.MP3_data_path, 'PSOM'], 's')
end

if exist([handles.MP3_data.database.Properties.UserData.MP3_data_path, 'PSOM'],'dir') ~= 7
[status, ~, ~] = mkdir([handles.MP3_data.database.Properties.UserData.MP3_data_path, 'PSOM']);
if status == false
error('Cannot create the PSOM folder to save the pipeline logs.')
end
% else
% % Here we clean all PSOM files because the code do not handle these
% % files for now
% rmdir([handles.MP3_data.database.Properties.UserData.MP3_data_path, 'PSOM'], 's');
end
opt_pipe.path_logs = [handles.MP3_data.database.Properties.UserData.MP3_data_path, 'PSOM'];
opt_pipe.max_queued = 3;
%opt_pipe.mode = 'session';
%
% % set the number of workers as function of the capacity of the machine
% myCluster = parcluster('local');
% opt_pipe.max_queued = myCluster.NumWorkers
% %opt_pipe.mode = 'session';

if exist([handles.MP3_data.database.Properties.UserData.MP3_data_path, 'Derived_data'],'dir') ~= 7
[status, ~, ~] = mkdir([handles.MP3_data.database.Properties.UserData.MP3_data_path, 'Derived_data']);
Expand Down Expand Up @@ -2163,7 +2189,14 @@ function MP3_pipeline_execute_button_Callback(hObject, eventdata, handles)
% end


%% exectute the pipeline
% %% execute the pipeline

if isnan(str2double(handles.Select_Number_Workers.String))
myCluster = parcluster('local');
opt_pipe.max_queued = myCluster.NumWorkers;
else
opt_pipe.max_queued = str2double(handles.Select_Number_Workers.String);
end

if handles.MP3_pipeline_radiobuttonPSOM.Value
if exist(fullfile(opt_pipe.path_logs, 'PIPE_history.txt'), 'file') == 2
Expand Down Expand Up @@ -3610,3 +3643,26 @@ function Vectorial_Screenshot_Callback(hObject, eventdata, handles)

print(fig, [path, file],'-depsc2')
msgbox('Done', 'Information') ;



function Select_Number_Workers_Callback(hObject, eventdata, handles)
% hObject handle to Select_Number_Workers (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of Select_Number_Workers as text
% str2double(get(hObject,'String')) returns contents of Select_Number_Workers as a double


% --- Executes during object creation, after setting all properties.
function Select_Number_Workers_CreateFcn(hObject, eventdata, handles)
% hObject handle to Select_Number_Workers (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
94 changes: 61 additions & 33 deletions MP3_pipeline/Modules_Repository/ANTs/Module_Atlas_ANTs.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
% % define every option needed to run this module
% --> module_option(1,:) = field names
% --> module_option(2,:) = defaults values
module_option(:,1) = {'script_location', '/home/bouxf/Code/Matlab/ImageProcessing/ANTsSync/antsbin/bin'};
module_option(:,1) = {'script_location', '/home/bouxf/Code/ANTs/antsbin/bin'};
module_option(:,2) = {'dimension', '3'}; % TODO:remove my path
module_option(:,3) = {'transformation', 's'};
module_option(:,4) = {'atlas_filename', 'Atlas'};
Expand Down Expand Up @@ -39,31 +39,33 @@
user_parameter(:,1) = {'Description','Text','','','','',...
{
'ANTs Atlas Matching:'
' ANTS was created by:'
' ANTs was created by:'
' Brian B. Avants, Nick Tustison and Gang Song'
' Penn Image Computing And Science Laboratory'
' University of Pennsylvania'
' https://github.com/ANTsX/ANTs'
''
'Prerequisite: Put your ''.nii'' atlas in the ''data/atlas'' folder'
'Prerequisite: put your ''.nii'' or ''.nii.gz'' atlas and label files in the ''./data/atlas'' folder'
}'};

user_parameter(:,2) = {'Select one anatomical scan as input','1Scan','','',{'SequenceName'}, 'Mandatory',''};
user_parameter(:,3) = {'Parameters','','','','', '', ''};
user_parameter(:,4) = {' .ANTs script location','char','','script_location','', '',...
{'The ''bin'' ANTs path (.../antsbin/bin)'}};
folder_files = dir('data/atlas/*.nii*');

s = split(mfilename('fullpath'),'MP3_pipeline',1);
folder_files = dir(fullfile(s{1}, 'data/atlas/'));
if isempty(folder_files)
folder_files(1).name = ' ';
end
user_parameter(:,5) = {' .Atlas filename','cell', {folder_files.name}, 'atlas_filename','','',...
{'Select your atlas file'}};
user_parameter(:,6) = {' .Label filename','cell', {folder_files.name}, 'label_filename','','',...
{'Select your atlas labels file'}};
{'Select your labels file'}};
user_parameter(:,7) = {' .Dimension','cell', {'2','3'},'dimension','', '',...
{'2 or 3 (for 2 or 3 dimensional registration of single volume)'}};
{'Select the dimension: 2 or 3 (for 2 or 3 dimensional registration of single volume)'}};
user_parameter(:,8) = {' .Transformation','cell', {'t','r','a','s','sr','so','b','br','bo'},'transformation','','',...
{'Choose the transform type (default = ''s''):'
{'Select the transform type (default = ''s''):'
' t: translation (1 stage)'
' r: rigid (1 stage)'
' a: rigid + affine (2 stages)'
Expand All @@ -74,7 +76,7 @@
' br: rigid + deformable b-spline syn (2 stages)'
' bo: deformable b-spline syn only (1 stage)'}};
user_parameter(:,9) = {' .Mask ROI','1ROI', '', '', {'SequenceName'}, 'Optional',...
{'Select ROI (optional)'}};
{'Select ROI (optional but recommanded)'}};

VariableNames = {'Names_Display', 'Type', 'Default', 'PSOM_Fields', 'Scans_Input_DOF', 'IsInputMandatoryOrOptional','Help'};
opt.table = table(user_parameter(1,:)', user_parameter(2,:)', user_parameter(3,:)', user_parameter(4,:)', user_parameter(5,:)', user_parameter(6,:)', user_parameter(7,:)','VariableNames', VariableNames);
Expand Down Expand Up @@ -118,8 +120,6 @@
end




%% Syntax
if ~exist('files_in','var')||~exist('files_out','var')||~exist('opt','var')
error('Smoothing:brick','Bad syntax, type ''help %s'' for more info.',mfilename)
Expand All @@ -138,46 +138,61 @@
%% The core of the brick starts here %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

s = split(mfilename('fullpath'),'MP3_pipeline',1);
s = s{1};

prefix = char(opt.Table_in(1,:).Filename);

% Execute the ANTs command line
%compute transformations
if any(contains(fields(files_in), 'In2')) %if a mask is given
system(['bash ./MP3_pipeline/ANTs/sync_atlas.sh' ...
system(['bash ' s 'MP3_pipeline/Modules_Repository/ANTs/ANTs/sync_atlas.sh' ...
' -s ' opt.script_location ...
' -a ' './Atlas/' opt.atlas_filename ...
' -a ' s 'data/atlas/' opt.atlas_filename ...
' -i ' files_in.In1{1} ...
' -d ' opt.dimension ...
' -t ' opt.transformation ...
' -o ' [prefix '_transformation_'] ...
' -o ' s 'data/atlas/' prefix '_transformation_' ...
' -x ' files_in.In2{1} ...
]);
else
system(['bash ./MP3_pipeline/ANTs/sync_atlas.sh' ...
system(['bash ' s 'MP3_pipeline/Modules_Repository/ANTs/ANTs/sync_atlas.sh' ...
' -s ' opt.script_location ...
' -a ' './Atlas/' opt.atlas_filename ...
' -a ' s 'data/atlas/' opt.atlas_filename ...
' -i ' files_in.In1{1} ...
' -d ' opt.dimension ...
' -t ' opt.transformation ...
' -o ' [prefix '_transformation_'] ...
' -o ' s 'data/atlas/' prefix '_transformation_' ...
]);
end

transf0 = dir([prefix '_transformation_0*']);
transf1 = dir([prefix '_transformation_1Inverse*']);
transf0 = dir([s 'data/atlas/' prefix '_transformation_0*']);
transf1 = dir([s 'data/atlas/' prefix '_transformation_1Inverse*']);


%rescale atlas map
system(['bash ./MP3_pipeline/ANTs/apply_transformation.sh' ...
if ~isempty(transf0) && isempty(transf1)
system(['bash ' s 'MP3_pipeline/Modules_Repository/ANTs/ANTs/apply_transformation.sh' ...
' -s ' opt.script_location ...
' -d ' opt.dimension ...
' -t ' '"' '[' transf0.folder '/' transf0.name ',1]' '"' ...
' -i ' files_in.In1{1} ...
' -l ' s 'data/atlas/' opt.atlas_filename ...
' -o ' files_out.In1{1} ...
' -v ' '0'
]);
elseif ~isempty(transf0) && ~isempty(transf1)
system(['bash ' s 'MP3_pipeline/Modules_Repository/ANTs/ANTs/apply_transformation.sh' ...
' -s ' opt.script_location ...
' -d ' opt.dimension ...
' -t ' '"' transf1.name ' [' transf0.name ',1]' '"' ...
' -t ' '"' transf1.folder '/' transf1.name ' [' transf0.folder '/' transf0.name ',1]' '"' ...
' -i ' files_in.In1{1} ...
' -l ' './Atlas/' opt.atlas_filename ...
' -l ' s 'data/atlas/' opt.atlas_filename ...
' -o ' files_out.In1{1} ...
' -v ' '0'
]);
end


% Json processing
[path, name, ~] = fileparts(files_in.In1{1});
Expand All @@ -192,16 +207,29 @@


%rescale label map
system(['bash ./MP3_pipeline/ANTs/apply_transformation.sh' ...
' -s ' opt.script_location ...
' -d ' opt.dimension ...
' -t ' '"' transf1.name ' [' transf0.name ',1]' '"' ...
' -i ' files_in.In1{1} ...
' -l ' './data/atlas/' opt.label_filename ...
' -o ' files_out.In2{1} ...
' -v ' '0'
]);

if ~isempty(transf0) && isempty(transf1)
system(['bash ' s 'MP3_pipeline/Modules_Repository/ANTs/ANTs/apply_transformation.sh' ...
' -s ' opt.script_location ...
' -d ' opt.dimension ...
' -t ' '"' '[' transf0.folder '/' transf0.name ',1]' '"' ...
' -i ' files_in.In1{1} ...
' -l ' s './data/atlas/' opt.label_filename ...
' -o ' files_out.In2{1} ...
' -v ' '0'
]);
elseif ~isempty(transf0) && ~isempty(transf1)
system(['bash ' s 'MP3_pipeline/Modules_Repository/ANTs/ANTs/apply_transformation.sh' ...
' -s ' opt.script_location ...
' -d ' opt.dimension ...
' -t ' '"' transf1.folder '/' transf1.name ' [' transf0.folder '/' transf0.name ',1]' '"' ...
' -i ' files_in.In1{1} ...
' -l ' s './data/atlas/' opt.label_filename ...
' -o ' files_out.In2{1} ...
' -v ' '0'
]);
end


% Json processing
[path, name, ~] = fileparts(files_in.In1{1});
jsonfile = [path, '/', name, '.json'];
Expand All @@ -215,9 +243,9 @@


% remove temp files
temp_files = dir([prefix '_transformation_*']);
temp_files = dir([s './data/atlas/' prefix '_transformation_*']);
for i =1:size(temp_files)
delete(temp_files(i).name);
delete([s 'data/atlas/' temp_files(i).name]);
end


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,8 @@
ROI_cluster_header = ROI_nifti_header_Clean{i};
% On a fait le même traitement sur les files_out (tout début du code) que sur l'ouverture des ROI. Il y a donc tout à penser que l'ordre des fichiers correspondra.
ROI_cluster_header.fname = files_out.In1{i};
ROI_cluster_header = rmfield(ROI_cluster_header, 'pinfo');
%ROI_cluster_header = rmfield(ROI_cluster_header, 'pinfo');
ROI_cluster_header.pinfo = [1 0];
ROI_cluster_header = rmfield(ROI_cluster_header, 'private');

Cluster = write_volume(Cluster,ROI_nifti_header_Clean{i}, 'axial');
Expand Down
Loading

0 comments on commit 905d3be

Please sign in to comment.