Skip to content

Commit 610b819

Browse files
authored
[NET-276] Allow txt and csv functional connectivity files (#114)
enable csv txt and multiple txt
1 parent 8f438d1 commit 610b819

1 file changed

Lines changed: 80 additions & 49 deletions

File tree

+nla/+inputField/NetworkAtlasFuncConn.m

Lines changed: 80 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@
3737
label_gap = LABEL_GAP;
3838
h = LABEL_H * 2 + label_gap;
3939

40-
%% Create label
40+
%% NETWORK ATLAS
41+
42+
% Create label
4143
if ~isgraphics(obj.label)
4244
obj.label = uilabel(parent);
4345
end
@@ -46,14 +48,14 @@
4648
obj.label.HorizontalAlignment = 'left';
4749
obj.label.Position = [x, y - LABEL_H, label_w + label_gap, LABEL_H];
4850

49-
%% Create button
51+
% Create button
5052
if ~isgraphics(obj.button)
5153
obj.button = uibutton(parent, 'push', 'ButtonPushedFcn', @(h,e)obj.buttonClickedCallback());
5254
end
5355
button_w = 100;
5456
obj.button.Position = [x + label_w + label_gap, y - LABEL_H, button_w, LABEL_H];
5557

56-
%% Mesh inflation selector
58+
% Mesh inflation selector
5759
if ~isgraphics(obj.inflation_label)
5860
obj.inflation_label = uilabel(parent);
5961
obj.inflation_label.HorizontalAlignment = 'right';
@@ -70,15 +72,15 @@
7072
end
7173
obj.inflation_dropdown.Position = [0, y - LABEL_H, inflation_dropdown_w, LABEL_H];
7274

73-
%% 'View as surface parcel' checkbox
75+
% 'View as surface parcel' checkbox
7476
checkbox_surface_parcels_w = 108;
7577
if ~isgraphics(obj.checkbox_surface_parcels)
7678
obj.checkbox_surface_parcels = uicheckbox(parent);
7779
obj.checkbox_surface_parcels.Text = ' Surface parcels';
7880
end
7981
obj.checkbox_surface_parcels.Position = [0, y - LABEL_H, checkbox_surface_parcels_w, LABEL_H];
8082

81-
%% Create view button
83+
% Create view button
8284
if ~isgraphics(obj.button_view_net_atlas)
8385
obj.button_view_net_atlas = uibutton(parent, 'push', 'ButtonPushedFcn',...
8486
@(h,e)obj.buttonViewNetAtlasClickedCallback());
@@ -88,8 +90,10 @@
8890
obj.button_view_net_atlas.Position = [0, y - LABEL_H, button_view_net_atlas_w, LABEL_H];
8991

9092
w = label_w + label_gap + button_w + label_gap + checkbox_surface_parcels_w + label_gap + button_view_net_atlas_w;
91-
92-
%% Create label2
93+
%%
94+
95+
%% FUNCTIONAL CONNECTIVITY
96+
% Create label2
9397
if ~isgraphics(obj.label2)
9498
obj.label2 = uilabel(parent);
9599
end
@@ -98,14 +102,14 @@
98102
obj.label2.HorizontalAlignment = 'left';
99103
obj.label2.Position = [x, y - h, label2_w + label_gap, LABEL_H];
100104

101-
%% Create button2
105+
% Create button2
102106
if ~isgraphics(obj.button2)
103107
obj.button2 = uibutton(parent, 'push', 'ButtonPushedFcn', @(h,e)obj.button2ClickedCallback());
104108
end
105109
button2_w = 100;
106110
obj.button2.Position = [x + label2_w + label_gap, y - h, button2_w, LABEL_H];
107111

108-
%% Create view button
112+
% Create view button
109113
if ~isgraphics(obj.button_view_fc_avg)
110114
obj.button_view_fc_avg = uibutton(parent, 'push', 'ButtonPushedFcn', @(h,e)obj.buttonViewFCAvgClickedCallback());
111115
end
@@ -116,6 +120,7 @@
116120

117121
w2 = label2_w + label_gap + button2_w + label_gap + button_view_fc_avg_w;
118122
w = max(w, w2);
123+
%%
119124
end
120125

121126
function undraw(obj)
@@ -204,55 +209,81 @@ function buttonClickedCallback(obj, ~)
204209
end
205210

206211
function button2ClickedCallback(obj, ~)
207-
[file, path, idx] = uigetfile({'*.mat', 'Functional connectivity matrix (*.mat)'}, 'Select Functional Connectivity Matrix');
208-
if idx == 1
209-
prog = uiprogressdlg(obj.fig, 'Title', 'Loading functional connectivity data', 'Message',...
210-
sprintf('Loading %s', file), 'Indeterminate', true);
211-
drawnow;
212-
212+
[file, path, idx] = uigetfile(...
213+
{'*.mat', 'MATLAB File (*.mat)'; '*.csv', 'Comma-separated Values (*.csv)'; '*.txt', 'Text file (*.txt)'},...
214+
'Select Functional Connectivity Matrix', 'MultiSelect', 'on'...
215+
);
216+
text_file = file;
217+
if iscell(file)
218+
text_file = file{1};
219+
end
220+
prog = uiprogressdlg(obj.fig, 'Title', 'Loading functional connectivity data', 'Message',...
221+
sprintf('Loading %s', text_file), 'Indeterminate', true);
222+
drawnow;
223+
224+
fc_unordered = false;
225+
if idx == 1
213226
fc_data = load([path file]);
214-
fc_unordered = false;
215-
if isnumeric(fc_data)
216-
fc_unordered = fc_data;
217-
elseif isstruct(fc_data)
218-
if isfield(fc_data, 'functional_connectivity')
219-
fc_unordered = fc_data.functional_connectivity;
220-
elseif isfield(fc_data, 'func_conn')
221-
fc_unordered = fc_data.func_conn;
222-
elseif isfield(fc_data, 'fc')
223-
fc_unordered = fc_data.fc;
224-
else
225-
fn = fieldnames(fc_data);
226-
if numel(fn) == 1
227-
fname = fn{1};
228-
if isnumeric(fc_data.(fname))
229-
fc_unordered = fc_data.(fname);
230-
end
227+
else
228+
if iscell(file)
229+
fc_data = readmatrix([path file{1}]);
230+
for current_file = 2:numel(file)
231+
fc_data(:,:,current_file) = readmatrix([path file{current_file}]);
232+
end
233+
else
234+
fc_data = readmatrix([path file]);
235+
fc_data_size = size(fc_data);
236+
if numel(fc_data_size) == 2 && fc_data_size(1) ~= fc_data_size(2)
237+
greater_dimension = fc_data_size(2);
238+
lesser_dimension = fc_data_size(1);
239+
if fc_data_size(1) > fc_data_size(2)
240+
greater_dimension = fc_data_size(1);
241+
lesser_dimension = fc_data_size(2);
231242
end
243+
third_dimension = greater_dimension / lesser_dimension;
244+
fc_data = reshape(fc_data, [lesser_dimension, lesser_dimension, third_dimension]);
232245
end
233246
end
247+
end
234248

235-
% functional connectivity matrix (not ordered/trimmed according to network atlas yet)
236-
if ~islogical(fc_unordered)
237-
obj.func_conn_unordered = double(fc_unordered);
238-
239-
%% Transform R-values to Z-scores
240-
% If this condition isn't true, it cannot be R values
241-
% If it is true, it is almost certainly R values but might not be
242-
if all(abs(obj.func_conn_unordered(:)) <= 1)
243-
sel = uiconfirm(obj.fig, sprintf('Fisher Z transform functional connectivity data?\n(If you have provided R-values)'), 'Fisher Z transform?');
244-
if strcmp(sel, 'Ok')
245-
obj.func_conn_unordered = nla.fisherR2Z(obj.func_conn_unordered);
249+
if isnumeric(fc_data)
250+
fc_unordered = fc_data;
251+
elseif isstruct(fc_data)
252+
if isfield(fc_data, 'functional_connectivity')
253+
fc_unordered = fc_data.functional_connectivity;
254+
elseif isfield(fc_data, 'func_conn')
255+
fc_unordered = fc_data.func_conn;
256+
elseif isfield(fc_data, 'fc')
257+
fc_unordered = fc_data.fc;
258+
else
259+
fn = fieldnames(fc_data);
260+
if numel(fn) == 1
261+
fname = fn{1};
262+
if isnumeric(fc_data.(fname))
263+
fc_unordered = fc_data.(fname);
246264
end
247265
end
248-
249-
obj.update();
250-
close(prog);
251-
else
252-
close(prog);
253-
uialert(obj.fig, sprintf('Could not load functional connectivity matrix from %s', file), 'Invalid functional connectivity file');
254266
end
255267
end
268+
269+
% functional connectivity matrix (not ordered/trimmed according to network atlas yet)
270+
if ~islogical(fc_unordered)
271+
obj.func_conn_unordered = double(fc_unordered);
272+
273+
%% Transform R-values to Z-scores
274+
% If this condition isn't true, it cannot be R values
275+
% If it is true, it is almost certainly R values but might not be
276+
if all(abs(obj.func_conn_unordered(:)) <= 1)
277+
sel = uiconfirm(obj.fig, sprintf('Fisher Z transform functional connectivity data?\n(If you have provided R-values)'), 'Fisher Z transform?');
278+
if strcmp(sel, 'Ok')
279+
obj.func_conn_unordered = nla.fisherR2Z(obj.func_conn_unordered);
280+
end
281+
end
282+
obj.update();
283+
else
284+
uialert(obj.fig, sprintf('Could not load functional connectivity matrix from %s', file), 'Invalid functional connectivity file');
285+
end
286+
close(prog);
256287
end
257288

258289
function buttonViewNetAtlasClickedCallback(obj)

0 commit comments

Comments
 (0)