OSCR

Hypercapnia dissociates neuronal and hemodynamic responses impairing neurovascular coupling and functional brain connectivity.

Code ↔ Paper

1 match between paragraphs of the paper and lines of its authors' code, computed by the harvester (lexical-v1). Click a colored paragraph or line to see its counterpart.

The 1 match
  1. [1] § Methods › Dynamic functional connectivity analysis ↔ dfc_state_analysis.m, lines 864–924 · score 0.56 · cross correlation, state transition, lag, duration, dFC, window

Paper

Loaded from Europe PMC by your browser, not stored by OSCR: doi.org · Europe PMC

The paper is loaded when this pane is shown.

The authors' code

MATLAB · 1,383 lines · 67 KB · CC-BY-4.0 · 1 match

  1. close all; clc; clearvars;
  2. %% dFC state analysis: FL (10 Hz, 1 Hz), neural, and fMRI
  3. %
  4. % Required files in the working directory:
  5. % dFC_10Hz.mat
  6. % dFC_1Hz.mat
  7. % dFC_fMRI.mat
  8. % dFC_neural.mat
  9. %
  10. % Expected data dimensions: [num_regions x num_regions x num_windows x num_animals]
  11. %% Load data
  12. load('dFC_10Hz.mat');
  13. load('dFC_neural.mat');
  14. load('dFC_fMRI.mat');
  15. load('dFC_1Hz.mat');
  16. % Optional colormaps
  17. % cm_turbo_custom = load_colormap_safe('turbo_custom.mat', 'turbo_custom', parula(256));
  18. % cm_turbo_custom_endWhite = load_colormap_safe('turbo_custom_endWhite.mat', 'turbo_custom_endWhite', parula(256));
  19. % cm_custom_blueToRed = load_colormap_safe('custom_blueToRed.mat', 'custom_blueToRed', parula(256));
  20. % cm_custom_blue2red_2 = load_colormap_safe('custom_blue2red_2.mat', 'custom_blue2red_2', parula(256));
  21. rng('threefry');
  22. %% Parameters
  23. num_regions = size(dFC_10Hz, 1);
  24. num_animals = size(dFC_10Hz, 4);
  25. num_replicates = 20;
  26. max_clusters = 10;
  27. window_size_10Hz = 300;
  28. step_size_10Hz = 10;
  29. window_size_fMRI = 30;
  30. step_size_fMRI = 1;
  31. window_size_1Hz = 30;
  32. step_size_1Hz = 1;
  33. sampling_rate_10Hz = 10;
  34. sampling_rate_fMRI = 1;
  35. sampling_rate_1Hz = 1;
  36. num_windows_neural = size(dFC_neural, 3);
  37. num_windows_fMRI = size(dFC_fMRI, 3);
  38. num_windows_10Hz = size(dFC_10Hz, 3);
  39. num_windows_1Hz = size(dFC_1Hz, 3);
  40. optimal_num_clusters_combined = 6;
  41. optimal_num_clusters_fMRI = 5;
  42. % Region re-ordering for visualization
  43. new_order = [1:10, 11, 23, 12:15, 24, 16, 17, 18, 19, 20, 21, 22, 25, ...
  44. 26:35, 36, 48, 37:40, 49, 41, 42, 43, 44, 45, 46, 47, 50];
  45. %% CO2 timing
  46. % Start indices are subject-specific only for subject 3.
  47. co2_on_periods = [175, 535];
  48. co2_on_periods_sub3 = [235, 595];
  49. co2_duration = 165; % chosen analysis duration after accounting for windowing
  50. co2_on_duration_fMRI = co2_duration;
  51. co2_on_indices_10Hz = round(co2_on_periods * sampling_rate_10Hz / step_size_10Hz);
  52. co2_on_indices_10Hz_sub3 = round(co2_on_periods_sub3 * sampling_rate_10Hz / step_size_10Hz);
  53. co2_on_indices_fMRI = round(co2_on_periods * sampling_rate_fMRI / step_size_fMRI);
  54. co2_on_indices_fMRI_sub3 = round(co2_on_periods_sub3 * sampling_rate_fMRI / step_size_fMRI);
  55. co2_on_indices_1Hz = round(co2_on_periods * sampling_rate_1Hz / step_size_1Hz);
  56. co2_on_indices_1Hz_sub3 = round(co2_on_periods_sub3 * sampling_rate_1Hz / step_size_1Hz);
  57. %% Reshape data for clustering
  58. hemodynamic_10Hz_data = reshape(dFC_10Hz, num_regions * num_regions, [])';
  59. hemodynamic_1Hz_data = reshape(dFC_1Hz, num_regions * num_regions, [])';
  60. combined_hemodynamic_data = [hemodynamic_10Hz_data; hemodynamic_1Hz_data];
  61. fMRI_data = reshape(dFC_fMRI, num_regions * num_regions, [])';
  62. neural_data = reshape(dFC_neural, num_regions * num_regions, [])';
  63. %% K-means clustering
  64. rng('philox');
  65. [idx_combined, centroids_combined] = kmeans(combined_hemodynamic_data, ...
  66. optimal_num_clusters_combined, 'Replicates', num_replicates);
  67. idx_10Hz = reshape(idx_combined(1:size(hemodynamic_10Hz_data, 1)), num_windows_10Hz, num_animals);
  68. idx_1Hz = reshape(idx_combined(size(hemodynamic_10Hz_data, 1) + 1:end), num_windows_1Hz, num_animals);
  69. rng('philox');
  70. [idx_fMRI, centroids_fMRI] = kmeans(fMRI_data, optimal_num_clusters_fMRI, ...
  71. 'Replicates', num_replicates);
  72. idx_fMRI = reshape(idx_fMRI, num_windows_fMRI, num_animals);
  73. %% Remove states observed in only one subject, then fill missing labels by nearest centroid
  74. [idx_10Hz, removed_states_10Hz] = remove_single_subject_states(idx_10Hz);
  75. [idx_1Hz, removed_states_1Hz] = remove_single_subject_states(idx_1Hz);
  76. [idx_fMRI, removed_states_fMRI] = remove_single_subject_states(idx_fMRI);
  77. if ~isempty(removed_states_10Hz)
  78. fprintf('FL 10 Hz states removed for single-subject occurrence: %s\n', mat2str(removed_states_10Hz));
  79. end
  80. if ~isempty(removed_states_1Hz)
  81. fprintf('FL 1 Hz states removed for single-subject occurrence: %s\n', mat2str(removed_states_1Hz));
  82. end
  83. if ~isempty(removed_states_fMRI)
  84. fprintf('fMRI states removed for single-subject occurrence: %s\n', mat2str(removed_states_fMRI));
  85. end
  86. distance_matrix_combined = pdist2(centroids_combined, centroids_combined);
  87. distance_matrix_fMRI = pdist2(centroids_fMRI, centroids_fMRI);
  88. idx_10Hz = replace_nan_states_with_closest(idx_10Hz, distance_matrix_combined);
  89. idx_1Hz = replace_nan_states_with_closest(idx_1Hz, distance_matrix_combined);
  90. idx_fMRI = replace_nan_states_with_closest(idx_fMRI, distance_matrix_fMRI);
  91. %% Plot identified state centroids and mean neural dFC
  92. neural_plot = mean(dFC_neural, [3 4]);
  93. neural_2plot = neural_plot(new_order, new_order);
  94. figure('Position', [100 100 500 900]);
  95. for k = 1:optimal_num_clusters_combined
  96. FL_plot = reshape(centroids_combined(k, :), num_regions, num_regions);
  97. FL_2plot = FL_plot(new_order, new_order);
  98. subplot(ceil(optimal_num_clusters_combined / 2), 2, k);
  99. imagesc(FL_2plot);
  100. axis square;
  101. caxis([-1 1]);
  102. colormap(parula);
  103. title(sprintf('Identified State %d - FL', k));
  104. xlabel('Region'); ylabel('Region');
  105. end
  106. figure('Position', [100 100 500 900]);
  107. for k = 1:optimal_num_clusters_fMRI
  108. fMRI_plot = reshape(centroids_fMRI(k, :), num_regions, num_regions);
  109. fMRI_2plot = fMRI_plot(new_order, new_order);
  110. subplot(ceil(optimal_num_clusters_fMRI / 2), 2, k);
  111. imagesc(fMRI_2plot);
  112. axis square;
  113. caxis([-0.4 0.4]);
  114. colorbar;
  115. colormap(parula);
  116. title(sprintf('Identified State %d - fMRI', k));
  117. xlabel('Region'); ylabel('Region');
  118. end
  119. figure;
  120. imagesc(neural_2plot);
  121. axis square;
  122. colorbar;
  123. caxis([-1 1]);
  124. colormap(parula);
  125. title('Mean neural dFC');
  126. xlabel('Region'); ylabel('Region');
  127. %% Compare hemodynamic state centroids with neural dFC windows
  128. state_neural_similarity_combined = nan(optimal_num_clusters_combined, num_animals);
  129. state_neural_similarity_fMRI = nan(optimal_num_clusters_fMRI, num_animals);
  130. for k = 1:optimal_num_clusters_combined
  131. hemo_state = centroids_combined(k, :);
  132. for animal = 1:num_animals
  133. neural_dFC = neural_data((animal - 1) * num_windows_neural + (1:num_windows_neural), :);
  134. state_neural_similarity_combined(k, animal) = mean(corr(hemo_state', neural_dFC', 'Rows', 'pairwise'));
  135. end
  136. end
  137. for k = 1:optimal_num_clusters_fMRI
  138. hemo_state = centroids_fMRI(k, :);
  139. for animal = 1:num_animals
  140. neural_dFC = neural_data((animal - 1) * num_windows_neural + (1:num_windows_neural), :);
  141. state_neural_similarity_fMRI(k, animal) = mean(corr(hemo_state', neural_dFC', 'Rows', 'pairwise'));
  142. end
  143. end
  144. figure;
  145. subplot(2, 1, 1);
  146. imagesc(state_neural_similarity_combined);
  147. colorbar;
  148. colormap(cm_turbo_custom);
  149. clim([0.25 0.85]);
  150. title('Similarity between FL states and neural dFC windows');
  151. xlabel('Animal'); ylabel('FL state');
  152. subplot(2, 1, 2);
  153. imagesc(state_neural_similarity_fMRI);
  154. colorbar;
  155. colormap(cm_turbo_custom);
  156. clim([0.3 0.6]);
  157. title('Similarity between fMRI states and neural dFC windows');
  158. xlabel('Animal'); ylabel('fMRI state');
  159. add_jitter = @(values, scale) values + scale * (rand(size(values)) - 0.5);
  160. jitter_scale = 0.1;
  161. colors = lines(num_animals);
  162. figure('Position', [100, 100, 1000, 800]);
  163. subplot(2, 1, 1); hold on;
  164. for animal = 1:num_animals
  165. y_values = state_neural_similarity_combined(:, animal);
  166. x_values = 1:length(y_values);
  167. scatter(add_jitter(x_values, jitter_scale), y_values, 50, colors(animal, :), ...
  168. 'filled', 'DisplayName', sprintf('Animal %d', animal));
  169. end
  170. mean_values_combined = mean(state_neural_similarity_combined, 2, 'omitnan');
  171. for state = 1:length(mean_values_combined)
  172. plot([state - 0.4, state + 0.4], [mean_values_combined(state), mean_values_combined(state)], 'k-', 'LineWidth', 2);
  173. end
  174. title('FL state similarity to neural dFC windows');
  175. xlabel('FL state'); ylabel('Similarity'); legend('show', 'Location', 'eastoutside'); grid on; hold off;
  176. subplot(2, 1, 2); hold on;
  177. for animal = 1:num_animals
  178. y_values = state_neural_similarity_fMRI(:, animal);
  179. x_values = 1:length(y_values);
  180. scatter(add_jitter(x_values, jitter_scale), y_values, 50, colors(animal, :), ...
  181. 'filled', 'DisplayName', sprintf('Animal %d', animal));
  182. end
  183. mean_values_fMRI = mean(state_neural_similarity_fMRI, 2, 'omitnan');
  184. for state = 1:length(mean_values_fMRI)
  185. plot([state - 0.4, state + 0.4], [mean_values_fMRI(state), mean_values_fMRI(state)], 'k-', 'LineWidth', 2);
  186. end
  187. title('fMRI state similarity to neural dFC windows');
  188. xlabel('fMRI state'); ylabel('Similarity'); legend('show', 'Location', 'eastoutside'); grid on; hold off;
  189. %% Similarity between FL and fMRI state centroids
  190. similarity_fMRI_combined = corr(centroids_fMRI', centroids_combined', 'Rows', 'pairwise');
  191. similarity_fMRI_states = corr(centroids_fMRI', 'Rows', 'pairwise');
  192. similarity_FL_states = corr(centroids_combined', 'Rows', 'pairwise');
  193. figure;
  194. imagesc(similarity_fMRI_combined);
  195. colorbar;
  196. colormap(cm_turbo_custom);
  197. title('Similarity between fMRI states and FL states');
  198. xlabel('FL state'); ylabel('fMRI state');
  199. figure;
  200. imagesc(similarity_fMRI_states);
  201. colorbar;
  202. colormap(cm_turbo_custom_endWhite);
  203. caxis([0.65 0.9]);
  204. title('Similarity between fMRI states');
  205. xlabel('fMRI state'); ylabel('fMRI state');
  206. figure;
  207. imagesc(similarity_FL_states);
  208. colorbar;
  209. colormap(cm_turbo_custom_endWhite);
  210. caxis([0.6 0.96]);
  211. title('Similarity between FL states');
  212. xlabel('FL state'); ylabel('FL state');
  213. %% State distributions and transition matrices during CO2 on/off
  214. state_dist_10Hz_on = zeros(optimal_num_clusters_combined, num_animals);
  215. state_dist_10Hz_off = zeros(optimal_num_clusters_combined, num_animals);
  216. state_dist_1Hz_on = zeros(optimal_num_clusters_combined, num_animals);
  217. state_dist_1Hz_off = zeros(optimal_num_clusters_combined, num_animals);
  218. state_dist_fMRI_on = zeros(optimal_num_clusters_fMRI, num_animals);
  219. state_dist_fMRI_off = zeros(optimal_num_clusters_fMRI, num_animals);
  220. trans_mat_fMRI_on = zeros(optimal_num_clusters_fMRI, optimal_num_clusters_fMRI, num_animals);
  221. trans_mat_fMRI_off = zeros(optimal_num_clusters_fMRI, optimal_num_clusters_fMRI, num_animals);
  222. trans_mat_10Hz_on = zeros(optimal_num_clusters_combined, optimal_num_clusters_combined, num_animals);
  223. trans_mat_10Hz_off = zeros(optimal_num_clusters_combined, optimal_num_clusters_combined, num_animals);
  224. trans_mat_1Hz_on = zeros(optimal_num_clusters_combined, optimal_num_clusters_combined, num_animals);
  225. trans_mat_1Hz_off = zeros(optimal_num_clusters_combined, optimal_num_clusters_combined, num_animals);
  226. for animal = 1:num_animals
  227. [starts_10Hz, starts_1Hz, starts_fMRI] = get_co2_start_indices_for_animal(animal, ...
  228. co2_on_indices_10Hz, co2_on_indices_10Hz_sub3, ...
  229. co2_on_indices_1Hz, co2_on_indices_1Hz_sub3, ...
  230. co2_on_indices_fMRI, co2_on_indices_fMRI_sub3);
  231. ends_10Hz = starts_10Hz + co2_duration;
  232. ends_1Hz = starts_1Hz + co2_duration;
  233. ends_fMRI = starts_fMRI + co2_duration;
  234. off_starts_fMRI = [1, ends_fMRI + window_size_fMRI / 2];
  235. off_ends_fMRI = [starts_fMRI - window_size_fMRI / 2, num_windows_fMRI];
  236. off_starts_10Hz = [1, ends_10Hz + window_size_10Hz / sampling_rate_10Hz / 2];
  237. off_ends_10Hz = [starts_10Hz - window_size_10Hz / sampling_rate_10Hz / 2, num_windows_10Hz];
  238. off_starts_1Hz = [1, ends_1Hz + window_size_1Hz / 2];
  239. off_ends_1Hz = [starts_1Hz - window_size_1Hz / 2, num_windows_1Hz];
  240. % CO2-on state counts and transitions
  241. for cycle = 1:length(starts_10Hz)
  242. state_dist_10Hz_on(:, animal) = state_dist_10Hz_on(:, animal) + count_states_in_range(idx_10Hz(:, animal), starts_10Hz(cycle), min(ends_10Hz(cycle), num_windows_10Hz), optimal_num_clusters_combined);
  243. state_dist_1Hz_on(:, animal) = state_dist_1Hz_on(:, animal) + count_states_in_range(idx_1Hz(:, animal), starts_1Hz(cycle), min(ends_1Hz(cycle), num_windows_1Hz), optimal_num_clusters_combined);
  244. state_dist_fMRI_on(:, animal) = state_dist_fMRI_on(:, animal) + count_states_in_range(idx_fMRI(:, animal), starts_fMRI(cycle), min(ends_fMRI(cycle), num_windows_fMRI), optimal_num_clusters_fMRI);
  245. trans_mat_10Hz_on(:, :, animal) = trans_mat_10Hz_on(:, :, animal) + count_transitions_in_range(idx_10Hz(:, animal), starts_10Hz(cycle), min(ends_10Hz(cycle), num_windows_10Hz), optimal_num_clusters_combined);
  246. trans_mat_1Hz_on(:, :, animal) = trans_mat_1Hz_on(:, :, animal) + count_transitions_in_range(idx_1Hz(:, animal), starts_1Hz(cycle), min(ends_1Hz(cycle), num_windows_1Hz), optimal_num_clusters_combined);
  247. trans_mat_fMRI_on(:, :, animal) = trans_mat_fMRI_on(:, :, animal) + count_transitions_in_range(idx_fMRI(:, animal), starts_fMRI(cycle), min(ends_fMRI(cycle), num_windows_fMRI), optimal_num_clusters_fMRI);
  248. end
  249. % CO2-off state counts and transitions
  250. for cycle = 1:length(off_starts_10Hz)
  251. state_dist_10Hz_off(:, animal) = state_dist_10Hz_off(:, animal) + count_states_in_range(idx_10Hz(:, animal), max(1, round(off_starts_10Hz(cycle))), min(round(off_ends_10Hz(cycle)), num_windows_10Hz), optimal_num_clusters_combined);
  252. state_dist_1Hz_off(:, animal) = state_dist_1Hz_off(:, animal) + count_states_in_range(idx_1Hz(:, animal), max(1, round(off_starts_1Hz(cycle))), min(round(off_ends_1Hz(cycle)), num_windows_1Hz), optimal_num_clusters_combined);
  253. state_dist_fMRI_off(:, animal) = state_dist_fMRI_off(:, animal) + count_states_in_range(idx_fMRI(:, animal), max(1, round(off_starts_fMRI(cycle))), min(round(off_ends_fMRI(cycle)), num_windows_fMRI), optimal_num_clusters_fMRI);
  254. trans_mat_10Hz_off(:, :, animal) = trans_mat_10Hz_off(:, :, animal) + count_transitions_in_range(idx_10Hz(:, animal), max(1, round(off_starts_10Hz(cycle))), min(round(off_ends_10Hz(cycle)), num_windows_10Hz), optimal_num_clusters_combined);
  255. trans_mat_1Hz_off(:, :, animal) = trans_mat_1Hz_off(:, :, animal) + count_transitions_in_range(idx_1Hz(:, animal), max(1, round(off_starts_1Hz(cycle))), min(round(off_ends_1Hz(cycle)), num_windows_1Hz), optimal_num_clusters_combined);
  256. trans_mat_fMRI_off(:, :, animal) = trans_mat_fMRI_off(:, :, animal) + count_transitions_in_range(idx_fMRI(:, animal), max(1, round(off_starts_fMRI(cycle))), min(round(off_ends_fMRI(cycle)), num_windows_fMRI), optimal_num_clusters_fMRI);
  257. end
  258. end
  259. % Normalize per animal
  260. state_dist_10Hz_on = normalize_columns(state_dist_10Hz_on);
  261. state_dist_10Hz_off = normalize_columns(state_dist_10Hz_off);
  262. state_dist_1Hz_on = normalize_columns(state_dist_1Hz_on);
  263. state_dist_1Hz_off = normalize_columns(state_dist_1Hz_off);
  264. state_dist_fMRI_on = normalize_columns(state_dist_fMRI_on);
  265. state_dist_fMRI_off = normalize_columns(state_dist_fMRI_off);
  266. mean_state_dist_10Hz_on = mean(state_dist_10Hz_on, 2, 'omitnan');
  267. mean_state_dist_10Hz_off = mean(state_dist_10Hz_off, 2, 'omitnan');
  268. mean_state_dist_1Hz_on = mean(state_dist_1Hz_on, 2, 'omitnan');
  269. mean_state_dist_1Hz_off = mean(state_dist_1Hz_off, 2, 'omitnan');
  270. mean_state_dist_fMRI_on = mean(state_dist_fMRI_on, 2, 'omitnan');
  271. mean_state_dist_fMRI_off = mean(state_dist_fMRI_off, 2, 'omitnan');
  272. sem_state_dist_10Hz_on = std(state_dist_10Hz_on, 0, 2, 'omitnan') / sqrt(num_animals);
  273. sem_state_dist_10Hz_off = std(state_dist_10Hz_off, 0, 2, 'omitnan') / sqrt(num_animals);
  274. sem_state_dist_1Hz_on = std(state_dist_1Hz_on, 0, 2, 'omitnan') / sqrt(num_animals);
  275. sem_state_dist_1Hz_off = std(state_dist_1Hz_off, 0, 2, 'omitnan') / sqrt(num_animals);
  276. sem_state_dist_fMRI_on = std(state_dist_fMRI_on, 0, 2, 'omitnan') / sqrt(num_animals);
  277. sem_state_dist_fMRI_off = std(state_dist_fMRI_off, 0, 2, 'omitnan') / sqrt(num_animals);
  278. p_values_state_10Hz = nan(optimal_num_clusters_combined, 1);
  279. p_values_state_1Hz = nan(optimal_num_clusters_combined, 1);
  280. p_values_state_fMRI = nan(optimal_num_clusters_fMRI, 1);
  281. for i = 1:optimal_num_clusters_combined
  282. p_values_state_10Hz(i) = safe_paired_ttest(state_dist_10Hz_on(i, :), state_dist_10Hz_off(i, :));
  283. p_values_state_1Hz(i) = safe_paired_ttest(state_dist_1Hz_on(i, :), state_dist_1Hz_off(i, :));
  284. end
  285. for i = 1:optimal_num_clusters_fMRI
  286. p_values_state_fMRI(i) = safe_paired_ttest(state_dist_fMRI_on(i, :), state_dist_fMRI_off(i, :));
  287. end
  288. fprintf('P-values for state distributions - FL 10 Hz:\n'); disp(p_values_state_10Hz);
  289. fprintf('P-values for state distributions - FL 1 Hz:\n'); disp(p_values_state_1Hz);
  290. fprintf('P-values for state distributions - fMRI:\n'); disp(p_values_state_fMRI);
  291. figure('Position', [0 0 400 900]);
  292. plot_grouped_bars_with_paired_points(3, 1, 1, mean_state_dist_10Hz_on, mean_state_dist_10Hz_off, sem_state_dist_10Hz_on, sem_state_dist_10Hz_off, state_dist_10Hz_on, state_dist_10Hz_off, 'State Distribution - FL 10 Hz', 'Proportion', 1:optimal_num_clusters_combined, [0 0.68]);
  293. plot_grouped_bars_with_paired_points(3, 1, 2, mean_state_dist_1Hz_on, mean_state_dist_1Hz_off, sem_state_dist_1Hz_on, sem_state_dist_1Hz_off, state_dist_1Hz_on, state_dist_1Hz_off, 'State Distribution - FL 1 Hz', 'Proportion', 1:optimal_num_clusters_combined, [0 0.38]);
  294. plot_grouped_bars_with_paired_points(3, 1, 3, mean_state_dist_fMRI_on, mean_state_dist_fMRI_off, sem_state_dist_fMRI_on, sem_state_dist_fMRI_off, state_dist_fMRI_on, state_dist_fMRI_off, 'State Distribution - fMRI', 'Proportion', 1:optimal_num_clusters_fMRI, [0 0.83]);
  295. sgtitle('State distributions for FL 10 Hz, FL 1 Hz, and fMRI (CO2 on/off)');
  296. %% Transition probability matrices
  297. trans_matrix_10Hz = trans_mat_10Hz_on + trans_mat_10Hz_off;
  298. trans_matrix_1Hz = trans_mat_1Hz_on + trans_mat_1Hz_off;
  299. trans_matrix_fMRI = trans_mat_fMRI_on + trans_mat_fMRI_off;
  300. trans_prob_10Hz = normalize_transition_tensor(trans_matrix_10Hz);
  301. trans_prob_10Hz_on = normalize_transition_tensor(trans_mat_10Hz_on);
  302. trans_prob_10Hz_off = normalize_transition_tensor(trans_mat_10Hz_off);
  303. trans_prob_1Hz = normalize_transition_tensor(trans_matrix_1Hz);
  304. trans_prob_1Hz_on = normalize_transition_tensor(trans_mat_1Hz_on);
  305. trans_prob_1Hz_off = normalize_transition_tensor(trans_mat_1Hz_off);
  306. trans_prob_fMRI = normalize_transition_tensor(trans_matrix_fMRI);
  307. trans_prob_fMRI_on = normalize_transition_tensor(trans_mat_fMRI_on);
  308. trans_prob_fMRI_off = normalize_transition_tensor(trans_mat_fMRI_off);
  309. avg_trans_mat_10Hz_on = mean(trans_prob_10Hz_on, 3, 'omitnan');
  310. avg_trans_mat_10Hz_off = mean(trans_prob_10Hz_off, 3, 'omitnan');
  311. avg_trans_mat_1Hz_on = mean(trans_prob_1Hz_on, 3, 'omitnan');
  312. avg_trans_mat_1Hz_off = mean(trans_prob_1Hz_off, 3, 'omitnan');
  313. avg_trans_mat_fMRI_on = mean(trans_prob_fMRI_on, 3, 'omitnan');
  314. avg_trans_mat_fMRI_off = mean(trans_prob_fMRI_off, 3, 'omitnan');
  315. p_values_trans_10Hz = nan(optimal_num_clusters_combined, optimal_num_clusters_combined);
  316. p_values_trans_1Hz = nan(optimal_num_clusters_combined, optimal_num_clusters_combined);
  317. p_values_trans_fMRI = nan(optimal_num_clusters_fMRI, optimal_num_clusters_fMRI);
  318. for i = 1:optimal_num_clusters_combined
  319. for j = 1:optimal_num_clusters_combined
  320. p_values_trans_10Hz(i, j) = safe_paired_ttest(squeeze(trans_prob_10Hz_on(i, j, :)), squeeze(trans_prob_10Hz_off(i, j, :)));
  321. p_values_trans_1Hz(i, j) = safe_paired_ttest(squeeze(trans_prob_1Hz_on(i, j, :)), squeeze(trans_prob_1Hz_off(i, j, :)));
  322. end
  323. end
  324. for i = 1:optimal_num_clusters_fMRI
  325. for j = 1:optimal_num_clusters_fMRI
  326. p_values_trans_fMRI(i, j) = safe_paired_ttest(squeeze(trans_prob_fMRI_on(i, j, :)), squeeze(trans_prob_fMRI_off(i, j, :)));
  327. end
  328. end
  329. fprintf('P-values for transition probabilities - FL 10 Hz:\n'); disp(p_values_trans_10Hz);
  330. fprintf('P-values for transition probabilities - FL 1 Hz:\n'); disp(p_values_trans_1Hz);
  331. fprintf('P-values for transition probabilities - fMRI:\n'); disp(p_values_trans_fMRI);
  332. figure;
  333. threshold_transition = 0.05;
  334. plot_transition_matrix_with_sig(3, 2, 1, avg_trans_mat_10Hz_on, p_values_trans_10Hz, threshold_transition, 'Average Transition Matrix - FL 10 Hz (CO2 On)', 'Next State', 'Current State', [-0.01 0.9], cm_custom_blueToRed);
  335. plot_transition_matrix_with_sig(3, 2, 2, avg_trans_mat_10Hz_off, p_values_trans_10Hz, threshold_transition, 'Average Transition Matrix - FL 10 Hz (CO2 Off)', 'Next State', 'Current State', [-0.01 0.9], cm_custom_blueToRed);
  336. plot_transition_matrix_with_sig(3, 2, 3, avg_trans_mat_1Hz_on, p_values_trans_1Hz, threshold_transition, 'Average Transition Matrix - FL 1 Hz (CO2 On)', 'Next State', 'Current State', [-0.01 0.9], cm_custom_blueToRed);
  337. plot_transition_matrix_with_sig(3, 2, 4, avg_trans_mat_1Hz_off, p_values_trans_1Hz, threshold_transition, 'Average Transition Matrix - FL 1 Hz (CO2 Off)', 'Next State', 'Current State', [-0.01 0.9], cm_custom_blueToRed);
  338. plot_transition_matrix_with_sig(3, 2, 5, avg_trans_mat_fMRI_on, p_values_trans_fMRI, threshold_transition, 'Average Transition Matrix - fMRI (CO2 On)', 'Next State', 'Current State', [-0.02 0.9], cm_custom_blueToRed);
  339. plot_transition_matrix_with_sig(3, 2, 6, avg_trans_mat_fMRI_off, p_values_trans_fMRI, threshold_transition, 'Average Transition Matrix - fMRI (CO2 Off)', 'Next State', 'Current State', [-0.02 0.9], cm_custom_blueToRed);
  340. sgtitle('Average transition matrices for FL 10 Hz, FL 1 Hz, and fMRI (CO2 on/off)');
  341. %% Joint FL-fMRI state distributions (overall)
  342. count_10Hz_fMRI = zeros(optimal_num_clusters_combined, optimal_num_clusters_fMRI);
  343. count_1Hz_fMRI = zeros(optimal_num_clusters_combined, optimal_num_clusters_fMRI);
  344. count_fMRI_10Hz = zeros(optimal_num_clusters_fMRI, optimal_num_clusters_combined);
  345. count_fMRI_1Hz = zeros(optimal_num_clusters_fMRI, optimal_num_clusters_combined);
  346. for animal = 1:num_animals
  347. for t = 1:num_windows_fMRI
  348. f_state = idx_fMRI(t, animal);
  349. if t <= num_windows_10Hz
  350. fl10_state = idx_10Hz(t, animal);
  351. count_10Hz_fMRI(fl10_state, f_state) = count_10Hz_fMRI(fl10_state, f_state) + 1;
  352. end
  353. if t <= num_windows_1Hz
  354. fl1_state = idx_1Hz(t, animal);
  355. count_1Hz_fMRI(fl1_state, f_state) = count_1Hz_fMRI(fl1_state, f_state) + 1;
  356. end
  357. end
  358. for t = 1:num_windows_10Hz
  359. fl10_state = idx_10Hz(t, animal);
  360. if t <= num_windows_fMRI
  361. f_state = idx_fMRI(t, animal);
  362. count_fMRI_10Hz(f_state, fl10_state) = count_fMRI_10Hz(f_state, fl10_state) + 1;
  363. end
  364. end
  365. for t = 1:num_windows_1Hz
  366. fl1_state = idx_1Hz(t, animal);
  367. if t <= num_windows_fMRI
  368. f_state = idx_fMRI(t, animal);
  369. count_fMRI_1Hz(f_state, fl1_state) = count_fMRI_1Hz(f_state, fl1_state) + 1;
  370. end
  371. end
  372. end
  373. percent_10Hz_fMRI = safe_percent_by_column(count_10Hz_fMRI);
  374. percent_1Hz_fMRI = safe_percent_by_column(count_1Hz_fMRI);
  375. percent_fMRI_10Hz = safe_percent_by_column(count_fMRI_10Hz);
  376. percent_fMRI_1Hz = safe_percent_by_column(count_fMRI_1Hz);
  377. ulim = 40;
  378. figure;
  379. subplot(1, 2, 1); imagesc(percent_10Hz_fMRI); colorbar; axis square; colormap(cm_turbo_custom); caxis([0 ulim]); title('Percentage distribution of 10 Hz FL states by fMRI state'); xlabel('fMRI State'); ylabel('10 Hz FL State');
  380. subplot(1, 2, 2); imagesc(percent_1Hz_fMRI); colorbar; axis square; colormap(cm_turbo_custom); caxis([0 ulim]); title('Percentage distribution of 1 Hz FL states by fMRI state'); xlabel('fMRI State'); ylabel('1 Hz FL State');
  381. figure;
  382. subplot(1, 2, 1); imagesc(percent_fMRI_10Hz); colorbar; axis square; colormap(cm_turbo_custom); caxis([0 ulim]); title('Percentage distribution of fMRI states by 10 Hz FL state'); xlabel('10 Hz FL State'); ylabel('fMRI State');
  383. subplot(1, 2, 2); imagesc(percent_fMRI_1Hz); colorbar; axis square; colormap(cm_turbo_custom); caxis([0 ulim]); title('Percentage distribution of fMRI states by 1 Hz FL state'); xlabel('1 Hz FL State'); ylabel('fMRI State');
  384. %% Joint FL-fMRI state distributions by CO2 condition (10 Hz FL, fMRI)
  385. count_10Hz_fMRI_on = zeros(optimal_num_clusters_combined, optimal_num_clusters_fMRI, num_animals);
  386. count_10Hz_fMRI_off = zeros(optimal_num_clusters_combined, optimal_num_clusters_fMRI, num_animals);
  387. count_fMRI_10Hz_on = zeros(optimal_num_clusters_fMRI, optimal_num_clusters_combined, num_animals);
  388. count_fMRI_10Hz_off = zeros(optimal_num_clusters_fMRI, optimal_num_clusters_combined, num_animals);
  389. for animal = 1:num_animals
  390. [starts_10Hz, ~, starts_fMRI] = get_co2_start_indices_for_animal(animal, ...
  391. co2_on_indices_10Hz, co2_on_indices_10Hz_sub3, ...
  392. co2_on_indices_1Hz, co2_on_indices_1Hz_sub3, ...
  393. co2_on_indices_fMRI, co2_on_indices_fMRI_sub3);
  394. timing_info_fMRI = build_timing_mask(num_windows_fMRI, starts_fMRI, starts_fMRI + co2_duration);
  395. timing_info_10Hz = build_timing_mask(num_windows_10Hz, starts_10Hz, starts_10Hz + co2_duration);
  396. for t = 1:num_windows_fMRI
  397. f_state = idx_fMRI(t, animal);
  398. if t <= num_windows_10Hz
  399. fl_state = idx_10Hz(t, animal);
  400. if timing_info_10Hz(t)
  401. count_10Hz_fMRI_on(fl_state, f_state, animal) = count_10Hz_fMRI_on(fl_state, f_state, animal) + 1;
  402. else
  403. count_10Hz_fMRI_off(fl_state, f_state, animal) = count_10Hz_fMRI_off(fl_state, f_state, animal) + 1;
  404. end
  405. end
  406. end
  407. for t = 1:num_windows_10Hz
  408. fl_state = idx_10Hz(t, animal);
  409. if t <= num_windows_fMRI
  410. f_state = idx_fMRI(t, animal);
  411. if timing_info_fMRI(t)
  412. count_fMRI_10Hz_on(f_state, fl_state, animal) = count_fMRI_10Hz_on(f_state, fl_state, animal) + 1;
  413. else
  414. count_fMRI_10Hz_off(f_state, fl_state, animal) = count_fMRI_10Hz_off(f_state, fl_state, animal) + 1;
  415. end
  416. end
  417. end
  418. end
  419. total_count_10Hz_fMRI_on = sum(count_10Hz_fMRI_on, 3);
  420. total_count_10Hz_fMRI_off = sum(count_10Hz_fMRI_off, 3);
  421. total_count_fMRI_10Hz_on = sum(count_fMRI_10Hz_on, 3);
  422. total_count_fMRI_10Hz_off = sum(count_fMRI_10Hz_off, 3);
  423. percent_10Hz_fMRI_on = safe_percent_by_column(total_count_10Hz_fMRI_on);
  424. percent_10Hz_fMRI_off = safe_percent_by_column(total_count_10Hz_fMRI_off);
  425. percent_fMRI_10Hz_on = safe_percent_by_column(total_count_fMRI_10Hz_on);
  426. percent_fMRI_10Hz_off = safe_percent_by_column(total_count_fMRI_10Hz_off);
  427. p_values_10Hz_fMRI = nan(optimal_num_clusters_combined, optimal_num_clusters_fMRI);
  428. p_values_fMRI_10Hz = nan(optimal_num_clusters_fMRI, optimal_num_clusters_combined);
  429. for i = 1:optimal_num_clusters_combined
  430. for j = 1:optimal_num_clusters_fMRI
  431. p_values_10Hz_fMRI(i, j) = safe_paired_ttest(squeeze(count_10Hz_fMRI_on(i, j, :)), squeeze(count_10Hz_fMRI_off(i, j, :)));
  432. end
  433. end
  434. for i = 1:optimal_num_clusters_fMRI
  435. for j = 1:optimal_num_clusters_combined
  436. p_values_fMRI_10Hz(i, j) = safe_paired_ttest(squeeze(count_fMRI_10Hz_on(i, j, :)), squeeze(count_fMRI_10Hz_off(i, j, :)));
  437. end
  438. end
  439. fprintf('P-values for joint state distributions - 10 Hz FL to fMRI:\n'); disp(p_values_10Hz_fMRI);
  440. fprintf('P-values for joint state distributions - fMRI to 10 Hz FL:\n'); disp(p_values_fMRI_10Hz);
  441. figure;
  442. threshold_joint = 0.05;
  443. ulim = 50;
  444. plot_matrix_with_sig(2, 2, 1, percent_10Hz_fMRI_on, p_values_10Hz_fMRI, threshold_joint, 'Percentage Distribution - 10 Hz FL to fMRI (CO2 On)', 'fMRI State', '10 Hz FL State', [0 ulim], cm_custom_blue2red_2);
  445. plot_matrix_with_sig(2, 2, 2, percent_10Hz_fMRI_off, p_values_10Hz_fMRI, threshold_joint, 'Percentage Distribution - 10 Hz FL to fMRI (CO2 Off)', 'fMRI State', '10 Hz FL State', [0 ulim], cm_custom_blue2red_2);
  446. plot_matrix_with_sig(2, 2, 3, percent_fMRI_10Hz_on, p_values_fMRI_10Hz, threshold_joint, 'Percentage Distribution - fMRI to 10 Hz FL (CO2 On)', '10 Hz FL State', 'fMRI State', [0 ulim], cm_custom_blue2red_2);
  447. plot_matrix_with_sig(2, 2, 4, percent_fMRI_10Hz_off, p_values_fMRI_10Hz, threshold_joint, 'Percentage Distribution - fMRI to 10 Hz FL (CO2 Off)', '10 Hz FL State', 'fMRI State', [0 ulim], cm_custom_blue2red_2);
  448. sgtitle('Percentage distributions for FL and fMRI states during CO2 on/off');
  449. %% Joint transition probabilities: FL to fMRI (1 Hz and 10 Hz), overall and by CO2
  450. joint_transitions_10Hz_fMRI = zeros(optimal_num_clusters_combined, optimal_num_clusters_fMRI);
  451. joint_transitions_1Hz_fMRI = zeros(optimal_num_clusters_combined, optimal_num_clusters_fMRI);
  452. for animal = 1:num_animals
  453. for t = 1:(min(num_windows_10Hz, num_windows_fMRI) - 1)
  454. joint_transitions_10Hz_fMRI(idx_10Hz(t, animal), idx_fMRI(t, animal)) = joint_transitions_10Hz_fMRI(idx_10Hz(t, animal), idx_fMRI(t, animal)) + 1;
  455. end
  456. for t = 1:(min(num_windows_1Hz, num_windows_fMRI) - 1)
  457. joint_transitions_1Hz_fMRI(idx_1Hz(t, animal), idx_fMRI(t, animal)) = joint_transitions_1Hz_fMRI(idx_1Hz(t, animal), idx_fMRI(t, animal)) + 1;
  458. end
  459. end
  460. joint_trans_prob_10Hz_fMRI = normalize_rows_2d(joint_transitions_10Hz_fMRI);
  461. joint_trans_prob_1Hz_fMRI = normalize_rows_2d(joint_transitions_1Hz_fMRI);
  462. figure;
  463. subplot(1, 2, 1); imagesc(joint_trans_prob_10Hz_fMRI); colorbar; colormap(cm_turbo_custom); caxis([0 0.5]); title('Joint transition probabilities - 10 Hz FL to fMRI'); xlabel('fMRI State'); ylabel('10 Hz FL State');
  464. subplot(1, 2, 2); imagesc(joint_trans_prob_1Hz_fMRI); colorbar; colormap(cm_turbo_custom); caxis([0 0.5]); title('Joint transition probabilities - 1 Hz FL to fMRI'); xlabel('fMRI State'); ylabel('1 Hz FL State');
  465. joint_trans_prob_10Hz_fMRI_on = zeros(optimal_num_clusters_combined, optimal_num_clusters_fMRI, num_animals);
  466. joint_trans_prob_10Hz_fMRI_off = zeros(optimal_num_clusters_combined, optimal_num_clusters_fMRI, num_animals);
  467. joint_trans_prob_1Hz_fMRI_on = zeros(optimal_num_clusters_combined, optimal_num_clusters_fMRI, num_animals);
  468. joint_trans_prob_1Hz_fMRI_off = zeros(optimal_num_clusters_combined, optimal_num_clusters_fMRI, num_animals);
  469. for animal = 1:num_animals
  470. [~, ~, starts_fMRI] = get_co2_start_indices_for_animal(animal, ...
  471. co2_on_indices_10Hz, co2_on_indices_10Hz_sub3, ...
  472. co2_on_indices_1Hz, co2_on_indices_1Hz_sub3, ...
  473. co2_on_indices_fMRI, co2_on_indices_fMRI_sub3);
  474. ends_fMRI = starts_fMRI + co2_on_duration_fMRI;
  475. for t = 1:(min(num_windows_10Hz, num_windows_fMRI) - 1)
  476. current_state_10Hz = idx_10Hz(t, animal);
  477. next_state_fMRI = idx_fMRI(t + 1, animal);
  478. if current_state_10Hz > 0 && next_state_fMRI > 0
  479. if any(t >= starts_fMRI & t <= ends_fMRI)
  480. joint_trans_prob_10Hz_fMRI_on(current_state_10Hz, next_state_fMRI, animal) = joint_trans_prob_10Hz_fMRI_on(current_state_10Hz, next_state_fMRI, animal) + 1;
  481. else
  482. joint_trans_prob_10Hz_fMRI_off(current_state_10Hz, next_state_fMRI, animal) = joint_trans_prob_10Hz_fMRI_off(current_state_10Hz, next_state_fMRI, animal) + 1;
  483. end
  484. end
  485. end
  486. for t = 1:(min(num_windows_1Hz, num_windows_fMRI) - 1)
  487. current_state_1Hz = idx_1Hz(t, animal);
  488. next_state_fMRI = idx_fMRI(t + 1, animal);
  489. if current_state_1Hz > 0 && next_state_fMRI > 0
  490. if any(t >= starts_fMRI & t <= ends_fMRI)
  491. joint_trans_prob_1Hz_fMRI_on(current_state_1Hz, next_state_fMRI, animal) = joint_trans_prob_1Hz_fMRI_on(current_state_1Hz, next_state_fMRI, animal) + 1;
  492. else
  493. joint_trans_prob_1Hz_fMRI_off(current_state_1Hz, next_state_fMRI, animal) = joint_trans_prob_1Hz_fMRI_off(current_state_1Hz, next_state_fMRI, animal) + 1;
  494. end
  495. end
  496. end
  497. end
  498. joint_trans_prob_10Hz_fMRI_on = normalize_transition_tensor(joint_trans_prob_10Hz_fMRI_on);
  499. joint_trans_prob_10Hz_fMRI_off = normalize_transition_tensor(joint_trans_prob_10Hz_fMRI_off);
  500. joint_trans_prob_1Hz_fMRI_on = normalize_transition_tensor(joint_trans_prob_1Hz_fMRI_on);
  501. joint_trans_prob_1Hz_fMRI_off = normalize_transition_tensor(joint_trans_prob_1Hz_fMRI_off);
  502. p_values_joint_10Hz_fMRI = nan(optimal_num_clusters_combined, optimal_num_clusters_fMRI);
  503. p_values_joint_1Hz_fMRI = nan(optimal_num_clusters_combined, optimal_num_clusters_fMRI);
  504. for i = 1:optimal_num_clusters_combined
  505. for j = 1:optimal_num_clusters_fMRI
  506. p_values_joint_10Hz_fMRI(i, j) = safe_paired_ttest(squeeze(joint_trans_prob_10Hz_fMRI_on(i, j, :)), squeeze(joint_trans_prob_10Hz_fMRI_off(i, j, :)));
  507. p_values_joint_1Hz_fMRI(i, j) = safe_paired_ttest(squeeze(joint_trans_prob_1Hz_fMRI_on(i, j, :)), squeeze(joint_trans_prob_1Hz_fMRI_off(i, j, :)));
  508. end
  509. end
  510. fprintf('P-values for joint transition probabilities - 10 Hz FL to fMRI:\n'); disp(p_values_joint_10Hz_fMRI);
  511. fprintf('P-values for joint transition probabilities - 1 Hz FL to fMRI:\n'); disp(p_values_joint_1Hz_fMRI);
  512. figure;
  513. threshold_joint_trans = 0.1;
  514. plot_matrix_with_sig(2, 2, 1, mean(joint_trans_prob_10Hz_fMRI_on, 3, 'omitnan'), p_values_joint_10Hz_fMRI, threshold_joint_trans, 'Joint Transition Probabilities - 10 Hz FL to fMRI (CO2 On)', 'fMRI State', '10 Hz FL State', [0 0.5], cm_turbo_custom);
  515. plot_matrix_with_sig(2, 2, 2, mean(joint_trans_prob_10Hz_fMRI_off, 3, 'omitnan'), p_values_joint_10Hz_fMRI, threshold_joint_trans, 'Joint Transition Probabilities - 10 Hz FL to fMRI (CO2 Off)', 'fMRI State', '10 Hz FL State', [0 0.5], cm_turbo_custom);
  516. plot_matrix_with_sig(2, 2, 3, mean(joint_trans_prob_1Hz_fMRI_on, 3, 'omitnan'), p_values_joint_1Hz_fMRI, threshold_joint_trans, 'Joint Transition Probabilities - 1 Hz FL to fMRI (CO2 On)', 'fMRI State', '1 Hz FL State', [0 0.5], cm_turbo_custom);
  517. plot_matrix_with_sig(2, 2, 4, mean(joint_trans_prob_1Hz_fMRI_off, 3, 'omitnan'), p_values_joint_1Hz_fMRI, threshold_joint_trans, 'Joint Transition Probabilities - 1 Hz FL to fMRI (CO2 Off)', 'fMRI State', '1 Hz FL State', [0 0.5], cm_turbo_custom);
  518. sgtitle('Joint transition probabilities for FL to fMRI (CO2 on/off)');
  519. %% Similarity between FL and fMRI dFC matrices over time
  520. similarity_10Hz_fMRI = nan(num_windows_fMRI, num_animals);
  521. similarity_1Hz_fMRI = nan(num_windows_fMRI, num_animals);
  522. dFC_10Hz_reshaped = reshape(dFC_10Hz, num_regions * num_regions, num_windows_10Hz, num_animals);
  523. dFC_1Hz_reshaped = reshape(dFC_1Hz, num_regions * num_regions, num_windows_1Hz, num_animals);
  524. dFC_fMRI_reshaped = reshape(dFC_fMRI, num_regions * num_regions, num_windows_fMRI, num_animals);
  525. for animal = 1:num_animals
  526. for t = 1:num_windows_fMRI
  527. start_time_fMRI = (t - 1) * step_size_fMRI + 1;
  528. start_time_10Hz = round(start_time_fMRI / (step_size_10Hz / 10)) - 4;
  529. end_time_10Hz = start_time_10Hz + 5;
  530. if start_time_10Hz > 0 && end_time_10Hz <= num_windows_10Hz
  531. avg_dFC_10Hz = mean(dFC_10Hz_reshaped(:, start_time_10Hz:end_time_10Hz, animal), 2);
  532. similarity_10Hz_fMRI(t, animal) = corr(avg_dFC_10Hz, dFC_fMRI_reshaped(:, t, animal), 'Rows', 'pairwise');
  533. end
  534. t_1Hz = round(((t - 1) * step_size_fMRI) / step_size_1Hz) + 1;
  535. if t_1Hz > 0 && t_1Hz <= num_windows_1Hz
  536. similarity_1Hz_fMRI(t, animal) = corr(dFC_1Hz_reshaped(:, t_1Hz, animal), dFC_fMRI_reshaped(:, t, animal), 'Rows', 'pairwise');
  537. end
  538. end
  539. end
  540. similarity_10Hz_fMRI_on = [];
  541. similarity_10Hz_fMRI_off = [];
  542. similarity_1Hz_fMRI_on = [];
  543. similarity_1Hz_fMRI_off = [];
  544. cc = 30;
  545. for animal = 1:num_animals
  546. [starts_10Hz, starts_1Hz, starts_fMRI] = get_co2_start_indices_for_animal(animal, ...
  547. co2_on_indices_10Hz, co2_on_indices_10Hz_sub3, ...
  548. co2_on_indices_1Hz, co2_on_indices_1Hz_sub3, ...
  549. co2_on_indices_fMRI, co2_on_indices_fMRI_sub3);
  550. ends_10Hz = starts_10Hz + co2_duration;
  551. ends_1Hz = starts_1Hz + co2_duration;
  552. ends_fMRI = starts_fMRI + co2_duration;
  553. off_starts_fMRI = [1, ends_fMRI + window_size_fMRI / 2];
  554. off_ends_fMRI = [starts_fMRI - window_size_fMRI / 2, num_windows_fMRI];
  555. off_starts_10Hz = [1, ends_10Hz + window_size_10Hz / sampling_rate_10Hz / 2];
  556. off_ends_10Hz = [starts_10Hz - window_size_10Hz / sampling_rate_10Hz / 2, num_windows_10Hz];
  557. for cycle = 1:length(starts_10Hz)
  558. for t = (starts_10Hz(cycle) + cc):min(ends_10Hz(cycle), num_windows_fMRI) - cc
  559. if t > 0 && t <= num_windows_10Hz
  560. similarity_10Hz_fMRI_on = [similarity_10Hz_fMRI_on; similarity_10Hz_fMRI(t, animal)]; %#ok<AGROW>
  561. end
  562. if t > 0 && t <= num_windows_1Hz
  563. similarity_1Hz_fMRI_on = [similarity_1Hz_fMRI_on; similarity_1Hz_fMRI(t, animal)]; %#ok<AGROW>
  564. end
  565. end
  566. end
  567. for cycle = 1:length(off_starts_10Hz)
  568. for t = max(1, round(off_starts_10Hz(cycle))) + cc : round(off_ends_10Hz(cycle)) - cc
  569. if t > 0 && t <= num_windows_10Hz
  570. similarity_10Hz_fMRI_off = [similarity_10Hz_fMRI_off; similarity_10Hz_fMRI(t, animal)]; %#ok<AGROW>
  571. end
  572. if t > 0 && t <= num_windows_1Hz
  573. similarity_1Hz_fMRI_off = [similarity_1Hz_fMRI_off; similarity_1Hz_fMRI(t, animal)]; %#ok<AGROW>
  574. end
  575. end
  576. end
  577. end
  578. llim = 10;
  579. ulim = 90;
  580. similarity_1Hz_fMRI_on_filtered = percentile_filter(similarity_1Hz_fMRI_on, llim, ulim);
  581. similarity_1Hz_fMRI_off_filtered = percentile_filter(similarity_1Hz_fMRI_off, llim, ulim);
  582. similarity_10Hz_fMRI_on_filtered = percentile_filter(similarity_10Hz_fMRI_on, llim, ulim);
  583. similarity_10Hz_fMRI_off_filtered = percentile_filter(similarity_10Hz_fMRI_off, llim, ulim);
  584. figure;
  585. subplot(1, 2, 1);
  586. plot_distribution_comparison(similarity_1Hz_fMRI_on_filtered, similarity_1Hz_fMRI_off_filtered, '1 Hz similarity');
  587. subplot(1, 2, 2);
  588. plot_distribution_comparison(similarity_10Hz_fMRI_on_filtered, similarity_10Hz_fMRI_off_filtered, '10 Hz similarity');
  589. [~, p_10Hz] = ttest2(similarity_10Hz_fMRI_on_filtered, similarity_10Hz_fMRI_off_filtered);
  590. [~, p_1Hz] = ttest2(similarity_1Hz_fMRI_on_filtered, similarity_1Hz_fMRI_off_filtered);
  591. effect_1Hz = cohens_d_two_sample(similarity_1Hz_fMRI_on_filtered, similarity_1Hz_fMRI_off_filtered);
  592. effect_10Hz = cohens_d_two_sample(similarity_10Hz_fMRI_on_filtered, similarity_10Hz_fMRI_off_filtered);
  593. fprintf('P-value for similarity comparison (10 Hz FL): %.6f\n', p_10Hz);
  594. fprintf('P-value for similarity comparison (1 Hz FL): %.6f\n', p_1Hz);
  595. fprintf('Cohen''s d for similarity comparison (10 Hz FL): %.6f\n', effect_10Hz);
  596. fprintf('Cohen''s d for similarity comparison (1 Hz FL): %.6f\n', effect_1Hz);
  597. %% Dwell times during CO2 on/off
  598. [dwell_times_10Hz_on, dwell_times_10Hz_off] = deal(nan(optimal_num_clusters_combined, num_animals));
  599. [dwell_times_1Hz_on, dwell_times_1Hz_off] = deal(nan(optimal_num_clusters_combined, num_animals));
  600. [dwell_times_fMRI_on, dwell_times_fMRI_off] = deal(nan(optimal_num_clusters_fMRI, num_animals));
  601. for animal = 1:num_animals
  602. [starts_10Hz, starts_1Hz, starts_fMRI] = get_co2_start_indices_for_animal(animal, ...
  603. co2_on_indices_10Hz, co2_on_indices_10Hz_sub3, ...
  604. co2_on_indices_1Hz, co2_on_indices_1Hz_sub3, ...
  605. co2_on_indices_fMRI, co2_on_indices_fMRI_sub3);
  606. timing_info_10Hz = build_timing_mask(num_windows_10Hz, starts_10Hz, starts_10Hz + co2_duration);
  607. timing_info_1Hz = build_timing_mask(num_windows_1Hz, starts_1Hz, starts_1Hz + co2_duration);
  608. timing_info_fMRI = build_timing_mask(num_windows_fMRI, starts_fMRI, starts_fMRI + co2_duration);
  609. dwell_times_10Hz_on(:, animal) = calculate_dwell_times(idx_10Hz(:, animal), timing_info_10Hz, optimal_num_clusters_combined);
  610. dwell_times_10Hz_off(:, animal) = calculate_dwell_times(idx_10Hz(:, animal), ~timing_info_10Hz, optimal_num_clusters_combined);
  611. dwell_times_1Hz_on(:, animal) = calculate_dwell_times(idx_1Hz(:, animal), timing_info_1Hz, optimal_num_clusters_combined);
  612. dwell_times_1Hz_off(:, animal) = calculate_dwell_times(idx_1Hz(:, animal), ~timing_info_1Hz, optimal_num_clusters_combined);
  613. dwell_times_fMRI_on(:, animal) = calculate_dwell_times(idx_fMRI(:, animal), timing_info_fMRI, optimal_num_clusters_fMRI);
  614. dwell_times_fMRI_off(:, animal) = calculate_dwell_times(idx_fMRI(:, animal), ~timing_info_fMRI, optimal_num_clusters_fMRI);
  615. end
  616. p_values_dwell_10Hz = nan(optimal_num_clusters_combined, 1);
  617. p_values_dwell_1Hz = nan(optimal_num_clusters_combined, 1);
  618. p_values_dwell_fMRI = nan(optimal_num_clusters_fMRI, 1);
  619. for i = 1:optimal_num_clusters_combined
  620. p_values_dwell_10Hz(i) = safe_paired_ttest(dwell_times_10Hz_on(i, :), dwell_times_10Hz_off(i, :));
  621. p_values_dwell_1Hz(i) = safe_paired_ttest(dwell_times_1Hz_on(i, :), dwell_times_1Hz_off(i, :));
  622. end
  623. for i = 1:optimal_num_clusters_fMRI
  624. p_values_dwell_fMRI(i) = safe_paired_ttest(dwell_times_fMRI_on(i, :), dwell_times_fMRI_off(i, :));
  625. end
  626. fprintf('P-values for dwell times - FL 10 Hz:\n'); disp(p_values_dwell_10Hz);
  627. fprintf('P-values for dwell times - FL 1 Hz:\n'); disp(p_values_dwell_1Hz);
  628. fprintf('P-values for dwell times - fMRI:\n'); disp(p_values_dwell_fMRI);
  629. mean_dwell_times_10Hz_on = mean(dwell_times_10Hz_on, 2, 'omitnan');
  630. mean_dwell_times_10Hz_off = mean(dwell_times_10Hz_off, 2, 'omitnan');
  631. mean_dwell_times_1Hz_on = mean(dwell_times_1Hz_on, 2, 'omitnan');
  632. mean_dwell_times_1Hz_off = mean(dwell_times_1Hz_off, 2, 'omitnan');
  633. mean_dwell_times_fMRI_on = mean(dwell_times_fMRI_on, 2, 'omitnan');
  634. mean_dwell_times_fMRI_off = mean(dwell_times_fMRI_off, 2, 'omitnan');
  635. sem_dwell_times_10Hz_on = std(dwell_times_10Hz_on, 0, 2, 'omitnan') / sqrt(num_animals);
  636. sem_dwell_times_10Hz_off = std(dwell_times_10Hz_off, 0, 2, 'omitnan') / sqrt(num_animals);
  637. sem_dwell_times_1Hz_on = std(dwell_times_1Hz_on, 0, 2, 'omitnan') / sqrt(num_animals);
  638. sem_dwell_times_1Hz_off = std(dwell_times_1Hz_off, 0, 2, 'omitnan') / sqrt(num_animals);
  639. sem_dwell_times_fMRI_on = std(dwell_times_fMRI_on, 0, 2, 'omitnan') / sqrt(num_animals);
  640. sem_dwell_times_fMRI_off = std(dwell_times_fMRI_off, 0, 2, 'omitnan') / sqrt(num_animals);
  641. figure('Position', [0 0 400 900]);
  642. plot_grouped_bars_with_paired_points(3, 1, 1, mean_dwell_times_10Hz_on, mean_dwell_times_10Hz_off, sem_dwell_times_10Hz_on, sem_dwell_times_10Hz_off, dwell_times_10Hz_on, dwell_times_10Hz_off, 'Dwell Times - FL 10 Hz', 'Time (windows)', 1:optimal_num_clusters_combined, []);
  643. plot_grouped_bars_with_paired_points(3, 1, 2, mean_dwell_times_1Hz_on, mean_dwell_times_1Hz_off, sem_dwell_times_1Hz_on, sem_dwell_times_1Hz_off, dwell_times_1Hz_on, dwell_times_1Hz_off, 'Dwell Times - FL 1 Hz', 'Time (windows)', 1:optimal_num_clusters_combined, []);
  644. plot_grouped_bars_with_paired_points(3, 1, 3, mean_dwell_times_fMRI_on, mean_dwell_times_fMRI_off, sem_dwell_times_fMRI_on, sem_dwell_times_fMRI_off, dwell_times_fMRI_on, dwell_times_fMRI_off, 'Dwell Times - fMRI', 'Time (windows)', 1:optimal_num_clusters_fMRI, []);
  645. sgtitle('Dwell times for FL 10 Hz, FL 1 Hz, and fMRI (CO2 on/off)');
  646. %% Entry and exit rates during CO2 on/off
  647. [entry_rate_10Hz_on, entry_rate_10Hz_off] = deal(nan(optimal_num_clusters_combined, num_animals));
  648. [entry_rate_1Hz_on, entry_rate_1Hz_off] = deal(nan(optimal_num_clusters_combined, num_animals));
  649. [entry_rate_fMRI_on, entry_rate_fMRI_off] = deal(nan(optimal_num_clusters_fMRI, num_animals));
  650. [exit_rate_10Hz_on, exit_rate_10Hz_off] = deal(nan(optimal_num_clusters_combined, num_animals));
  651. [exit_rate_1Hz_on, exit_rate_1Hz_off] = deal(nan(optimal_num_clusters_combined, num_animals));
  652. [exit_rate_fMRI_on, exit_rate_fMRI_off] = deal(nan(optimal_num_clusters_fMRI, num_animals));
  653. for animal = 1:num_animals
  654. [starts_10Hz, starts_1Hz, starts_fMRI] = get_co2_start_indices_for_animal(animal, ...
  655. co2_on_indices_10Hz, co2_on_indices_10Hz_sub3, ...
  656. co2_on_indices_1Hz, co2_on_indices_1Hz_sub3, ...
  657. co2_on_indices_fMRI, co2_on_indices_fMRI_sub3);
  658. timing_info_10Hz = build_timing_mask(num_windows_10Hz, starts_10Hz, starts_10Hz + co2_duration);
  659. timing_info_1Hz = build_timing_mask(num_windows_1Hz, starts_1Hz, starts_1Hz + co2_duration);
  660. timing_info_fMRI = build_timing_mask(num_windows_fMRI, starts_fMRI, starts_fMRI + co2_duration);
  661. entry_rate_10Hz_on(:, animal) = calculate_entry_rates(idx_10Hz(:, animal), timing_info_10Hz, optimal_num_clusters_combined);
  662. entry_rate_10Hz_off(:, animal) = calculate_entry_rates(idx_10Hz(:, animal), ~timing_info_10Hz, optimal_num_clusters_combined);
  663. exit_rate_10Hz_on(:, animal) = calculate_exit_rates(idx_10Hz(:, animal), timing_info_10Hz, optimal_num_clusters_combined);
  664. exit_rate_10Hz_off(:, animal) = calculate_exit_rates(idx_10Hz(:, animal), ~timing_info_10Hz, optimal_num_clusters_combined);
  665. entry_rate_1Hz_on(:, animal) = calculate_entry_rates(idx_1Hz(:, animal), timing_info_1Hz, optimal_num_clusters_combined);
  666. entry_rate_1Hz_off(:, animal) = calculate_entry_rates(idx_1Hz(:, animal), ~timing_info_1Hz, optimal_num_clusters_combined);
  667. exit_rate_1Hz_on(:, animal) = calculate_exit_rates(idx_1Hz(:, animal), timing_info_1Hz, optimal_num_clusters_combined);
  668. exit_rate_1Hz_off(:, animal) = calculate_exit_rates(idx_1Hz(:, animal), ~timing_info_1Hz, optimal_num_clusters_combined);
  669. entry_rate_fMRI_on(:, animal) = calculate_entry_rates(idx_fMRI(:, animal), timing_info_fMRI, optimal_num_clusters_fMRI);
  670. entry_rate_fMRI_off(:, animal) = calculate_entry_rates(idx_fMRI(:, animal), ~timing_info_fMRI, optimal_num_clusters_fMRI);
  671. exit_rate_fMRI_on(:, animal) = calculate_exit_rates(idx_fMRI(:, animal), timing_info_fMRI, optimal_num_clusters_fMRI);
  672. exit_rate_fMRI_off(:, animal) = calculate_exit_rates(idx_fMRI(:, animal), ~timing_info_fMRI, optimal_num_clusters_fMRI);
  673. end
  674. p_values_entry_10Hz = nan(optimal_num_clusters_combined, 1);
  675. p_values_entry_1Hz = nan(optimal_num_clusters_combined, 1);
  676. p_values_entry_fMRI = nan(optimal_num_clusters_fMRI, 1);
  677. p_values_exit_10Hz = nan(optimal_num_clusters_combined, 1);
  678. p_values_exit_1Hz = nan(optimal_num_clusters_combined, 1);
  679. p_values_exit_fMRI = nan(optimal_num_clusters_fMRI, 1);
  680. for i = 1:optimal_num_clusters_combined
  681. p_values_entry_10Hz(i) = safe_paired_ttest(entry_rate_10Hz_on(i, :), entry_rate_10Hz_off(i, :));
  682. p_values_entry_1Hz(i) = safe_paired_ttest(entry_rate_1Hz_on(i, :), entry_rate_1Hz_off(i, :));
  683. p_values_exit_10Hz(i) = safe_paired_ttest(exit_rate_10Hz_on(i, :), exit_rate_10Hz_off(i, :));
  684. p_values_exit_1Hz(i) = safe_paired_ttest(exit_rate_1Hz_on(i, :), exit_rate_1Hz_off(i, :));
  685. end
  686. for i = 1:optimal_num_clusters_fMRI
  687. p_values_entry_fMRI(i) = safe_paired_ttest(entry_rate_fMRI_on(i, :), entry_rate_fMRI_off(i, :));
  688. p_values_exit_fMRI(i) = safe_paired_ttest(exit_rate_fMRI_on(i, :), exit_rate_fMRI_off(i, :));
  689. end
  690. fprintf('P-values for entry rates - FL 10 Hz:\n'); disp(p_values_entry_10Hz);
  691. fprintf('P-values for entry rates - FL 1 Hz:\n'); disp(p_values_entry_1Hz);
  692. fprintf('P-values for entry rates - fMRI:\n'); disp(p_values_entry_fMRI);
  693. fprintf('P-values for exit rates - FL 10 Hz:\n'); disp(p_values_exit_10Hz);
  694. fprintf('P-values for exit rates - FL 1 Hz:\n'); disp(p_values_exit_1Hz);
  695. fprintf('P-values for exit rates - fMRI:\n'); disp(p_values_exit_fMRI);
  696. mean_entry_rates_10Hz_on = mean(entry_rate_10Hz_on, 2, 'omitnan');
  697. mean_entry_rates_10Hz_off = mean(entry_rate_10Hz_off, 2, 'omitnan');
  698. mean_entry_rates_1Hz_on = mean(entry_rate_1Hz_on, 2, 'omitnan');
  699. mean_entry_rates_1Hz_off = mean(entry_rate_1Hz_off, 2, 'omitnan');
  700. mean_entry_rates_fMRI_on = mean(entry_rate_fMRI_on, 2, 'omitnan');
  701. mean_entry_rates_fMRI_off = mean(entry_rate_fMRI_off, 2, 'omitnan');
  702. sem_entry_rates_10Hz_on = std(entry_rate_10Hz_on, 0, 2, 'omitnan') / sqrt(num_animals);
  703. sem_entry_rates_10Hz_off = std(entry_rate_10Hz_off, 0, 2, 'omitnan') / sqrt(num_animals);
  704. sem_entry_rates_1Hz_on = std(entry_rate_1Hz_on, 0, 2, 'omitnan') / sqrt(num_animals);
  705. sem_entry_rates_1Hz_off = std(entry_rate_1Hz_off, 0, 2, 'omitnan') / sqrt(num_animals);
  706. sem_entry_rates_fMRI_on = std(entry_rate_fMRI_on, 0, 2, 'omitnan') / sqrt(num_animals);
  707. sem_entry_rates_fMRI_off = std(entry_rate_fMRI_off, 0, 2, 'omitnan') / sqrt(num_animals);
  708. mean_exit_rates_10Hz_on = mean(exit_rate_10Hz_on, 2, 'omitnan');
  709. mean_exit_rates_10Hz_off = mean(exit_rate_10Hz_off, 2, 'omitnan');
  710. mean_exit_rates_1Hz_on = mean(exit_rate_1Hz_on, 2, 'omitnan');
  711. mean_exit_rates_1Hz_off = mean(exit_rate_1Hz_off, 2, 'omitnan');
  712. mean_exit_rates_fMRI_on = mean(exit_rate_fMRI_on, 2, 'omitnan');
  713. mean_exit_rates_fMRI_off = mean(exit_rate_fMRI_off, 2, 'omitnan');
  714. sem_exit_rates_10Hz_on = std(exit_rate_10Hz_on, 0, 2, 'omitnan') / sqrt(num_animals);
  715. sem_exit_rates_10Hz_off = std(exit_rate_10Hz_off, 0, 2, 'omitnan') / sqrt(num_animals);
  716. sem_exit_rates_1Hz_on = std(exit_rate_1Hz_on, 0, 2, 'omitnan') / sqrt(num_animals);
  717. sem_exit_rates_1Hz_off = std(exit_rate_1Hz_off, 0, 2, 'omitnan') / sqrt(num_animals);
  718. sem_exit_rates_fMRI_on = std(exit_rate_fMRI_on, 0, 2, 'omitnan') / sqrt(num_animals);
  719. sem_exit_rates_fMRI_off = std(exit_rate_fMRI_off, 0, 2, 'omitnan') / sqrt(num_animals);
  720. figure('Position', [0 0 400 900]);
  721. plot_grouped_bars_with_paired_points(3, 1, 1, mean_entry_rates_10Hz_on, mean_entry_rates_10Hz_off, sem_entry_rates_10Hz_on, sem_entry_rates_10Hz_off, entry_rate_10Hz_on, entry_rate_10Hz_off, 'Entry Rates - FL 10 Hz', 'Entry Rate (entries/window)', 1:optimal_num_clusters_combined, []);
  722. plot_grouped_bars_with_paired_points(3, 1, 2, mean_entry_rates_1Hz_on, mean_entry_rates_1Hz_off, sem_entry_rates_1Hz_on, sem_entry_rates_1Hz_off, entry_rate_1Hz_on, entry_rate_1Hz_off, 'Entry Rates - FL 1 Hz', 'Entry Rate (entries/window)', 1:optimal_num_clusters_combined, []);
  723. plot_grouped_bars_with_paired_points(3, 1, 3, mean_entry_rates_fMRI_on, mean_entry_rates_fMRI_off, sem_entry_rates_fMRI_on, sem_entry_rates_fMRI_off, entry_rate_fMRI_on, entry_rate_fMRI_off, 'Entry Rates - fMRI', 'Entry Rate (entries/window)', 1:optimal_num_clusters_fMRI, []);
  724. sgtitle('Entry rates for FL 10 Hz, FL 1 Hz, and fMRI (CO2 on/off)');
  725. figure('Position', [0 0 400 900]);
  726. plot_grouped_bars_with_paired_points(3, 1, 1, mean_exit_rates_10Hz_on, mean_exit_rates_10Hz_off, sem_exit_rates_10Hz_on, sem_exit_rates_10Hz_off, exit_rate_10Hz_on, exit_rate_10Hz_off, 'Exit Rates - FL 10 Hz', 'Exit Rate (exits/window)', 1:optimal_num_clusters_combined, []);
  727. plot_grouped_bars_with_paired_points(3, 1, 2, mean_exit_rates_1Hz_on, mean_exit_rates_1Hz_off, sem_exit_rates_1Hz_on, sem_exit_rates_1Hz_off, exit_rate_1Hz_on, exit_rate_1Hz_off, 'Exit Rates - FL 1 Hz', 'Exit Rate (exits/window)', 1:optimal_num_clusters_combined, []);
  728. plot_grouped_bars_with_paired_points(3, 1, 3, mean_exit_rates_fMRI_on, mean_exit_rates_fMRI_off, sem_exit_rates_fMRI_on, sem_exit_rates_fMRI_off, exit_rate_fMRI_on, exit_rate_fMRI_off, 'Exit Rates - fMRI', 'Exit Rate (exits/window)', 1:optimal_num_clusters_fMRI, []);
  729. sgtitle('Exit rates for FL 10 Hz, FL 1 Hz, and fMRI (CO2 on/off)');
  730. %% Cross-correlation between FL and fMRI state transitions
  731. thres = 0.01;
  732. state_transitions_FL = zeros(num_windows_10Hz - 1, num_animals);
  733. state_transitions_fMRI = zeros(num_windows_fMRI - 1, num_animals);
  734. for animal = 1:num_animals
  735. state_transitions_FL(:, animal) = diff(idx_10Hz(:, animal)) ~= 0;
  736. state_transitions_fMRI(:, animal) = diff(idx_fMRI(:, animal)) ~= 0;
  737. end
  738. max_lag = 6;
  739. cross_corr_FL_to_fMRI = zeros(2 * max_lag + 1, num_animals);
  740. for animal = 1:num_animals
  741. [cross_corr, lags_xcorr] = xcorr(state_transitions_FL(:, animal), state_transitions_fMRI(:, animal), max_lag, 'coeff');
  742. cross_corr_FL_to_fMRI(:, animal) = cross_corr;
  743. end
  744. avg_cross_corr_FL_to_fMRI = mean(cross_corr_FL_to_fMRI, 2, 'omitnan');
  745. p_values_FL_to_fMRI = nan(2 * max_lag + 1, 1);
  746. for lag_idx = 1:(2 * max_lag + 1)
  747. p_values_FL_to_fMRI(lag_idx) = safe_one_sample_ttest(cross_corr_FL_to_fMRI(lag_idx, :));
  748. end
  749. figure;
  750. subplot(2, 1, 1); hold on;
  751. plot(lags_xcorr, avg_cross_corr_FL_to_fMRI, '-b', 'LineWidth', 1.5);
  752. sig_lags = find(p_values_FL_to_fMRI < thres);
  753. plot(lags_xcorr(sig_lags), avg_cross_corr_FL_to_fMRI(sig_lags), 'r*', 'MarkerSize', 10);
  754. xlabel('Lag (frames)'); ylabel('Cross-Correlation'); title('Cross-correlation between FL and fMRI state transitions'); grid on; hold off;
  755. cross_corr_FL_to_fMRI_on = zeros(2 * max_lag + 1, num_animals);
  756. cross_corr_FL_to_fMRI_off = zeros(2 * max_lag + 1, num_animals);
  757. for animal = 1:num_animals
  758. [starts_10Hz, ~, starts_fMRI] = get_co2_start_indices_for_animal(animal, ...
  759. co2_on_indices_10Hz, co2_on_indices_10Hz_sub3, ...
  760. co2_on_indices_1Hz, co2_on_indices_1Hz_sub3, ...
  761. co2_on_indices_fMRI, co2_on_indices_fMRI_sub3);
  762. timing_info_10Hz = build_timing_mask(num_windows_10Hz, starts_10Hz, starts_10Hz + co2_duration);
  763. timing_info_fMRI = build_timing_mask(num_windows_fMRI, starts_fMRI, starts_fMRI + co2_duration);
  764. cross_corr_FL_to_fMRI_on(:, animal) = xcorr(state_transitions_FL(timing_info_10Hz(1:end-1), animal), state_transitions_fMRI(timing_info_fMRI(1:end-1), animal), max_lag, 'coeff');
  765. cross_corr_FL_to_fMRI_off(:, animal) = xcorr(state_transitions_FL(~timing_info_10Hz(1:end-1), animal), state_transitions_fMRI(~timing_info_fMRI(1:end-1), animal), max_lag, 'coeff');
  766. end
  767. avg_cross_corr_FL_to_fMRI_on = mean(cross_corr_FL_to_fMRI_on, 2, 'omitnan');
  768. avg_cross_corr_FL_to_fMRI_off = mean(cross_corr_FL_to_fMRI_off, 2, 'omitnan');
  769. p_values_FL_to_fMRI_on = nan(2 * max_lag + 1, 1);
  770. p_values_FL_to_fMRI_off = nan(2 * max_lag + 1, 1);
  771. for lag_idx = 1:(2 * max_lag + 1)
  772. p_values_FL_to_fMRI_on(lag_idx) = safe_one_sample_ttest(cross_corr_FL_to_fMRI_on(lag_idx, :));
  773. p_values_FL_to_fMRI_off(lag_idx) = safe_one_sample_ttest(cross_corr_FL_to_fMRI_off(lag_idx, :));
  774. end
  775. subplot(2, 1, 2); hold on;
  776. plot(lags_xcorr, avg_cross_corr_FL_to_fMRI_on, '-g', 'LineWidth', 1.5);
  777. plot(lags_xcorr, avg_cross_corr_FL_to_fMRI_off, '-r', 'LineWidth', 1.5);
  778. plot(lags_xcorr(p_values_FL_to_fMRI_on < thres), avg_cross_corr_FL_to_fMRI_on(p_values_FL_to_fMRI_on < thres), 'g*', 'MarkerSize', 8);
  779. plot(lags_xcorr(p_values_FL_to_fMRI_off < thres), avg_cross_corr_FL_to_fMRI_off(p_values_FL_to_fMRI_off < thres), 'r*', 'MarkerSize', 8);
  780. xlabel('Lag (frames)'); ylabel('Cross-Correlation'); title('Cross-correlation between FL and fMRI state transitions (CO2 on/off)'); grid on; hold off; ylim([0 0.1]);
  781. sgtitle('Cross-correlation between FL and fMRI state transitions');
  782. %% Conditional co-occurrence matrices across temporal lags
  783. lags = 0;
  784. [T, N] = size(idx_10Hz);
  785. K_FL = max(idx_10Hz(:));
  786. K_fMRI = max(idx_fMRI(:));
  787. L = numel(lags);
  788. CoocOn = zeros(K_fMRI, K_FL, L);
  789. CoocOff = zeros(K_fMRI, K_FL, L);
  790. P_on_fMRIgivenFL = nan(K_fMRI, K_FL, L);
  791. P_off_fMRIgivenFL = nan(K_fMRI, K_FL, L);
  792. P_on_FLgivenfMRI = nan(K_fMRI, K_FL, L);
  793. P_off_FLgivenfMRI = nan(K_fMRI, K_FL, L);
  794. for animal = 1:N
  795. if animal == 3
  796. on_idx = co2_on_indices_10Hz_sub3;
  797. else
  798. on_idx = co2_on_indices_10Hz;
  799. end
  800. on_mask = false(T, 1);
  801. on_mask(on_idx(on_idx <= T)) = true;
  802. off_mask = ~on_mask;
  803. for li = 1:L
  804. lag = lags(li);
  805. for t = 1:T
  806. tFL = t - lag;
  807. if tFL < 1 || tFL > T || t > size(idx_fMRI, 1)
  808. continue;
  809. end
  810. fL = idx_10Hz(tFL, animal);
  811. fR = idx_fMRI(t, animal);
  812. if fL > 0 && fR > 0
  813. if on_mask(t)
  814. CoocOn(fR, fL, li) = CoocOn(fR, fL, li) + 1;
  815. elseif off_mask(t)
  816. CoocOff(fR, fL, li) = CoocOff(fR, fL, li) + 1;
  817. end
  818. end
  819. end
  820. end
  821. end
  822. for li = 1:L
  823. C_on = CoocOn(:, :, li);
  824. C_off = CoocOff(:, :, li);
  825. P_on_fMRIgivenFL(:, :, li) = normalize_columns(C_on);
  826. P_off_fMRIgivenFL(:, :, li) = normalize_columns(C_off);
  827. P_on_FLgivenfMRI(:, :, li) = normalize_rows_2d(C_on);
  828. P_off_FLgivenfMRI(:, :, li) = normalize_rows_2d(C_off);
  829. end
  830. figure('Position', [100 100 1200 600]);
  831. for li = 1:L
  832. lag = lags(li);
  833. subplot(4, L, li);
  834. imagesc(P_on_fMRIgivenFL(:, :, li)); axis square; colorbar;
  835. title(sprintf('P(fMRI|FL) On, lag=%ds', lag));
  836. if li == 1, ylabel('fMRI state'); end
  837. xlabel('FL state');
  838. subplot(4, L, li + L);
  839. imagesc(P_off_fMRIgivenFL(:, :, li)); axis square; colorbar;
  840. title(sprintf('P(fMRI|FL) Off, lag=%ds', lag));
  841. xlabel('FL state');
  842. subplot(4, L, li + 2 * L);
  843. imagesc(P_on_FLgivenfMRI(:, :, li)); axis square; colorbar;
  844. title(sprintf('P(FL|fMRI) On, lag=%ds', lag));
  845. if li == 1, ylabel('fMRI state'); end
  846. xlabel('FL state');
  847. subplot(4, L, li + 3 * L);
  848. imagesc(P_off_FLgivenfMRI(:, :, li)); axis square; colorbar;
  849. title(sprintf('P(FL|fMRI) Off, lag=%ds', lag));
  850. xlabel('FL state');
  851. end
  852. sgtitle('Conditional co-occurrence matrices across lags and CO2 conditions');
  853. example_FL = 5;
  854. example_fMRI = 1;
  855. figure('Position', [200 200 800 300]);
  856. for li = 1:L
  857. subplot(2, L, li);
  858. bar(P_on_fMRIgivenFL(:, example_FL, li), 'b'); hold on;
  859. bar(P_off_fMRIgivenFL(:, example_FL, li), 'r'); hold off;
  860. ylim([0 1]);
  861. title(sprintf('P(fMRI|FL=%d), lag=%ds', example_FL, lags(li)));
  862. if li == 1, ylabel('Probability'); end
  863. xlabel('fMRI state'); legend('On', 'Off');
  864. subplot(2, L, li + L);
  865. bar(P_on_FLgivenfMRI(example_fMRI, :, li), 'b'); hold on;
  866. bar(P_off_FLgivenfMRI(example_fMRI, :, li), 'r'); hold off;
  867. ylim([0 1]);
  868. title(sprintf('P(FL|fMRI=%d), lag=%ds', example_fMRI, lags(li)));
  869. xlabel('FL state');
  870. end
  871. sgtitle(sprintf('Example conditional distributions for FL=%d and fMRI=%d', example_FL, example_fMRI));
  872. %% Local functions
  873. function cmap = load_colormap_safe(filename, varname, fallback)
  874. if exist(filename, 'file')
  875. S = load(filename);
  876. if isfield(S, varname)
  877. cmap = S.(varname);
  878. return;
  879. end
  880. end
  881. cmap = fallback;
  882. end
  883. function [starts_10Hz, starts_1Hz, starts_fMRI] = get_co2_start_indices_for_animal(animal, co2_on_indices_10Hz, co2_on_indices_10Hz_sub3, co2_on_indices_1Hz, co2_on_indices_1Hz_sub3, co2_on_indices_fMRI, co2_on_indices_fMRI_sub3)
  884. if animal == 3
  885. starts_10Hz = co2_on_indices_10Hz_sub3;
  886. starts_1Hz = co2_on_indices_1Hz_sub3;
  887. starts_fMRI = co2_on_indices_fMRI_sub3;
  888. else
  889. starts_10Hz = co2_on_indices_10Hz;
  890. starts_1Hz = co2_on_indices_1Hz;
  891. starts_fMRI = co2_on_indices_fMRI;
  892. end
  893. end
  894. function mask = build_timing_mask(num_windows, starts, ends_)
  895. mask = false(num_windows, 1);
  896. for i = 1:length(starts)
  897. s = max(1, round(starts(i)));
  898. e = min(num_windows, round(ends_(i)));
  899. if s <= e
  900. mask(s:e) = true;
  901. end
  902. end
  903. end
  904. function [idx_out, removed_states] = remove_single_subject_states(idx_in)
  905. idx_out = idx_in;
  906. removed_states = [];
  907. states = unique(idx_in(:));
  908. states = states(~isnan(states));
  909. for state = states'
  910. subject_count = sum(any(idx_in == state, 1));
  911. if subject_count == 1
  912. idx_out(idx_out == state) = NaN;
  913. removed_states(end + 1) = state; %#ok<AGROW>
  914. end
  915. end
  916. end
  917. function idx_out = replace_nan_states_with_closest(idx_in, distance_matrix)
  918. idx_out = idx_in;
  919. for animal = 1:size(idx_out, 2)
  920. for t = 1:size(idx_out, 1)
  921. if isnan(idx_out(t, animal))
  922. non_nan_states = idx_out(~isnan(idx_out(:, animal)), animal);
  923. if isempty(non_nan_states)
  924. continue;
  925. end
  926. min_distance = inf;
  927. similar_state = NaN;
  928. for s = non_nan_states'
  929. distances = distance_matrix(s, :);
  930. [min_dist, state] = min(distances);
  931. if min_dist < min_distance
  932. min_distance = min_dist;
  933. similar_state = state;
  934. end
  935. end
  936. idx_out(t, animal) = similar_state;
  937. end
  938. end
  939. end
  940. end
  941. function counts = count_states_in_range(state_vector, start_idx, end_idx, num_states)
  942. counts = zeros(num_states, 1);
  943. start_idx = max(1, round(start_idx));
  944. end_idx = min(length(state_vector), round(end_idx));
  945. if start_idx > end_idx
  946. return;
  947. end
  948. for s = 1:num_states
  949. counts(s) = sum(state_vector(start_idx:end_idx) == s);
  950. end
  951. end
  952. function trans_counts = count_transitions_in_range(state_vector, start_idx, end_idx, num_states)
  953. trans_counts = zeros(num_states, num_states);
  954. start_idx = max(1, round(start_idx));
  955. end_idx = min(length(state_vector), round(end_idx));
  956. if start_idx >= end_idx
  957. return;
  958. end
  959. for t = start_idx:(end_idx - 1)
  960. current_state = state_vector(t);
  961. next_state = state_vector(t + 1);
  962. if ~isnan(current_state) && ~isnan(next_state)
  963. trans_counts(current_state, next_state) = trans_counts(current_state, next_state) + 1;
  964. end
  965. end
  966. end
  967. function M = normalize_columns(M)
  968. denom = sum(M, 1, 'omitnan');
  969. denom(denom == 0) = NaN;
  970. M = M ./ denom;
  971. end
  972. function P = normalize_rows_2d(M)
  973. denom = sum(M, 2, 'omitnan');
  974. denom(denom == 0) = NaN;
  975. P = M ./ denom;
  976. P(isnan(P)) = 0;
  977. end
  978. function pct = safe_percent_by_column(counts)
  979. denom = sum(counts, 1);
  980. denom(denom == 0) = NaN;
  981. pct = counts ./ denom * 100;
  982. pct(isnan(pct)) = 0;
  983. end
  984. function T = normalize_transition_tensor(count_tensor)
  985. T = zeros(size(count_tensor));
  986. for animal = 1:size(count_tensor, 3)
  987. for i = 1:size(count_tensor, 1)
  988. row_sum = sum(count_tensor(i, :, animal));
  989. if row_sum > 0
  990. T(i, :, animal) = count_tensor(i, :, animal) / row_sum;
  991. end
  992. end
  993. end
  994. end
  995. function p = safe_paired_ttest(x, y)
  996. x = x(:);
  997. y = y(:);
  998. valid = ~isnan(x) & ~isnan(y);
  999. if nnz(valid) < 2 || numel(unique(x(valid) - y(valid))) < 1
  1000. p = NaN;
  1001. return;
  1002. end
  1003. [~, p] = ttest(x(valid), y(valid));
  1004. end
  1005. function p = safe_one_sample_ttest(x)
  1006. x = x(:);
  1007. x = x(~isnan(x));
  1008. if numel(x) < 2 || numel(unique(x)) < 2
  1009. p = NaN;
  1010. return;
  1011. end
  1012. [~, p] = ttest(x);
  1013. end
  1014. function plot_grouped_bars_with_paired_points(nr, nc, idx_subplot, mean_on, mean_off, sem_on, sem_off, data_on, data_off, plot_title, ylab, xtick_vals, y_limits)
  1015. subplot(nr, nc, idx_subplot);
  1016. bar_data = [mean_on, mean_off];
  1017. bar_handle = bar(bar_data, 'grouped');
  1018. hold on;
  1019. bar_handle(1).FaceColor = [0.2 0.6 0.8];
  1020. bar_handle(2).FaceColor = [0.8 0.4 0.4];
  1021. x_on = bar_handle(1).XEndPoints;
  1022. x_off = bar_handle(2).XEndPoints;
  1023. errorbar(x_on, mean_on, sem_on, 'k', 'linestyle', 'none', 'LineWidth', 1);
  1024. errorbar(x_off, mean_off, sem_off, 'k', 'linestyle', 'none', 'LineWidth', 1);
  1025. jitter_amount = 0.05;
  1026. marker_size = 22;
  1027. line_color = [0.7 0.7 0.7];
  1028. for s = 1:numel(mean_on)
  1029. jitter_vec = (rand(size(data_on, 2), 1) - 0.5) * 2 * jitter_amount;
  1030. x_on_jit = x_on(s) + jitter_vec;
  1031. x_off_jit = x_off(s) + jitter_vec;
  1032. y_on = data_on(s, :)';
  1033. y_off = data_off(s, :)';
  1034. valid_pairs = ~isnan(y_on) & ~isnan(y_off);
  1035. for a = find(valid_pairs)'
  1036. plot([x_on_jit(a), x_off_jit(a)], [y_on(a), y_off(a)], '-', 'Color', line_color, 'LineWidth', 0.8);
  1037. end
  1038. scatter(x_on_jit(~isnan(y_on)), y_on(~isnan(y_on)), marker_size, 'filled', 'MarkerFaceColor', [0 0.25 0.55], 'MarkerFaceAlpha', 0.7);
  1039. scatter(x_off_jit(~isnan(y_off)), y_off(~isnan(y_off)), marker_size, 'filled', 'MarkerFaceColor', [0.55 0 0], 'MarkerFaceAlpha', 0.7);
  1040. end
  1041. title(plot_title);
  1042. xlabel('State');
  1043. ylabel(ylab);
  1044. xticks(xtick_vals);
  1045. legend({'CO2 On', 'CO2 Off'});
  1046. if ~isempty(y_limits)
  1047. ylim(y_limits);
  1048. end
  1049. hold off;
  1050. end
  1051. function plot_transition_matrix_with_sig(nr, nc, idx_subplot, M, p_values, threshold, ttl, xl, yl, climits, cmap)
  1052. subplot(nr, nc, idx_subplot);
  1053. imagesc(M);
  1054. colorbar;
  1055. axis square;
  1056. colormap(cmap);
  1057. caxis(climits);
  1058. title(ttl);
  1059. xlabel(xl);
  1060. ylabel(yl);
  1061. hold on;
  1062. for i = 1:size(M, 1)
  1063. for j = 1:size(M, 2)
  1064. if ~isnan(p_values(i, j)) && p_values(i, j) < threshold
  1065. text(j, i, '*', 'HorizontalAlignment', 'Center', 'VerticalAlignment', 'Middle', 'Color', 'k', 'FontSize', 14);
  1066. end
  1067. end
  1068. end
  1069. hold off;
  1070. end
  1071. function plot_matrix_with_sig(nr, nc, idx_subplot, M, p_values, threshold, ttl, xl, yl, climits, cmap)
  1072. subplot(nr, nc, idx_subplot);
  1073. imagesc(M);
  1074. colorbar;
  1075. axis square;
  1076. colormap(cmap);
  1077. caxis(climits);
  1078. title(ttl);
  1079. xlabel(xl);
  1080. ylabel(yl);
  1081. hold on;
  1082. for i = 1:size(M, 1)
  1083. for j = 1:size(M, 2)
  1084. if ~isnan(p_values(i, j)) && p_values(i, j) < threshold
  1085. text(j, i, '*', 'HorizontalAlignment', 'Center', 'VerticalAlignment', 'Middle', 'Color', 'k', 'FontSize', 14);
  1086. end
  1087. end
  1088. end
  1089. hold off;
  1090. end
  1091. function y = percentile_filter(x, lower_pct, upper_pct)
  1092. x = x(~isnan(x));
  1093. if isempty(x)
  1094. y = x;
  1095. return;
  1096. end
  1097. lo = prctile(x, lower_pct);
  1098. hi = prctile(x, upper_pct);
  1099. y = x(x >= lo & x <= hi);
  1100. end
  1101. function plot_distribution_comparison(x_on, x_off, ttl)
  1102. if exist('daviolinplot', 'file') == 2
  1103. daviolinplot([x_on; x_off], 'groups', [ones(size(x_on)); 2 * ones(size(x_off))]);
  1104. title(ttl);
  1105. return;
  1106. end
  1107. boxplot([x_on; x_off], [ones(size(x_on)); 2 * ones(size(x_off))]);
  1108. set(gca, 'XTickLabel', {'CO2 On', 'CO2 Off'});
  1109. ylabel('Similarity');
  1110. title(ttl);
  1111. end
  1112. function d = cohens_d_two_sample(x, y)
  1113. x = x(~isnan(x));
  1114. y = y(~isnan(y));
  1115. if numel(x) < 2 || numel(y) < 2
  1116. d = NaN;
  1117. return;
  1118. end
  1119. nx = numel(x);
  1120. ny = numel(y);
  1121. sx = std(x, 0);
  1122. sy = std(y, 0);
  1123. s_pooled = sqrt(((nx - 1) * sx^2 + (ny - 1) * sy^2) / (nx + ny - 2));
  1124. if s_pooled == 0
  1125. d = NaN;
  1126. else
  1127. d = (mean(x) - mean(y)) / s_pooled;
  1128. end
  1129. end
  1130. function dwell_times = calculate_dwell_times(state_sequence, timing_mask, num_states)
  1131. dwell_times = nan(num_states, 1);
  1132. state_sequence = state_sequence(:);
  1133. timing_mask = timing_mask(:);
  1134. for state = 1:num_states
  1135. run_lengths = [];
  1136. in_run = false;
  1137. current_len = 0;
  1138. for t = 1:length(state_sequence)
  1139. is_selected_state = timing_mask(t) && state_sequence(t) == state;
  1140. if is_selected_state
  1141. current_len = current_len + 1;
  1142. in_run = true;
  1143. elseif in_run
  1144. run_lengths(end + 1) = current_len; %#ok<AGROW>
  1145. current_len = 0;
  1146. in_run = false;
  1147. end
  1148. end
  1149. if in_run
  1150. run_lengths(end + 1) = current_len; %#ok<AGROW>
  1151. end
  1152. if ~isempty(run_lengths)
  1153. dwell_times(state) = mean(run_lengths);
  1154. end
  1155. end
  1156. end
  1157. function entry_rates = calculate_entry_rates(state_sequence, timing_mask, num_states)
  1158. entry_rates = nan(num_states, 1);
  1159. state_sequence = state_sequence(:);
  1160. timing_mask = timing_mask(:);
  1161. total_selected = sum(timing_mask);
  1162. if total_selected == 0
  1163. return;
  1164. end
  1165. for state = 1:num_states
  1166. entries = 0;
  1167. for t = 1:length(state_sequence)
  1168. if timing_mask(t) && state_sequence(t) == state
  1169. if t == 1 || ~timing_mask(t - 1) || state_sequence(t - 1) ~= state
  1170. entries = entries + 1;
  1171. end
  1172. end
  1173. end
  1174. entry_rates(state) = entries / total_selected;
  1175. end
  1176. end
  1177. function exit_rates = calculate_exit_rates(state_sequence, timing_mask, num_states)
  1178. exit_rates = nan(num_states, 1);
  1179. state_sequence = state_sequence(:);
  1180. timing_mask = timing_mask(:);
  1181. total_selected = sum(timing_mask);
  1182. if total_selected == 0
  1183. return;
  1184. end
  1185. for state = 1:num_states
  1186. exits = 0;
  1187. for t = 1:length(state_sequence)
  1188. if timing_mask(t) && state_sequence(t) == state
  1189. is_exit = (t == length(state_sequence)) || ~timing_mask(min(t + 1, length(timing_mask))) || state_sequence(min(t + 1, length(state_sequence))) ~= state;
  1190. if is_exit
  1191. exits = exits + 1;
  1192. end
  1193. end
  1194. end
  1195. exit_rates(state) = exits / total_selected;
  1196. end
  1197. end

dfc_state_analysis.m, under CC-BY-4.0 · at the source

Overview

  1. Institute for Biomedical Engineering and Institute of Pharmacology and Toxicology, Faculty of Medicine, University of Zurich,Zurich, Switzerland
  2. Department of Information Technology and Electrical Engineering, Institute for Biomedical Engineering, ETH Zurich,Zurich, Switzerland
  3. Department of Psychiatry, Faculty of Medicine, University of Geneva,Geneva, Switzerland
  4. Department of Basic Neurosciences, Faculty of Medicine, University of Geneva,Geneva, Switzerland
  5. Institute of Precision Optical Engineering, School of Physics Science and Engineering, Tongji University,Shanghai, China
Institutions: University of Zurich (Switzerland); Institute for Biomedical Engineering (Switzerland); University of Geneva (Switzerland); Tongji University (China)
Journal: Nature communications, volume 17, issue 1, article 5158
Dates: received 18 February 2025; accepted 31 March 2026; published online 13 April 2026
Type: Research article · Language: English
License: CC BY
Identifiers: DOI 10.1038/s41467-026-71742-z · PMID 41974737 · PMCID PMC13249851 · OpenAlex W7154072756
Open access: gold, a free copy (OpenAlex)
Status: code verified
Categories: fMRI (modality), mouse (organism)
Methods: Spectral & time-frequency, Connectivity, Statistics, Machine learning, Preprocessing, fMRI & imaging, Single-unit activity, calcium imaging, Smoothing, state filtering, decompositions
Keywords: Functional magnetic resonance imaging, Fluorescence imaging, Neuro-vascular interactions
MeSH: Brain*, Hemodynamics*, Hypercapnia*, Neurons*, Neurovascular Coupling*, Animals, Calcium, Carbon Dioxide, Magnetic Resonance Imaging, Male, Mice, Mice, Inbred C57BL, Oxygen (* major topic)
Topic: Neuroscience of respiration and sleep (Endocrine and Autonomic Systems, Neuroscience), according to OpenAlex
Citations: cited by 1 paper (Europe PMC); 50 references in the paper

Abstract

Neurovascular coupling (NVC) underpins the interpretation of hemodynamic signals as proxies for neural activity, yet its response to metabolic perturbations remains poorly understood. Here, we leverage concurrent fluorescence calcium imaging and functional magnetic resonance imaging in mice expressing genetically encoded calcium indicators to dissect how elevated CO₂ levels reshape the interplay between neural and vascular responses. Our findings indicate that hypercapnia induces opposing trends in calcium and blood-oxygen-level-dependent (BOLD) responses, accompanied by global desynchronization of brain activity. Additionally, 5% CO₂ suppressed sensory-evoked BOLD and hemoglobin responses, while neuronal and astrocytic activity remained unaffected. Dynamic functional connectivity and co-activation pattern analyses further reveal a dissociation in the coordination between BOLD hemodynamic responses and their underlying neural dynamics under hypercapnic conditions. Notably, we observed that hemodynamic responses, normally driven by neuronal signaling, get attenuated with BOLD signals no longer reflecting neural activity patterns in the brain. These findings demonstrate that hypercapnia can override conventional NVC relationships, compelling a reassessment of how BOLD contrast is interpreted under hypercapnic stress in preclinical and clinical settings. This holds particular relevance for chronic hypercapnia-related conditions where a deeper understanding of NVC disruption may inform improved diagnostic and therapeutic strategies.

Reproduced under the paper's license (CC BY), from the paper cited above.

Repository

Its files are read in the Code ↔ Paper reader above, with 1 match between paragraphs and lines of code.

Zenodo 19099592

License: CC-BY-4.0
State: the link answers, verified on 29 September 2026
Evidence: files inventoried
Languages: MATLAB (2)
Size: 2 files, 2 scripts
Software Heritage: not checked
Found in: “Code availability”
Not found: README, license file, CITATION.cff, environment file, tests, continuous integration, documentation
Availability: 1 check, the latest on 29 September 2026: the link answers (HTTP 200)
  • 29 September 2026: the link answers (HTTP 200)
2 files
At the source:

Code availability

Examples of custom codes used in this manuscript are deposited and publicly available on Zenodo at 10.5281/zenodo.19099592.

Reproduced under the paper's license (CC BY), from the paper cited above.

Tracing map

Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.

What the map holds:

  • 1 repository of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
  • 2 scripts, each with its path and the digest of its content;
  • 1 match between paragraphs of the paper and lines of the code (method lexical-v1);
  • neither the text of the paper nor the code itself.

Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.

Data

No dataset and no data link were found in the paper.

Data availability

The data that support the findings of this study are available from the corresponding author. All data supporting the findings of this study are found within the paper and its Supplementary Information. Source data are provided with this paper.

Reproduced under the paper's license (CC BY), from the paper cited above.

Versions

The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.

Version 1, 29 September 2026: the first record

Recorded: type, language, journal, volume, issue, pages, dates, 5 authors, 3 keywords, 13 MeSH terms, 1 funder, 49 references.

Cite

This paper

Gezginer, I., Chen, Y., Zerbi, V., Chen, Z., & Razansky, D. (2026). Hypercapnia dissociates neuronal and hemodynamic responses impairing neurovascular coupling and functional brain connectivity. Nature communications, 17(1), 5158. https://doi.org/10.1038/s41467-026-71742-z

BibTeX

@article{gezginer2026hypercapnia,
author = {Gezginer, Irmak and Chen, Yi and Zerbi, Valerio and Chen, Zhenyue and Razansky, Daniel},
title = {{Hypercapnia dissociates neuronal and hemodynamic responses impairing neurovascular coupling and functional brain connectivity}},
journal = {Nature communications},
year = {2026},
month = apr,
volume = {17},
number = {1},
pages = {5158},
publisher = {Nature Publishing Group},
issn = {2041-1723},
doi = {10.1038/s41467-026-71742-z},
url = {https://doi.org/10.1038/s41467-026-71742-z},
pmid = {41974737},
pmcid = {PMC13249851}
}

RIS

TY - JOUR
AU - Gezginer, Irmak
AU - Chen, Yi
AU - Zerbi, Valerio
AU - Chen, Zhenyue
AU - Razansky, Daniel
TI - Hypercapnia dissociates neuronal and hemodynamic responses impairing neurovascular coupling and functional brain connectivity
T2 - Nature communications
J2 - Nat Commun
PY - 2026
DA - 2026/04/13
VL - 17
IS - 1
SP - 5158
SN - 2041-1723
PB - Nature Publishing Group
DO - 10.1038/s41467-026-71742-z
UR - https://doi.org/10.1038/s41467-026-71742-z
LA - en
ER -

CSL-JSON

{
"id": "10.1038/s41467-026-71742-z",
"type": "article-journal",
"title": "Hypercapnia dissociates neuronal and hemodynamic responses impairing neurovascular coupling and functional brain connectivity",
"container-title": "Nature communications",
"author": [
{
"family": "Gezginer",
"given": "Irmak"
},
{
"family": "Chen",
"given": "Yi"
},
{
"family": "Zerbi",
"given": "Valerio"
},
{
"family": "Chen",
"given": "Zhenyue"
},
{
"family": "Razansky",
"given": "Daniel"
}
],
"container-title-short": "Nat Commun",
"volume": "17",
"issue": "1",
"page": "5158",
"DOI": "10.1038/s41467-026-71742-z",
"PMID": "41974737",
"PMCID": "PMC13249851",
"ISSN": "2041-1723",
"publisher": "Nature Publishing Group",
"URL": "https://doi.org/10.1038/s41467-026-71742-z",
"language": "en",
"issued": {
"date-parts": [
[
2026,
4,
13
]
]
}
}

The tracing map gets a citation of its own once an author has validated it and it has a DOI.

Similar papers

The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.

[1] doi:10.1038/s41467-026-71746-9
Double-helix optical point spread function enables real-time mesoscopic 3D functional microangiography in the living mouse brain and skull.
Journal: Nature communications
In common: mouse, 3 authors
[2] doi:10.64898/2026.03.12.710517 [code]
Cortical excitability inversely modulates fMRI connectivity via low-frequency neuronal coupling
Journal: bioRxiv (preprint)
In common: Image Processing Toolbox, Signal Processing Toolbox, Statistics and Machine Learning Toolbox, fMRI, 1 reference, author Valerio Zerbi
[3] doi:10.1038/s41592-026-03154-2 [code]
Simultaneous single-cell calcium imaging of neuronal population activity and brain-wide BOLD fMRI.
Journal: Nature methods
In common: Image Processing Toolbox, Signal Processing Toolbox, Statistics and Machine Learning Toolbox, fMRI, mouse, 2 references
[4] doi:10.1162/imag.a.1254 [code]
The individuality of single-frame functional brain connectivity.
Journal: Imaging neuroscience (Cambridge, Mass.)
In common: Signal Processing Toolbox, Statistics and Machine Learning Toolbox, fMRI, 3 references
[5] doi:10.1016/j.bpsgos.2026.100753 [code]
Dynamic Repertoire of Brain Networks in Mindfulness-Based Cognitive Therapy During Rumination: A Randomized Controlled Trial.
Journal: Biological psychiatry global open science
In common: Image Processing Toolbox, Signal Processing Toolbox, Statistics and Machine Learning Toolbox, fMRI, 2 references
[6] doi:10.1093/braincomms/fcag279 [code]
Network flexibility facilitates treatment-induced recovery in post-stroke aphasia.
Journal: Brain communications
In common: Image Processing Toolbox, Statistics and Machine Learning Toolbox, fMRI, 3 references
[7] doi:10.1162/imag.a.1278 [code]
Young and old adult brains experience opposite effects of acute sleep restriction on the functional connectivity network.
Journal: Imaging neuroscience (Cambridge, Mass.)
In common: Image Processing Toolbox, Signal Processing Toolbox, Statistics and Machine Learning Toolbox, fMRI, 2 references
[8] doi:10.1162/imag.a.1357
Biphasic acclimation for simultaneous wide-field fluorescent Ca&lt;sup&gt;2+&lt;/sup&gt; imaging and fMRI of awake mice.
Journal: Imaging neuroscience (Cambridge, Mass.)
In common: fMRI, mouse, 4 references
[9] doi:10.1162/imag.a.1202
Recurring transient brain-wide co-activation patterns from EEG spatially resembling time-averaged resting-state networks.
Journal: Imaging neuroscience (Cambridge, Mass.)
In common: fMRI, 4 references
[10] doi:10.1016/j.bbih.2026.101274 [code]
Brain dynamics of attentional, default-mode and limbic networks are disrupted at rest in post-COVID-19 syndrome.
Journal: Brain, behavior, & immunity - health
In common: Signal Processing Toolbox, Statistics and Machine Learning Toolbox, fMRI, 2 references

Contribute

The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.

Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.

Request its removal

To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).

Discussion, reproductions, activity

Discussion: questions and error reports about this paper and its code, from signed-in readers and its authors. It opens with sign-in.

Reproductions: reports from readers who ran the authors' code: what they reproduced, with which environment, commit and data. It opens with sign-in.

Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.