Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

rsfmri_metrics.m 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. function [mNetX,mNet_Trim,SW,CC,CPL] = rsfmri_metrics(TCfile,GSR_signal,AUC,cut,scratch,want2c,GSR)
  2. [matrix] = load(fullfile(TCfile.folder,TCfile.name));
  3. funcmat = double(matrix.matrix);
  4. ts.ts = funcmat;
  5. ts.tr = 2.48;
  6. ts.Nnodes = size(funcmat,2);
  7. ts.Ntimepoints = size(funcmat,1);
  8. ts.Nsubjects = 1;
  9. ts.NnodesOrig = ts.Nnodes;
  10. ts.NtimepointsPerSubject = size(funcmat,1);
  11. ts.DD = 1:ts.Nnodes;
  12. ts.UNK = [];
  13. ts_scrub = ts;
  14. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  15. if GSR==1
  16. % for rix = 1:ts.Nnodes
  17. % [~,~,Resid] = regress(funcmat(:,rix),GSR_signal);
  18. % funcmat_GSR(:,rix) = Resid';
  19. % end
  20. yadj = zeros(size(funcmat));
  21. X = detrend(GSR_signal,'constant');
  22. for v = 1:ts.Nnodes
  23. % b = regression(funcmat(:,v),X);
  24. [Q, R]=qr(X,0);
  25. b = R\(Q'*funcmat(:,v));
  26. yvoxmodel = b(1)*X(:,1);
  27. % Adjust time-series
  28. yadj(:,v) = funcmat(:,v) - yvoxmodel;
  29. end
  30. ts_scrub.ts = double(yadj);
  31. end
  32. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  33. if cut==1
  34. funcmat_scrub = ts_scrub.ts;
  35. funcmat_scrub(scratch,:) = [];
  36. ts_scrub.ts = funcmat_scrub;
  37. ts_scrub.Ntimepoints = size(funcmat_scrub,1);
  38. ts_scrub.NtimepointsPerSubject = size(funcmat_scrub,1);
  39. end
  40. netmats = nets_netmats_md(ts,1,0,'corr'); % correlation transformed 2 Z-scores
  41. mNet = reshape(netmats(1,:),[sqrt(length(netmats)) sqrt(length(netmats))]);
  42. netmats_scrub = nets_netmats_md(ts_scrub,1,0,'corr'); % correlation transformed 2 Z-scores
  43. mNet_scrub = reshape(netmats_scrub(1,:),[sqrt(length(netmats_scrub)) sqrt(length(netmats_scrub))]);
  44. mNetX = mNet_scrub;
  45. mNetTresh = zeros(98,98,AUC(end));
  46. CPLx = zeros(1,AUC(end));
  47. CCx = zeros(1,AUC(end));
  48. NCC = zeros(1,AUC(end));
  49. NCPL = zeros(1,AUC(end));
  50. SWx = zeros(1,AUC(end));
  51. f = waitbar(0,strcat('0/100'));
  52. for gi=AUC
  53. p=gi/100;
  54. waitbar(1i/100,f,num2str(gi),'/100');
  55. mNetD = threshold_proportional(mNetX,p);
  56. mNetTresh(:,:,gi) = mNetD;
  57. % mNetD(mNetD==0) = nan;
  58. mNetDWght = weight_conversion(mNetD,'normalize');
  59. mNetDBin = weight_conversion(mNetD,'binarize');
  60. % Eglob (gi) = efficiency_wei(mNetD); % global efficieny
  61. D = distance_wei_floyd(mNetDWght,'inv');
  62. Dx = distance_wei_floyd(mNetDBin,'inv');
  63. lambda = charpath(D,0,0);
  64. CPLx(gi) = lambda;
  65. cplb = charpath(Dx,0,0);
  66. clx = clustering_coef_wu(mNetDWght);
  67. CCx(gi) = squeeze(mean(clx));
  68. clb = clustering_coef_wu(mNetDBin);
  69. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  70. % small worldness density threshold
  71. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  72. % create random network to asses small worldness
  73. lambda_rdm = zeros(1,100);
  74. clcf_rdm = zeros(1,100);
  75. for k=1:100
  76. random = makerandCIJ_und(size(mNetD,1),nnz(mNetD)/2); % compute random network with same number of nodes and edges
  77. D_rdm = distance_bin(random);
  78. lambda_rdm(k) = charpath(D_rdm,0,0);
  79. clcf_rdm(k) = mean(clustering_coef_bu(random));
  80. end
  81. % small-worldness
  82. norm_clcf = abs(squeeze(mean(clb)))/abs(mean(clcf_rdm));
  83. NCC(gi) = norm_clcf;
  84. norm_lambda = (cplb/(mean(lambda_rdm)));
  85. NCPL(gi) = norm_lambda;
  86. SWx(gi) = norm_clcf/norm_lambda;
  87. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  88. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  89. end
  90. mNetTresh(mNetTresh==0)=nan;
  91. mNet_Trim = squeeze(mean(mNetTresh,3,'omitnan'));
  92. % for aucx = 1:length(AUC)
  93. % auc_value(auc) =
  94. CC = trapz (AUC, CCx(AUC))/length(AUC);
  95. CPL = trapz (AUC, CPLx(AUC))/length(AUC);
  96. SW = trapz (AUC, SWx(AUC))/length(AUC);
  97. F = findall(0,'type','figure','tag','TMWWaitbar');
  98. delete(F)
  99. %%
  100. if want2c ==1
  101. figure('units','normalized','outerposition',[0 0 1 1])
  102. subplot(131)
  103. plotmat_values_rsfMRI(mNet,[],[-1 1],0,[]);
  104. hold on
  105. axis square;
  106. plot(get(gca,'xlim'),[mean(get(gca,'ylim')), mean(get(gca,'ylim'))],'k-','linewidth',2);
  107. plot([mean(get(gca,'xlim')), mean(get(gca,'xlim'))], get(gca,'ylim'),'k-','linewidth',2);
  108. title('raw mNet')
  109. % % ntx = threshold_proportional(mNetX,median(AUC)/100);
  110. % % ntx(ntx==0)=nan;
  111. % % hx = histogram(ntx,'BinEdges',linspace(min(min(ntx)),max(max(ntx)),20),'Normalization','probability');
  112. subplot(132)
  113. plotmat_values_rsfMRI(mNet_scrub,[],[-1 1],0,[]);
  114. hold on
  115. axis square;
  116. plot(get(gca,'xlim'),[mean(get(gca,'ylim')), mean(get(gca,'ylim'))],'k-','linewidth',2);
  117. plot([mean(get(gca,'xlim')), mean(get(gca,'xlim'))], get(gca,'ylim'),'k-','linewidth',2);
  118. title('scratched mNet')
  119. mNetDelta = mNet - mNet_scrub;
  120. subplot(133)
  121. plotmat_values_rsfMRI(mNetDelta,[],[-.5 .5],0,[]);
  122. hold on
  123. axis square;
  124. plot(get(gca,'xlim'),[mean(get(gca,'ylim')), mean(get(gca,'ylim'))],'k-','linewidth',2);
  125. plot([mean(get(gca,'xlim')), mean(get(gca,'xlim'))], get(gca,'ylim'),'k-','linewidth',2);
  126. title('delta')
  127. %
  128. % figure('units','normalized','outerposition',[0 0 1 1])
  129. % tpx = linspace(10,90,5)
  130. % for histi = 1:5
  131. % ntx = threshold_proportional(mNetX,tpx(histi)/100);
  132. % ntx(ntx==0)=nan;
  133. % wbin = linspace(min(min(ntx)),max(max(ntx)),20);
  134. % subplot(1,5,histi)
  135. % hy = histogram(ntx,'Normalization','probability','BinEdges',wbin);
  136. % title(num2str(tpx(histi)))
  137. % ylim([0 0.2])
  138. % end
  139. %
  140. % %
  141. % pause(3)
  142. end
  143. % close all
  144. %%
  145. end
  146. % h = histogram(mNet,'Normalization','probability')