Skip to content

Commit

Permalink
Fixes for last commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
andreashorn committed Oct 4, 2016
1 parent 3b4908d commit 86ddb04
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 59 deletions.
13 changes: 13 additions & 0 deletions cluster/ea_run_HMS_Orchestra_max.m
@@ -0,0 +1,13 @@
function ea_run_HMS_Orchestra_max(options)

% This is a function that runs code for each subject on a cluster. It needs
% to be adapted to suit your needs. Then, you can "Export code" using
% Lead-DBS and simply change the command ea_run to ea_run_cluster.


jobID=ea_generate_guid;
options.spmdir=spm('dir');
save([options.root,options.patientname,filesep,'job_',jobID],'options')
setenv('ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS','1')
cmdstring=['cd ',options.earoot,' && bsub -q long -R "rusage[mem=20000]" -W 720:0 -o ',[options.root,options.patientname,filesep,'job_',jobID],'.out -e ',[options.root,options.patientname,filesep,'job_',jobID],'.err matlab -singleCompThread -nodisplay -r "ea_run runcluster ',[options.root,options.patientname,filesep,'job_',jobID],'"'];
system(cmdstring);
2 changes: 1 addition & 1 deletion connectomics/ea_convis.m
Expand Up @@ -269,7 +269,7 @@ function ea_cvshowseedbasedresults(resultfig,directory,pV,pX,selectedparc,handle
if ~ret % something has changed since last time.
ea_deletePL(resultfig,'PL','mat');

[~,thresh]=ea_cvshowfiberconnectivities(resultfig,fibersfile,seed,targetsfile,thresh,1,options,'',changedstates,'mat');
[~,thresh]=ea_cvshowfiberconnectivities(resultfig,fibersfile,seed,targetsfile,thresh,1,options,'',changedstates,'mat',get(handles.vizmat_regs,'Value'),get(handles.vizmat_labs,'Value'));
set(handles.matthreshis,'String',num2str(thresh));

end
Expand Down
10 changes: 3 additions & 7 deletions connectomics/ea_cvshowfiberconnectivities.m
@@ -1,4 +1,4 @@
function [PL,thresh]=ea_cvshowfiberconnectivities(resultfig,fibersfile,seedfile,targetsfile,thresh,sides,options,stimparams,changedstates,mode)
function [PL,thresh]=ea_cvshowfiberconnectivities(resultfig,fibersfile,seedfile,targetsfile,thresh,sides,options,stimparams,changedstates,mode,showregs,showlabs)
% This function shows fiber-connectivity from a volume defined by a nx3
% point-list (volume). If stimparams.showconnectivities is set, connected
% areas to the volume are also visualized. To do so, the function uses
Expand Down Expand Up @@ -238,12 +238,8 @@
% always show seed patch (i.e. VAT)
PL.matseedsurf{side}=ea_showseedpatch(resultfig,seed{side},seed{side}.img,options);

if get(handles.vizvat_regs,'Value') || get(handles.vizvat_labs,'Value')
[PL.matsurf{side},PL.conlabels{side}]=ea_showconnectivitypatch(resultfig,targets,contargets,thresh,atlas_lgnd{2},tareas{side},[],get(handles.vizvat_regs,'Value'),get(handles.vizvat_labs,'Value'));
else
PL.matsurf{side}=[];
PL.conlabels{side}=[];
end
[PL.matsurf{side},PL.conlabels{side}]=ea_showconnectivitypatch(resultfig,targets,contargets,thresh,atlas_lgnd{2},tareas{side},[],showregs,showlabs);

clear allcareas conareas
% %% now show areas
% targets.img=round(targets.img);
Expand Down
2 changes: 1 addition & 1 deletion connectomics/ea_cvshowvatdmri.m
Expand Up @@ -59,7 +59,7 @@ function ea_cvshowvatdmri(resultfig,directory,handles,selectedparc,options)
if ~ret % something has changed since last time.
ea_deletePL(resultfig,'PL','vat');
if dimensionality % one of the vat checkboxes is active
[~,thresh]=ea_cvshowfiberconnectivities(resultfig,fibersfile,seedfile,targetsfile,thresh,sides,options,S,changedstates,'vat'); % 'vat' only used for storage of changes.
[~,thresh]=ea_cvshowfiberconnectivities(resultfig,fibersfile,seedfile,targetsfile,thresh,sides,options,S,changedstates,'vat',get(handles.vizvat_regs,'Value'),get(handles.vizvat_labs,'Value')); % 'vat' only used for storage of changes.
if isstruct(handles)
set(handles.vatthreshis,'String',num2str(thresh));
end
Expand Down
96 changes: 48 additions & 48 deletions connectomics/ea_showconnectivitypatch.m
@@ -1,43 +1,43 @@
function [matsurf,labels]=ea_showconnectivitypatch(resultfig,pV,mX,thresh,atlaslegend,atlasindices,showregs,showlabels)
function [matsurf,labels]=ea_showconnectivitypatch(resultfig,pV,mX,thresh,atlaslegend,atlasindices,usecolormap,showregs,showlabels)




tmX=mX>thresh;

options.prefs=ea_prefs('');
if options.prefs.hullsmooth
tmX=smooth3(tmX,'gaussian',options.prefs.hullsmooth);
end

bb=[0,0,0;size(mX)];

bb=map_coords_proxy(bb,pV);
gv=cell(3,1);
for dim=1:3
gv{dim}=linspace(bb(1,dim),bb(2,dim),size(mX,dim));
end
[X,Y,Z]=meshgrid(gv{1},gv{2},gv{3});
fv=isosurface(X,Y,Z,permute(tmX,[2,1,3]),0.5); % graph_metric


if ischar(options.prefs.hullsimplify)
% get to 1500 faces
simplify=1500;
fv=reducepatch(fv,simplify);
else
if options.prefs.hullsimplify<1 && options.prefs.hullsimplify>0

fv=reducepatch(fv,options.prefs.hullsimplify);
elseif options.prefs.hullsimplify>1
simplify=options.prefs.hullsimplify/length(fv.faces);
if showregs

tmX=mX>thresh;

options.prefs=ea_prefs('');
if options.prefs.hullsmooth
tmX=smooth3(tmX,'gaussian',options.prefs.hullsmooth);
end

bb=[0,0,0;size(mX)];

bb=map_coords_proxy(bb,pV);
gv=cell(3,1);
for dim=1:3
gv{dim}=linspace(bb(1,dim),bb(2,dim),size(mX,dim));
end
[X,Y,Z]=meshgrid(gv{1},gv{2},gv{3});
fv=isosurface(X,Y,Z,permute(tmX,[2,1,3]),0.5); % graph_metric


if ischar(options.prefs.hullsimplify)
% get to 1500 faces
simplify=1500;
fv=reducepatch(fv,simplify);
else
if options.prefs.hullsimplify<1 && options.prefs.hullsimplify>0

fv=reducepatch(fv,options.prefs.hullsimplify);
elseif options.prefs.hullsimplify>1
simplify=options.prefs.hullsimplify/length(fv.faces);
fv=reducepatch(fv,simplify);
end
end
end


set(0,'CurrentFigure',resultfig)
if showregs


set(0,'CurrentFigure',resultfig)
matsurf=patch(fv,'facealpha',0.7,'EdgeColor','none','facelighting','phong','FaceColor','interp');

zidx=mX==0;
Expand Down Expand Up @@ -86,7 +86,7 @@

[xx,yy,zz]=ind2sub(size(pV.img),find(pV.img==atlasindices(lab)));
XYZ=[xx,yy,zz];
centr_vx=[mean(XYZ,1),1]';
centr_vx=[mean(XYZ,1),1]';
centr_mm=pV.mat*centr_vx;

labels(lab)=text(centr_mm(1),centr_mm(2),centr_mm(3),sub2space(atlaslegend{atlasindices(lab)}));
Expand All @@ -103,39 +103,39 @@


% %% old
%
%
% bb=[0,0,0;size(mX)];
%
%
% bb=map_coords_proxy(bb,pV);
% gv=cell(3,1);
% for dim=1:3
% gv{dim}=linspace(bb(1,dim),bb(2,dim),size(mX,dim));
% end
% [X,Y,Z]=meshgrid(gv{1},gv{2},gv{3});
%
%
%
%
% fv=isosurface(X,Y,Z,permute(mX,[2,1,3]),thresh); % connected regions
%
%
% if ischar(options.prefs.lhullsimplify)
%
%
% % get to certain number of faces
% simplify=10000/length(fv.faces);
% fv=reducepatch(fv,simplify);
%
%
% else
% if options.prefs.lhullsimplify<1 && options.prefs.lhullsimplify>0
% fv=reducepatch(fv,options.prefs.lhullsimplify);
% end
% end
%
%
% set(0,'CurrentFigure',resultfig)
% matsurf=patch(fv,'FaceColor','interp','facealpha',0.7,'EdgeColor','none','facelighting','phong');
%
%
% cmX=mX;
% zidx=cmX==0;
% zidx=logical(zidx+isnan(cmX));
% cmX(isnan(cmX))=0;
%
%
% try % if not possible, connectivity is empty..
% cmX=cmX-min(cmX(cmX~=0));
% end
Expand All @@ -144,13 +144,13 @@
% end
% cmX(zidx)=0; % reset prior zero/nan values to zero
% isocolors(X,Y,Z,permute(cmX,[2,1,3]),matsurf)
%
%
% set(matsurf,'DiffuseStrength',0.9)
% set(matsurf,'SpecularStrength',0.1)
% set(matsurf,'FaceAlpha',0.3);
% %threshold seedcon
% % seedcon=((seedcon-thresh)/(max(seedcon)-thresh))*255;
% %
% %
% % cX=pX;
% % for i=1:length(seedcon)
% % cX(pX==i)=seedcon(i);
Expand Down
76 changes: 76 additions & 0 deletions dbshub/ea_exportscore.m
@@ -0,0 +1,76 @@
function score=ea_exportscore()

% for now static sample export:

score.studyOrigin='Earlystim'; % Tag label study name
score.studyDoi='10.1056/NEJMoa1205158'; % Tag label study name
score.metric='UPDRS-III'; % clinical score label
score.dbsOff.vals=[1,2,0,0,0,0,0,0,0,0,0,0,0,0,2,3,2,2,3,3,1,1,1,2,2,2,2];
score.dbsOff.mean=(mean(score.dbsOff.vals));
score.dbsOn.vals=[0,2,0,0,0,0,0,2,2,0,0,0,0,0,3,3,1,2,1,3,0,2,1,2,2,2,2];
score.dbsOn.mean=(mean(score.dbsOn.vals));
score.patient.DOB='05-10-1951'; % date of birth
score.patient.DOS='03-02-2014'; % date of surgery
score.patient.disease='Parkinson''''s Disease';
score.patient.diseaseSubtype='Tremor Dominant';
score.version=1.0;

ea_savejson('',score,ea_setjsopts('sample.json'));
















function opt=ea_setjsopts(fname)


opt.FileName=fname;
% opt.FloatFormat ['%.10g'|string]: format to show each numeric element
% of a 1D/2D array;
% opt.ArrayIndent [1|0]: if 1, output explicit data array with
% precedent indentation; if 0, no indentation
% opt.ArrayToStruct[0|1]: when set to 0, savejson outputs 1D/2D
% array in JSON array format; if sets to 1, an
% array will be shown as a struct with fields
% "_ArrayType_", "_ArraySize_" and "_ArrayData_"; for
% sparse arrays, the non-zero elements will be
% saved to _ArrayData_ field in triplet-format i.e.
% (ix,iy,val) and "_ArrayIsSparse_" will be added
% with a value of 1; for a complex array, the
% _ArrayData_ array will include two columns
% (4 for sparse) to record the real and imaginary
% parts, and also "_ArrayIsComplex_":1 is added.
% opt.ParseLogical [0|1]: if this is set to 1, logical array elem
% will use true/false rather than 1/0.
% opt.NoRowBracket [1|0]: if this is set to 1, arrays with a single
% numerical element will be shown without a square
% bracket, unless it is the root object; if 0, square
% brackets are forced for any numerical arrays.
% opt.ForceRootName [0|1]: when set to 1 and rootname is empty, savejson
% will use the name of the passed obj variable as the
% root object name; if obj is an expression and
% does not have a name, 'root' will be used; if this
% is set to 0 and rootname is empty, the root level
% will be merged down to the lower level.
% opt.Inf ['"$1_Inf_"'|string]: a customized regular expression pattern
% to represent +/-Inf. The matched pattern is '([-+]*)Inf'
% and $1 represents the sign. For those who want to use
% 1e999 to represent Inf, they can set opt.Inf to '$11e999'
% opt.NaN ['"_NaN_"'|string]: a customized regular expression pattern
% to represent NaN
% opt.JSONP [''|string]: to generate a JSONP output (JSON with padding),
% for example, if opt.JSON='foo', the JSON data is
% wrapped inside a function call as 'foo(...);'
% opt.UnpackHex [1|0]: conver the 0x[hex code] output by loadjson
% back to the string form
5 changes: 3 additions & 2 deletions ea_regressout.m
Expand Up @@ -6,7 +6,7 @@
nnanix=any(isnan(Cova),1);
nnanix=nnanix+(isnan(S));
nnanix=~nnanix;

Cleaned=S;
Cova=Cova(:,nnanix);

S=S(nnanix);
Expand All @@ -15,4 +15,5 @@
S=zscore(S);

beta_hat = (Cova*Cova')\Cova*squeeze(S'); % ordinary least-squares estimator
Cleaned=squeeze(S)'-Cova'*beta_hat; % regress out each covariate.
Cleaned(nnanix)=squeeze(S)'-Cova'*beta_hat; % regress out each covariate.
Cleaned=Cleaned';

0 comments on commit 86ddb04

Please sign in to comment.