fMRIDiag_plot.m 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. function fMRIDiag_plot(V,D_Stat,varargin)
  2. % fMRIDiag_plot(V,D_Stat,varargin)
  3. % Draws main var components (+ non-global comps) with BOLD intensity for
  4. % further diagnosis.
  5. %
  6. %%%%INPUTS
  7. % V : Is a structure which contains the variance components. For more
  8. % information regarding how to estimate the V, please see DSEvars.m
  9. %
  10. % D_Stat : Is a structure which contains the statistics of DVARS
  11. % inference. Can be obtained via DVARSCalc.m.
  12. %
  13. % The following arguments are optional:
  14. %
  15. % 'FD' : The frame-wise deplacement. FD can be calculated by FDCalc.m
  16. % By triggering this option, a subplot is added at the top of the
  17. % figure.
  18. %
  19. % 'AbsMov' : Absolute movement parameters which helps to gain a better
  20. % insight regarding the FD components. It can be a matrix of
  21. % 2xT-1 where the rows indicated main movement components
  22. % (rotation and trasnlational)
  23. %
  24. % 'Idx' : The index of significant DVARS spikes which can be calculated
  25. % via DVARSCalc.m. If the argument is not used, the
  26. % Idx is found via Bonferroni correction on p-values of
  27. % D_Stat structure.
  28. %
  29. % 'BOLD' : Intensity BOLD image. If triggered, a subplot is added at the
  30. % bottom of the figure.
  31. %
  32. % 'figure' : handle for the figure. Default is a 1600x1400 figure window
  33. %
  34. % 'norm' & 'scale' : For intensity normalisation, similar to DVARSCalc.m
  35. %
  36. % 'ColRng' : Colour range for BOLD intensity image. [Default is [-3 3] ]
  37. %
  38. % 'TickScaler' : If set to <1 then the number of ticks on the right y-axis
  39. % DSEvars sub-figure will be less. If set to >1, then more
  40. % ticks is shown [Default: 1]
  41. %
  42. %
  43. % 'verbose' : Print the log? if yes, set to 1, if not set to 0.
  44. %
  45. % Line/figure Specs such as: 'linewidth' and 'fontsize' as in matlab.
  46. %
  47. %
  48. %%%%EXAMPLE
  49. %
  50. % - %To produce the diagnostic figure for pure white noise, with two
  51. % %subplots.
  52. % [V,Stat]=DSEvars(randn(10e4,100));
  53. % fMRIDiag_plot(V)
  54. %
  55. % - %To produce the diagnostic figure for HCP subject 100307
  56. % OneSub='~/100307/rfMRI_REST1_LR.nii.gz' %a HCP Subject
  57. % [V,Stat]=DSEvars(OneSub);
  58. % fMRIDiag_plot(V)
  59. %
  60. % - %To produce *full* diagnostic figure for HCP subject 100307
  61. % This example shows a full diagnostic procedure using DSE var
  62. % decomposition and DVARS inference.
  63. %
  64. % OneSub='~/100307/rfMRI_REST1_LR.nii.gz' %a HCP Subject
  65. % [V,V_Stat]=DSEvars(OneSub);
  66. %
  67. % [DVARS,D_Stat]=DVARSCalc(OneSub);
  68. % idx=find(D_Stat.pvals<0.05./(T-1)); %to find the significant spikes
  69. %
  70. % MovPar=MovPartextImport(['~/100307/Movement_Regressors.txt']);
  71. % [FDts,FD_Stat]=FDCalc(MovPar);
  72. %
  73. % V1 = load_untouch_nii(OneSub);
  74. % V2 = V1.img;
  75. % X0 = size(V2,1); Y0 = size(V2,2); Z0 = size(V2,3); T0 = size(V2,4);
  76. % I0 = prod([X0,Y0,Z0]);
  77. % Y = reshape(V2,[I0,T0]); clear V2 V1;
  78. %
  79. % f_hdl=figure('position',[50,500,600,600]);
  80. % fMRIDiag_plot(V,'Idx',idx,'BOLD',Y,'FD',FDts,'AbsMov',[FD_Stat.AbsRot FD_Stat.AbsTrans],'figure',f_hdl)
  81. %
  82. %
  83. %
  84. %%%%REFERENCES
  85. %
  86. % Afyouni S. & Nichols T.E., Insights and inference for DVARS, 2017
  87. % http://www.biorxiv.org/content/early/2017/04/06/125021.1
  88. %
  89. % Soroosh Afyouni & Thomas Nichols, UoW, Feb 2017
  90. %
  91. % https://github.com/asoroosh/DVARS
  92. % http://warwick.ac.uk/tenichols
  93. %
  94. % Please report bugs to srafyouni@gmail.com
  95. %
  96. %External updates:
  97. % Eswar Damaraju <edamaraju@mrn.org>: fixed for empty Idx
  98. %
  99. FDflag = 0; AbsMovflag = 0; BOLDFlag = 0;
  100. md = []; scl = []; verbose = 1; gsrflag = 0;
  101. nsp = 14; lw = 2; lfs = 14; noColRngflag = 0;
  102. TickScaler = 1; %GrandMean = 100;
  103. if sum(strcmpi(varargin,'gsrflag'))
  104. gsrflag = varargin{find(strcmpi(varargin,'gsrflag'))+1};
  105. end
  106. % if sum(strcmpi(varargin,'GrandMean')) %needed for time when we had global
  107. % timeseries on the plot.
  108. % GrandMean = varargin{find(strcmpi(varargin,'GrandMean'))+1};
  109. % end
  110. if sum(strcmpi(varargin,'fd'))
  111. FDts = varargin{find(strcmpi(varargin,'fd'))+1};
  112. FDflag = 1;
  113. end
  114. % if sum(strcmpi(varargin,'prefix'))
  115. % prefix = varargin{find(strcmpi(varargin,'prefix'))+1};
  116. % end
  117. if sum(strcmpi(varargin,'AbsMov'))
  118. AbsMov = varargin{find(strcmpi(varargin,'AbsMov'))+1};
  119. AbsMovflag = 1;
  120. end
  121. %
  122. if sum(strcmpi(varargin,'idx'))
  123. Idx = varargin{find(strcmpi(varargin,'idx'))+1};
  124. else
  125. Idx = find(D_Stat.pvals<0.05./(D_Stat.dim(2)-1));
  126. end
  127. %
  128. if sum(strcmpi(varargin,'Thick'))
  129. Thickness = varargin{find(strcmpi(varargin,'Thick'))+1};
  130. elseif D_Stat.dim(2)>500
  131. Thickness = 1;
  132. else
  133. Thickness = 0.5;
  134. end
  135. %
  136. if sum(strcmpi(varargin,'PracticalThreshold'))
  137. psig = varargin{find(strcmpi(varargin,'PracticalThreshold'))+1};
  138. else
  139. psig = 5; % 5% level of pratical significance.
  140. end
  141. %
  142. if sum(strcmpi(varargin,'BOLD'))
  143. Y = varargin{find(strcmpi(varargin,'BOLD'))+1};
  144. BOLDFlag = 1;
  145. nsp = 20;
  146. end
  147. %
  148. if sum(strcmpi(varargin,'figure'))
  149. f_hdl = varargin{find(strcmpi(varargin,'figure'))+1};
  150. else
  151. f_hdl=figure('position',[50,500,1600,1400]);
  152. hold on; box on;
  153. end
  154. %
  155. if sum(strcmpi(varargin,'colrng'))
  156. ColRng = varargin{find(strcmpi(varargin,'colrng'))+1};
  157. else
  158. noColRngflag = 1;
  159. end
  160. %
  161. if sum(strcmpi(varargin,'norm'))
  162. scl = varargin{find(strcmpi(varargin,'norm'))+1};
  163. end
  164. %
  165. if sum(strcmpi(varargin,'TickScaler'))
  166. TickScaler = varargin{find(strcmpi(varargin,'TickScaler'))+1};
  167. end
  168. if sum(strcmpi(varargin,'scale'))
  169. scl = varargin{find(strcmpi(varargin,'scale'))+1};
  170. md = 1;
  171. end
  172. %
  173. if sum(strcmpi(varargin,'verbose'))
  174. verbose = varargin{find(strcmpi(varargin,'verbose'))+1};
  175. end
  176. %
  177. if sum(strcmpi(varargin,'linewidth'))
  178. lw = varargin{find(strcmpi(varargin,'linewidth'))+1};
  179. end
  180. %
  181. if sum(strcmpi(varargin,'fontsize'))
  182. lfs = varargin{find(strcmpi(varargin,'fontsize'))+1};
  183. end
  184. %###################################################################################
  185. Col=get(groot,'defaultAxesColorOrder');
  186. Acol=Col(5,:); % Green
  187. FDcol=[.5 .5 .5];
  188. Dcol=Col(1,:); % Blue
  189. Scol=Col(3,:); % Yellow
  190. Ecol=Col(4,:); % Purple
  191. PsigCol=Col(2,:); % Red (/orange!)
  192. T=length(V.Avar_ts);
  193. Time=1:T;
  194. hTime=(1:(T-1))+0.5;
  195. eTime=[1 T];
  196. %###################################################################################
  197. figure("WindowState","fullscreen")
  198. %---------------------------Allvar
  199. % sph0=subplot(nsp,1,[1 2]);
  200. % hold on; box on;
  201. % plot(Time,sqrt(V.Avar_ts(Time)),'color',Acol,'linestyle','-','linewidth',lw-.5)
  202. % ylabel('All','fontsize',lfs);
  203. % axis tight;
  204. % PatchMeUp(Idx);
  205. % set(sph0,'ygrid','on','xticklabel',[])
  206. % axis tight
  207. %---------------------------FD%---------------------------
  208. if FDflag
  209. sph0 = subplot(nsp,1,[1 2]);
  210. hold on; box on;
  211. yyaxis left
  212. FDline = plot(hTime,FDts,'color','k','linestyle','-','linewidth',lw-0.5);
  213. plot(hTime,ones(1,T-1)*0.5,'linewidth',lw,'linestyle','-.','color','r');
  214. plot(hTime,ones(1,T-1)*0.2,'linewidth',lw,'linestyle','-.','color','r');
  215. if max(FDts)>0.6
  216. ylim([0 max(FDts)+0.1]);
  217. else
  218. ylim([0 0.6]);
  219. end
  220. ylabel('FD (mm)','fontsize',lfs,'interpreter','latex','color','k');
  221. %axis tight;
  222. PatchMeUp(Idx,Thickness);
  223. set(sph0,'ygrid','on','xticklabel',[],'xlim',[1 T],'ytick',[0.2 0.5],'ycolor','k')
  224. if AbsMovflag
  225. yyaxis right
  226. mov1line=plot(Time,AbsMov(:,1),'color',FDcol+[0.1,0.3,0.3],'linestyle','-','linewidth',lw-0.9);
  227. mov2line=plot(Time,AbsMov(:,2),'color',FDcol+[0.1,0.5,0.5],'linestyle','-','linewidth',lw-0.9);
  228. axis tight
  229. ylabel('D (mm)','fontsize',lfs,'interpreter','latex');
  230. legend([FDline mov1line mov2line],{'FD','|Rotation|','|Translation|'},'location','northwest')
  231. else
  232. yyaxis right
  233. set(sph0,'yticklabel',[],'ycolor','k')
  234. end
  235. end
  236. %---------------------------Whole%---------------------------
  237. sph1=subplot(nsp,1,[3 11]);
  238. hold on; box on;
  239. %title('DSE Variance Decomposition (RMS units)','fontsize',13)
  240. yyaxis(sph1,'left')
  241. Aline = line(Time,sqrt(V.Avar_ts),'LineStyle','-','linewidth',lw,'color',Acol);
  242. line(Time,ones(1,T).*mean(sqrt(V.Avar_ts)),'LineStyle',':','linewidth',.5,'color',Acol)
  243. Dline = line(hTime,sqrt(V.Dvar_ts),'LineStyle','-','linewidth',lw,'color',Dcol);
  244. line(hTime,ones(1,T-1).*mean(sqrt(V.Dvar_ts)),'LineStyle',':','linewidth',.5,'color',Dcol)
  245. Sline = line(hTime,sqrt(V.Svar_ts),'LineStyle','-','linewidth',lw,'color',Scol);
  246. line(hTime,ones(1,T-1).*mean(sqrt(V.Svar_ts)),'LineStyle',':','linewidth',.5,'color',Scol)
  247. Edots = line(eTime,sqrt(V.Evar_ts),'LineStyle','none','Marker','o','markerfacecolor',Ecol,'linewidth',3,'color',Ecol);
  248. ylabel('$\sqrt{\mathrm{Variance}}$','fontsize',lfs,'interpreter','latex')
  249. YLim2 = ylim.^2/mean(V.Avar_ts)*100;
  250. set(sph1,'ycolor','k','xlim',[1 T])
  251. yyaxis(sph1,'right')
  252. YTick2 = PrettyTicks(YLim2,TickScaler); YTick=sqrt(YTick2);
  253. set(sph1,'XTick',[],'Ylim',sqrt(YLim2),'YTick',sqrt(YTick2),'YtickLabel',num2str([YTick2']));
  254. ylabel('\% of A-var','fontsize',lfs,'interpreter','latex')
  255. %set(sph2,'ygrid','on')
  256. h = abline('h',YTick);
  257. set(h,'linestyle','-','color',[.5 .5 .5]); %the grids!
  258. set(sph1,'ycolor','k','xlim',[1 T])
  259. h_Idx = PatchMeUp(Idx,Thickness);
  260. if isempty(Idx) %ED
  261. legend([Aline Dline Sline Edots],{'A-var','D-var','S-var','E-var'},'location','northwest') %ED
  262. else %ED
  263. legend([Aline Dline Sline Edots h_Idx(1)],{'A-var','D-var','S-var','E-var','Statistically Significant'},'location','northwest')
  264. end %ED
  265. %---------------------------Global%---------------------------
  266. % sph2=subplot(nsp,1,[12 13]);
  267. % hold on; box on;
  268. % %yyaxis(sph2,'left')
  269. % cntrd_g_ts=V.g_Ats+GrandMean;
  270. % plot(Time,cntrd_g_ts,'color',Acol,'linestyle','-','linewidth',lw);
  271. % %line(hTime,ones(1,T-1).*mean(V.g_Ats+mean(V.MeanOrig)),'LineStyle','-.','linewidth',.5,'color',Acol)
  272. %
  273. % %%%%%%%%%%%%%%%%%%%% Un-ccomment next 4 code lines if you need to see the gDvar and gSvar. %%%%%%%%%%%%%%%%%%%%
  274. % %plot(hTime,V.g_Dts+mean(V.MeanOrig),'color',Dcol,'linestyle','-','linewidth',lw);
  275. % %line(hTime,ones(1,T-1).*(mean(V.g_Dts)+mean(V.MeanOrig)),'LineStyle','-.','linewidth',.5,'color',Dcol)
  276. %
  277. % %plot(hTime,V.g_Sts+mean(V.MeanOrig),'color',Scol,'linestyle','-','linewidth',lw);
  278. % %line(hTime,ones(1,T-1).*(mean(V.g_Sts)+mean(V.MeanOrig)),'LineStyle','-.','linewidth',.5,'color',Scol)
  279. % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  280. %
  281. % mx_cntrd_g_ts=max(cntrd_g_ts); mn_cntrd_g_ts=min(cntrd_g_ts);
  282. % stps=abs(round(diff([mx_cntrd_g_ts mn_cntrd_g_ts])./3,1));
  283. % Ytcks=round(min(cntrd_g_ts):stps:max(cntrd_g_ts),2);
  284. %
  285. % ylabel('A$_{Gt}$','fontsize',lfs,'interpreter','latex')
  286. % %axis tight
  287. % %set(sph2,'ycolor','k')
  288. % %Ylim=ylim; Ylim=mean(Ylim)+0.5*[-1,1]*diff(Ylim)*2; ylim(Ylim)
  289. % %ylim_tmp=ylim; dylim_tmp=(ylim_tmp-mean(V.MeanOrig)); dylims_tmp=dylim_tmp./abs(dylim_tmp);
  290. % %YLim22=(dylim_tmp.^2/mean(V.Avar_ts));
  291. % %YLim22=((dylim_tmp.^2/mean(V.Avar_ts))-mean(YLim22))*100;
  292. % set(sph2,'ygrid','on','xlim',[1 T],'ycolor','k','yTick',Ytcks)
  293. % ytickformat('%,.2f')
  294. %
  295. % axis tight
  296. % PatchMeUp(Idx,Thickness);
  297. %---------------------------\Delta\%D-var---------------------------
  298. sph2=subplot(nsp,1,[12 13]);
  299. hold on; box on;
  300. %yyaxis(sph2,'left')
  301. plot(hTime,D_Stat.DeltapDvar,'color',Dcol,'linestyle','-','linewidth',lw);
  302. %line(hTime,ones(1,T-1).*psig,'LineStyle','-.','linewidth',.5,'color','r');
  303. %%%%%%%%%%%%%%%%%%%% Un-ccomment next 4 code lines if you need to see the gDvar and gSvar. %%%%%%%%%%%%%%%%%%%%
  304. %plot(hTime,V.g_Dts+mean(V.MeanOrig),'color',Dcol,'linestyle','-','linewidth',lw);
  305. %line(hTime,ones(1,T-1).*(mean(V.g_Dts)+mean(V.MeanOrig)),'LineStyle','-.','linewidth',.5,'color',Dcol)
  306. %plot(hTime,V.g_Sts+mean(V.MeanOrig),'color',Scol,'linestyle','-','linewidth',lw);
  307. %line(hTime,ones(1,T-1).*(mean(V.g_Sts)+mean(V.MeanOrig)),'LineStyle','-.','linewidth',.5,'color',Scol)
  308. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  309. mx_cntrd_g_ts = max(D_Stat.DeltapDvar); mn_cntrd_g_ts = min(D_Stat.DeltapDvar);
  310. stps = abs(round(diff([mx_cntrd_g_ts mn_cntrd_g_ts])./4.5));
  311. Ytcks = round(mn_cntrd_g_ts:stps:mx_cntrd_g_ts);
  312. ylabel('$\Delta\%D$-var','fontsize',lfs,'interpreter','latex')
  313. set(sph2,'ygrid','on','xlim',[1 T-1],'ycolor','k','yTick',Ytcks)
  314. %ytickformat('%,.2f')
  315. axis tight
  316. pIdx = find(D_Stat.DeltapDvar>psig);
  317. pIdx = intersect(Idx,pIdx); %only if they are statistically sig as well!
  318. h_pIdx=PatchMeUp(pIdx,Thickness,PsigCol);
  319. %h_Idx=PatchMeUp(setdiff(Idx,pIdx),Thickness);
  320. %legend([h_Idx(1) h_pIdx(1)],{'Statistically Significant','Practically Significant'},'location','northwest')
  321. if ~isempty(pIdx) % ED
  322. legend([h_pIdx(1)],{'Practically Significant'},'location','northwest')
  323. end
  324. %---------------------------The big dude%---------------------------
  325. if BOLDFlag
  326. Y = double(Y);
  327. if ~isnumeric(Y) && size(Y,1)<=size(Y,2); error('Unknown BOLD intensity image!'); end
  328. I0 = size(Y,1); T0 = size(Y,2);
  329. %Remove voxels of zeros/NaNs-----------------
  330. nan_idx = find(isnan(sum(Y,2)));
  331. zeros_idx = find(sum(Y,2)==0);
  332. idx = 1:I0;
  333. idx([nan_idx;zeros_idx]) = [];
  334. Y([nan_idx;zeros_idx],:) = [];
  335. I1 = size(Y,1); %update number of voxels
  336. if verbose; disp(['-Extra-cranial areas removed: ' num2str(size(Y,1)) 'x' num2str(size(Y,2))]); end;
  337. % Intensity Normalisation--------
  338. IntnstyScl = @(Y,md,scl) (Y./md)*scl;
  339. if ~isempty(scl) && isempty(md)
  340. md = median(mean(Y,2));
  341. Y = IntnstyScl(Y,md,scl);
  342. if verbose; disp(['-Intensity Normalised by ' num2str(scl) '&' num2str(md) '.']); end;
  343. elseif ~isempty(scl) && ~isempty(md)
  344. assert(md==1,'4D mean in scalling cannot be anything other than 1!')
  345. Y = IntnstyScl(Y,md,scl);
  346. if verbose; disp(['-Intensity Scaled by ' num2str(scl) '.']); end;
  347. elseif isempty(scl) && isempty(md)
  348. disp('-No normalisation/scaling has been set!')
  349. else
  350. error('Something is wrong with param re intensity normalisation')
  351. end
  352. %Centre the data-----------------------------
  353. mvY = mean(Y,2);
  354. dmeaner= repmat(mvY,[1,T0]);
  355. Y = Y-dmeaner; clear dmeaner
  356. if verbose; disp('-Data centred.'); end;
  357. %--------------------------------ONLY FOR TEST-----------------
  358. if gsrflag
  359. %gsrflag_lab={'GSR'};
  360. Y = fcn_GSR(Y);
  361. if verbose; disp('-Data GSRed.'); end;
  362. end
  363. %--------------------------------------------------------------
  364. sph3=subplot(nsp,1,[15 20]);
  365. hold on; box on;
  366. colormap(sph3,'gray');
  367. if noColRngflag
  368. imagesc(Y)
  369. else
  370. imagesc(Y,ColRng)
  371. end
  372. ylabel('Voxels','fontsize',lfs,'interpreter','latex')
  373. set(sph3,'xticklabel',[])
  374. axis tight
  375. end
  376. xlabel('Scans','fontsize',lfs,'interpreter','latex')
  377. set(gcf,'Color','w');
  378. %###################################################################################
  379. % function T=Ticks(Ys,sph)
  380. % % For a bunch of (Y-axis) values, find default tick locations
  381. % % Ys - cell array of vectors to plot
  382. % f=figure('visible','off');
  383. % plot(Ys{1})
  384. % hold on
  385. % for i=2:length(Ys)
  386. % plot(sph,Ys{i})
  387. % end
  388. % hold off
  389. % T=get(gca,'Ytick');
  390. % close(f)
  391. % return
  392. %###################################################################################
  393. function T=PrettyTicks(Lim,varargin)
  394. % For a given axis limit, find pretty tick spacing; assumes 50 is always
  395. % in the plot (i.e. that rounded integers are always appropriate)
  396. % Ylim - Y axis limts
  397. %
  398. % TEN & SA, 2017, UoW
  399. % srafyouni@gmail.com
  400. %
  401. MinTick=3; % Minimum number of tick locations
  402. if ~isempty(varargin)
  403. TickSp = [15 5 2.5 1 0.5 0.2]./varargin{1};
  404. elseif isempty(varargin)
  405. TickSp = [15 5 2.5 1 0.5 0.2];
  406. end
  407. ts=0;
  408. T=[];
  409. while length(T)<MinTick
  410. ts = ts+1;
  411. if ts>length(TickSp)
  412. break
  413. end
  414. TS=TickSp(ts);
  415. T = ceil(Lim(1)/TS)*TS : TS : floor(Lim(2)/TS)*TS;
  416. end
  417. return
  418. %###################################################################################
  419. function h=abline(a,b,varargin)
  420. % FORMAT h = abline(a,b,...)
  421. % Plots y=a+b*x in dotted line
  422. % FORMAT h = abline('h',y,...)
  423. % Plots a horizontal line at y; y can be a vector, & then multiple lines plotted
  424. % FORMAT h = abline('v',x,...)
  425. % Plots a vertical line at x; x can be a vector, & then multiple lines plotted
  426. %
  427. % ... Other graphics options, e.g. "'LineStyle','-'" or "'LineWidth',2" or
  428. % "'color',[1 0 0]", etc
  429. %
  430. % Like Splus' abline. Line is plotted and then moved behind all other
  431. % points on the graph.
  432. %
  433. % $Id: abline.m,v 1.1 2013/06/04 10:38:11 nichols Exp $
  434. if (nargin==2) && ischar(a)
  435. a = lower(a);
  436. else
  437. if (nargin<1)
  438. a = 0;
  439. end
  440. if (nargin<2)
  441. b = 0;
  442. end
  443. end
  444. XX=get(gca,'Xlim');
  445. YY=get(gca,'Ylim');
  446. h_exist = get(gca,'children');
  447. g = [];
  448. if ischar(a) && (a=='h')
  449. for i=1:length(b)
  450. g=[g;line(XX,[b(i) b(i)],'LineStyle',':',varargin{:})];
  451. end
  452. elseif ischar(a) && (a=='v')
  453. for i=1:length(b)
  454. g=[g;line([b(i) b(i)],YY,'LineStyle',':',varargin{:})];
  455. end
  456. else
  457. g=line(XX,a+b*XX,'LineStyle',':',varargin{:});
  458. end
  459. uistack(h_exist,'top');
  460. if (nargout>0)
  461. h=g;
  462. end
  463. set(gcf,'color','w');
  464. return
  465. %###################################################################################
  466. function ph=PatchMeUp(Idx,varargin)
  467. % Draws a patch across the significantly identified scans on var plots
  468. %
  469. % Internal function. Used in Diagnostics and DVARS plots.
  470. %
  471. % SA, 2017, UoW
  472. % srafyouni@gmail.com
  473. if nargin == 1
  474. stpjmp = 1;
  475. Lcol = [.5 .5 .5];
  476. elseif nargin == 2
  477. stpjmp = varargin{1};
  478. Lcol = [.5 .5 .5];
  479. elseif nargin == 3
  480. stpjmp = varargin{1};
  481. Lcol = varargin{2};
  482. end
  483. yyll=ylim;
  484. ph=[];%ED
  485. for ii=1:numel(Idx)
  486. xtmp=[Idx(ii)-stpjmp Idx(ii)-stpjmp Idx(ii)+stpjmp Idx(ii)+stpjmp];
  487. ytmp=[yyll(1) yyll(2) yyll(2) yyll(1) ];
  488. ph(ii)=patch(xtmp,ytmp,Lcol,'FaceAlpha',0.3,'edgecolor','none');
  489. clear *tmp
  490. end
  491. return
  492. %###################################################################################
  493. function gsrY=fcn_GSR(Y)
  494. %Global Signal Regression
  495. %Inspired by FSLnets
  496. %For the fMRIDiag, it needs to be transposed.
  497. %
  498. % SA, 2017, UoW
  499. % srafyouni@gmail.com
  500. %
  501. Y = Y';
  502. mgrot = mean(Y,2);
  503. gsrY = Y-(mgrot*(pinv(mgrot)*Y));
  504. gsrY = gsrY';