Skip to content

Commit

Permalink
One can now export code instead of running commands with Lead-DBS.
Browse files Browse the repository at this point in the history
  • Loading branch information
andreashorn committed May 16, 2016
1 parent 73af804 commit 5245766
Show file tree
Hide file tree
Showing 9 changed files with 606 additions and 77 deletions.
2 changes: 2 additions & 0 deletions connectomics/ea_perform_lc.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ function ea_perform_lc(options)
disp('*** Done.');

%% functional parts


disp('*** Performing functional parts of LEAD-Connectome...');

if options.lc.func.compute_CM % create functional connectivity matrix
Expand Down
33 changes: 33 additions & 0 deletions ea_export.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
function ea_export(options)
% This function exports jobs created by the GUI of Lead-DBS. It is
% distributed within Lead-DBS toolbox (www.lead-dbs.org)
% __________________________________________________________________________________
% Copyright (C) 2016 Charite University Medicine Berlin, Movement Disorders Unit
% Andreas Horn



[fn,pth]=uiputfile('*.m','Specify location for new job file...','lead_job.m');
if ~fn % user pressed cancel
return
end
exp=ea_gencode(options,'options');

fID=fopen([pth,fn],'w');

% export comments
fprintf(fID,'%s\n',['% - Lead-DBS Job created on ',date,':']);
fprintf(fID,'%s\n',['% --------------------------------------']);
fprintf(fID,'\n');
fprintf(fID,'\n');

for e=1:length(exp)
fprintf(fID,'%s\n',exp{e});
end
fprintf(fID,'\n');
fprintf(fID,'%s\n','% Execute job:');
fprintf(fID,'%s\n','% ---------------------------------------');
fprintf(fID,'\n');
fprintf(fID,'%s\n',['ea_run(''run'',options);']);

edit([pth,fn]);
23 changes: 13 additions & 10 deletions ea_exportisovolume.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,17 @@ function ea_exportisovolume(elstruct,options)
nii{side}(:)=nan;
XYZ=[X{side},Y{side},Z{side},ones(length(X{side}),1)]';
XYZ=Vol.mat\XYZ; % to voxel space.
XYZ=round(XYZ(1:3,:)');
XYZ=(XYZ(1:3,:)');
% repeat the above but in voxel space..
clear bb
bb(1,:)=[min(XYZ(:,1)),max(XYZ(:,1))];
bb(2,:)=[min(XYZ(:,2)),max(XYZ(:,2))];
bb(3,:)=[min(XYZ(:,3)),max(XYZ(:,3))];
bb(1,:)=[round(min(XYZ(:,1))),round(max(XYZ(:,1)))];
bb(2,:)=[round(min(XYZ(:,2))),round(max(XYZ(:,2)))];
bb(3,:)=[round(min(XYZ(:,3))),round(max(XYZ(:,3)))];
clear XI YI ZI
[XI,YI,ZI]=meshgrid([bb(1,1):bb(1,2)],[bb(2,1):bb(2,2)],[bb(3,1):bb(3,2)]);
warning('off')
F = scatteredInterpolant(XYZ(:,1),XYZ(:,2),XYZ(:,3),double(V{side}));

F = scatteredInterpolant(XYZ(:,1),XYZ(:,2),XYZ(:,3),double(V{side}),'natural');
warning('on')
F.ExtrapolationMethod='none';

Expand Down Expand Up @@ -131,19 +132,21 @@ function ea_exportisovolume(elstruct,options)
XYZ=[[X{1};-X{2}],[Y{1};Y{2}],[Z{1};Z{2}],ones(length([X{1};X{2}]),1)]';
end
XYZ=Vol.mat\XYZ; % to voxel space.
XYZ=round(XYZ(1:3,:)');
XYZ=(XYZ(1:3,:)');
% repeat the above but in voxel space..
clear bb
bb(1,:)=[min(XYZ(:,1)),max(XYZ(:,1))];
bb(2,:)=[min(XYZ(:,2)),max(XYZ(:,2))];
bb(3,:)=[min(XYZ(:,3)),max(XYZ(:,3))];
bb(1,:)=[round(min(XYZ(:,1))),round(max(XYZ(:,1)))];
bb(2,:)=[round(min(XYZ(:,2))),round(max(XYZ(:,2)))];
bb(3,:)=[round(min(XYZ(:,3))),round(max(XYZ(:,3)))];
clear XI YI ZI
[XI,YI,ZI]=meshgrid([bb(1,1):bb(1,2)],[bb(2,1):bb(2,2)],[bb(3,1):bb(3,2)]);



warning('off');
F = scatteredInterpolant(XYZ(:,1),XYZ(:,2),XYZ(:,3),double([V{1};V{2}]));

F = scatteredInterpolant(XYZ(:,1),XYZ(:,2),XYZ(:,3),double([V{1};V{2}]),'natural');


F.ExtrapolationMethod='none';
warning('on');
Expand Down
97 changes: 97 additions & 0 deletions ea_run.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
function ea_run(cmd,options)
% This function is the main execution function of Lead-DBS. It is
% distributed within Lead-DBS toolbox (www.lead-dbs.org)
% __________________________________________________________________________________
% Copyright (C) 2016 Charite University Medicine Berlin, Movement Disorders Unit
% Andreas Horn


try
options.lc=load([fileparts(which('lead')),filesep,'connectomics',filesep,'lc_options.mat']);
catch
options.lc=[];
end

if options.d3.autoserver && options.d3.write
choice = questdlg('Are you sure you want to export results to the server automatically?', ...
'Auto Server-Export', ...
'Cancel','Yes','Cancel');
% Handle response
switch choice
case 'Cancel'
return
end
end

clc
uipatdirs=getappdata(gcf,'uipatdir');

if isempty(uipatdirs)
uipatdirs={'No Patient Selected'};
end

prefs=ea_prefs('');
if length(uipatdirs)>1 && ~isempty(which('parpool')) && prefs.pp.do % do parallel processing if available and set in ea_prefs.
try delete(gcp); end
pp=parpool(prefs.pp.profile,prefs.pp.csize);

for pat=1:length(uipatdirs)
% set patient specific options
opts{pat}=options;
opts{pat}.root=[fileparts(uipatdirs{pat}),filesep];
[~,thispatdir]=fileparts(uipatdirs{pat});
opts{pat}.patientname=thispatdir;
end

parfor pat=1:length(uipatdirs)

% run main function
try
switch cmd
case 'run'
ea_autocoord(opts{pat});
case 'export'
ea_error('Exporting code not optimized for parallel processing as of yet. Please turn off parallel processing in ea_prefs.m');
end
catch
warning([opts{pat}.patientname,' failed. Please run this patient again and adjust parameters. Moving on to next patient.' ]);
end

end
delete(pp);

else

for pat=1:length(uipatdirs)
% set patient specific options
options.root=[fileparts(uipatdirs{pat}),filesep];
[root,thispatdir]=fileparts(uipatdirs{pat});
options.patientname=thispatdir;
% run main function

if length(uipatdirs)>1 % multi mode. Dont stop at errors.
try
switch cmd
case 'run'
ea_autocoord(options);
case 'export'
ea_export(options);
end
catch
warning([options.patientname,' failed. Please run this patient again and adjust parameters. Moving on to next patient.' ]);
end
else
switch cmd
case 'run'
ea_autocoord(options);
case 'export'
ea_export(options);
end
end
end
end





Loading

0 comments on commit 5245766

Please sign in to comment.