Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions +nla/+edge/+result/Base.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

methods
function obj = Base(size, prob_max)
import nla.* % required due to matlab package system quirks
import nla.TriMatrix

if nargin ~= 0
obj.coeff = TriMatrix(size);
obj.prob = TriMatrix(size);
Expand All @@ -25,7 +26,6 @@
end

function output(obj, net_atlas, flags, prob_label)
import nla.* % required due to matlab package system quirks

coeff_label = sprintf('Edge-level %s', obj.coeff_name);
prob_label_appended = '';
Expand All @@ -34,8 +34,8 @@ function output(obj, net_atlas, flags, prob_label)
prob_label_appended = sprintf(' (%s)', obj.behavior_name);
end

fig = gfx.createFigure();
matrix_plot = gfx.plots.MatrixPlot(fig, coeff_label, obj.coeff, net_atlas.nets, gfx.FigSize.LARGE, 'lower_limit', obj.coeff_range(1),...
fig = nla.gfx.createFigure();
matrix_plot = nla.gfx.plots.MatrixPlot(fig, coeff_label, obj.coeff, net_atlas.nets, nla.gfx.FigSize.LARGE, 'lower_limit', obj.coeff_range(1),...
'upper_limit', obj.coeff_range(2));
matrix_plot.displayImage();
w = matrix_plot.image_dimensions("image_width");
Expand All @@ -45,7 +45,7 @@ function output(obj, net_atlas, flags, prob_label)
if ~exist('prob_label', 'var')
prob_label = [sprintf('Edge-level Significance (P < %g)', obj.prob_max), prob_label_appended];
end
matrix_plot2 = gfx.plots.MatrixPlot(fig, prob_label, obj.prob_sig, net_atlas.nets, gfx.FigSize.LARGE,...
matrix_plot2 = nla.gfx.plots.MatrixPlot(fig, prob_label, obj.prob_sig, net_atlas.nets, nla.gfx.FigSize.LARGE,...
'draw_legend', false, 'draw_colorbar', false, 'color_map', [[1,1,1];[0,0,0]], 'x_position', w, 'lower_limit', 0, 'upper_limit', 1);
w2 = matrix_plot2.image_dimensions("image_width");
h2 = matrix_plot2.image_dimensions("image_height");
Expand All @@ -58,7 +58,7 @@ function output(obj, net_atlas, flags, prob_label)
%prob_log.v = -1 * log10(obj.prob.v);
cm_base = parula(1000);
cm = flip(cm_base(ceil(logspace(-3, 0, 256) .* 1000), :));
matrix_plot2 = gfx.plots.MatrixPlot(fig, prob_label, obj.prob, net_atlas.nets, gfx.FigSize.LARGE,...
matrix_plot2 = nla.gfx.plots.MatrixPlot(fig, prob_label, obj.prob, net_atlas.nets, nla.gfx.FigSize.LARGE,...
'draw_legend', false, 'color_map', cm, 'x_position', w, 'lower_limit', 0, 'upper_limit', 1);
w2 = matrix_plot2.image_dimensions("image_width");
h2 = matrix_plot2.image_dimensions("image_height");
Expand Down
2 changes: 0 additions & 2 deletions +nla/+edge/+result/Precalculated.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

methods
function obj = Precalculated(size, prob_max)
import nla.* % required due to matlab package system quirks
% hack because superclass constructor can't be optional??
if nargin == 0
size = 2;
prob_max = -1;
Expand Down
4 changes: 1 addition & 3 deletions +nla/+edge/+result/WelchT.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

methods
function obj = WelchT(size, prob_max, group_names)
import nla.* % required due to matlab package system quirks
% hack because superclass constructor can't be optional??
if nargin == 0
size = 2;
prob_max = -1;
Expand All @@ -18,7 +16,7 @@
obj@nla.edge.result.Base(size, prob_max);

if nargin ~= 0
obj.dof = TriMatrix(size);
obj.dof = nla.TriMatrix(size);
obj.behavior_name = sprintf("%s > %s", group_names{1}, group_names{2});
obj.coeff_range = [-3 3];
end
Expand Down
4 changes: 1 addition & 3 deletions +nla/+edge/+test/KendallB.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@

methods
function obj = KendallB()
import nla.* % required due to matlab package system quirks
obj@nla.edge.BaseTest();
end

function result = run(obj, input_struct)
import nla.* % required due to matlab package system quirks
[tau_vec, p_vec] = mex.run('kendallTauB', input_struct.behavior, input_struct.func_conn.v');
[tau_vec, p_vec] = nla.mex.run('kendallTauB', input_struct.behavior, input_struct.func_conn.v');
result = obj.composeResult(input_struct.net_atlas, tau_vec', p_vec', input_struct.prob_max);
end
end
Expand Down
1 change: 0 additions & 1 deletion +nla/+edge/+test/Pearson.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

methods
function obj = Pearson()
import nla.* % required due to matlab package system quirks
obj@nla.edge.BaseTest();
end

Expand Down
18 changes: 13 additions & 5 deletions +nla/+edge/+test/Precalculated.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

methods
function obj = Precalculated()
import nla.* % required due to matlab package system quirks
obj@nla.edge.BaseTest();
end

Expand All @@ -31,10 +30,19 @@

methods (Static)
function inputs = requiredInputs()
import nla.* % required due to matlab package system quirks
npairs_x_nperms = [inputField.DimensionType.NROIPAIRS, inputField.DimensionType.NPERMS];
npairs_x_1 = [inputField.DimensionType.NROIPAIRS, 1];
inputs = {inputField.NumberWithoutDefault('coeff_min', 'Coeff minimum', -Inf, Inf), inputField.NumberWithoutDefault('coeff_max', 'Coeff maximum', -Inf, Inf), inputField.NetworkAtlas(), inputField.EdgeLevelMatrix('precalc_obs_p', 'Precalculated observed significance (thresholded p-value)', npairs_x_1), inputField.EdgeLevelMatrix('precalc_obs_coeff', 'Precalculated observed coeff', npairs_x_1), inputField.EdgeLevelMatrix('precalc_perm_p', 'Precalculated permuted significance (thresholded p-value)', npairs_x_nperms), inputField.EdgeLevelMatrix('precalc_perm_coeff', 'Precalculated permuted coeff', npairs_x_nperms)};
import nla.inputField.DimensionType nla.inputField.NumberWithoutDefault nla.inputField.EdgeLevelMatrix

npairs_x_nperms = [DimensionType.NROIPAIRS,DimensionType.NPERMS];
npairs_x_1 = [DimensionType.NROIPAIRS, 1];
inputs = {...
NumberWithoutDefault('coeff_min', 'Coeff minimum', -Inf, Inf),...
NumberWithoutDefault('coeff_max', 'Coeff maximum', -Inf, Inf),...
inputField.NetworkAtlas(),...
EdgeLevelMatrix('precalc_obs_p', 'Precalculated observed significance (thresholded p-value)', npairs_x_1),...
EdgeLevelMatrix('precalc_obs_coeff', 'Precalculated observed coeff', npairs_x_1),...
EdgeLevelMatrix('precalc_perm_p', 'Precalculated permuted significance (thresholded p-value)', npairs_x_nperms),...
EdgeLevelMatrix('precalc_perm_coeff', 'Precalculated permuted coeff', npairs_x_nperms)...
};
end
end
end
Expand Down
1 change: 0 additions & 1 deletion +nla/+edge/+test/Spearman.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

methods
function obj = Spearman()
import nla.* % required due to matlab package system quirks
obj@nla.edge.BaseTest();
end

Expand Down
4 changes: 1 addition & 3 deletions +nla/+edge/+test/SpearmanEstimator.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@

methods
function obj = SpearmanEstimator()
import nla.* % required due to matlab package system quirks
obj@nla.edge.BaseTest();
end

function result = run(obj, input_struct)
import nla.* % required due to matlab package system quirks
%% input
y = input_struct.func_conn.v';

Expand Down Expand Up @@ -78,7 +76,7 @@
ok = (abs(rho_vec) < 1);
t(ok) = rho_vec(ok) .* sqrt((n - 2) ./ (1 - rho_vec(ok) .^ 2));

result = obj.composeResult(input_struct.net_atlas, fisherR2Z(rho_vec), (2 * tcdf(-abs(t), n - 2)), input_struct.prob_max);
result = obj.composeResult(input_struct.net_atlas, nla.fisherR2Z(rho_vec), (2 * tcdf(-abs(t), n - 2)), input_struct.prob_max);
end
end
end
Expand Down
13 changes: 5 additions & 8 deletions +nla/+edge/+test/WelchT.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@

methods
function obj = WelchT()
import nla.* % required due to matlab package system quirks
obj@nla.edge.BaseTest();
end

function result = run(obj, input_struct)
import nla.* % required due to matlab package system quirks
% This function calculates the t-test between 2 sets of data using the
% Welch method that does not assume equal mean or variance or samples. The
% function returns the t-statistic, p-value, and degrees of freedom.
Expand Down Expand Up @@ -48,17 +46,16 @@

methods (Static)
function inputs = requiredInputs()
import nla.* % required due to matlab package system quirks
inputs = requiredInputs@nla.edge.BaseTest();

% disable adding/modifying covariates in behavior
behavior_handle = helpers.firstInstanceOfClass(inputs, 'nla.inputField.Behavior');
behavior_handle = nla.helpers.firstInstanceOfClass(inputs, 'nla.inputField.Behavior');
behavior_handle.covariates_enabled = nla.inputField.CovariatesEnabled.ONLY_FC;

inputs{end + 1} = inputField.String('group1_name', 'Group 1 name:', 'Group1');
inputs{end + 1} = inputField.Number('group1_val', 'Group 1 behavior value:', -Inf, 1, Inf);
inputs{end + 1} = inputField.String('group2_name', 'Group 2 name:', 'Group2');
inputs{end + 1} = inputField.Number('group2_val', 'Group 2 behavior value:', -Inf, 0, Inf);
inputs{end + 1} = nla.inputField.String('group1_name', 'Group 1 name:', 'Group1');
inputs{end + 1} = nla.inputField.Number('group1_val', 'Group 1 behavior value:', -Inf, 1, Inf);
inputs{end + 1} = nla.inputField.String('group2_name', 'Group 2 name:', 'Group2');
inputs{end + 1} = nla.inputField.Number('group2_val', 'Group 2 behavior value:', -Inf, 0, Inf);
end
end
end
Expand Down
5 changes: 2 additions & 3 deletions +nla/+edge/BaseTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

methods
function obj = BaseTest()
import nla.* % required due to matlab package system quirks
end
end

Expand All @@ -33,8 +32,8 @@

methods (Static)
function inputs = requiredInputs()
import nla.* % required due to matlab package system quirks
inputs = {inputField.Number('prob_max', 'Edge-level P threshold <', 0, 0.05, 1), inputField.NetworkAtlasFuncConn(), inputField.Behavior()};
inputs = {nla.inputField.Number('prob_max', 'Edge-level P threshold <', 0, 0.05, 1),...
nla.inputField.NetworkAtlasFuncConn(), nla.inputField.Behavior()};
end
end
end
17 changes: 9 additions & 8 deletions +nla/+gfx/anatToMesh.m
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
function [mesh_l, mesh_r] = anatToMesh(anat, ctx, view_pos)
import nla.gfx.ViewPos nla.gfx.MeshType

%ANATTOMESH generate cortex hemisphere mesh from anatomy
% anat: anatomy struct, contained in cortex mesh files
% ctx: MeshType value, what inflation level of mesh to use
% view_pos: ViewPos value, which standard view to use
% mesh_l: mesh of left hemisphere of brain
% mesh_r: mesh of right hemisphere of brain
import nla.* % required due to matlab package system quirks
%% Choose inflation
switch ctx
case gfx.MeshType.STD
case MeshType.STD
mesh_l = anat.hemi_l.nodes;
mesh_r = anat.hemi_r.nodes;
case gfx.MeshType.INF
case MeshType.INF
mesh_l = anat.hemi_l.Inodes;
mesh_r = anat.hemi_r.Inodes;
case gfx.MeshType.VINF
case MeshType.VINF
mesh_l = anat.hemi_l.VInodes;
mesh_r = anat.hemi_r.VInodes;
end
Expand All @@ -24,18 +25,18 @@
mesh_r(:,1) = mesh_r(:,1) - min(mesh_r(:,1));

%% Rotate if necessary
if view_pos == gfx.ViewPos.LAT || view_pos == gfx.ViewPos.MED
if view_pos == ViewPos.LAT || view_pos == ViewPos.MED
dy = -5;
% rotate right hemi around and move to position for visualization
cmL = mean(mesh_l, 1);
cmR = mean(mesh_r, 1);
rm = helpers.rotationMatrix(Dir.Z, pi);
rm = nla.helpers.rotationMatrix(Dir.Z, pi);

% Rotate
switch view_pos
case gfx.ViewPos.LAT
case ViewPos.LAT
mesh_r = (mesh_r - (repmat(cmR, size(mesh_r, 1), 1))) * rm + (repmat(cmR, size(mesh_r, 1), 1));
case gfx.ViewPos.MED
case ViewPos.MED
mesh_l = (mesh_l - (repmat(cmL, size(mesh_l, 1), 1))) * rm + (repmat(cmL, size(mesh_l, 1), 1));
end
mesh_r(:, 1) = mesh_r(:, 1) + (cmL(:, 1) - cmR(:, 1)); % Shift over to same YZ plane
Expand Down
1 change: 0 additions & 1 deletion +nla/+gfx/colorChunk.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
function chunk = colorChunk(color, h, w)
import nla.* % required due to matlab package system quirks
%COLORCHUNK create a matrix of size h * w * 3, filled with color
chunk = repmat(reshape(color,1,1,[]), h, w);
end
Expand Down
2 changes: 1 addition & 1 deletion +nla/+gfx/createFigure.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
%toolbar, etc. settings.
% w: width in pixels
% h: height in pixels
import nla.* % required due to matlab package system quirks

fig = figure('Color', 'w', 'Resize', 'off', 'Name', 'NLA Figure', 'NumberTitle','off');
%fig.Icon = [findRootPath() 'thumb.png'];
if exist('w', 'var') && exist('h', 'var')
Expand Down
46 changes: 25 additions & 21 deletions +nla/+gfx/drawBrainVis.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ function drawBrainVis(edge_input_struct, input_struct, net_atlas, ctx, mesh_alph
% net2: Network to view correlations between
% sig_based: whether the net-level test is based on p-values
% thresholded by significance (for example, Chi2, HG)

import nla.* % required due to matlab package system quirks

fc_exists = isfield(edge_input_struct, 'func_conn');

Expand All @@ -26,7 +24,7 @@ function drawBrainVis(edge_input_struct, input_struct, net_atlas, ctx, mesh_alph
end

%% Display figures
fig = gfx.createFigure(1550, 750);
fig = nla.gfx.createFigure(1550, 750);
figure_title = sprintf('Brain Visualization: Average of edge-level correlations between nets in [%s - %s] Network Pair', net_atlas.nets(net1).name, net_atlas.nets(net2).name);

if sig_based
Expand Down Expand Up @@ -98,13 +96,15 @@ function drawBrainVis(edge_input_struct, input_struct, net_atlas, ctx, mesh_alph
end

function cols = valsToColor(ROI_vals, fc_vals, color_map, color_map_p, color_map_n, color_fc, llimit, ulimit)
import nla.gfx.valToColor

if color_fc
cols_p = gfx.valToColor(fc_vals, -0.5, 0.5, color_map_p);
cols_n = gfx.valToColor(fc_vals, -0.5, 0.5, color_map_n);
cols_p = valToColor(fc_vals, -0.5, 0.5, color_map_p);
cols_n = valToColor(fc_vals, -0.5, 0.5, color_map_n);
cols(ROI_vals > 0, :) = cols_p(ROI_vals > 0, :);
cols(ROI_vals <= 0, :) = cols_n(ROI_vals <= 0, :);
else
cols = gfx.valToColor(ROI_vals, llimit, ulimit, color_map);
cols = valToColor(ROI_vals, llimit, ulimit, color_map);
end
end

Expand All @@ -121,7 +121,7 @@ function drawROISpheres(ROI_pos, ax, net_atlas, net1, net2, ROI_radius, conn_map

if conn_map(j)
% render a sphere at each ROI location
gfx.drawSphere(ax, ROI_pos(j, :), net_atlas.nets(n).color, ROI_radius);
nla.gfx.drawSphere(ax, ROI_pos(j, :), net_atlas.nets(n).color, ROI_radius);
end
end
end
Expand All @@ -148,19 +148,23 @@ function drawEdges(ROI_pos, ax, net_atlas, net1, net2, color_map, color_map_p, c
if ~isempty(val)
col = valsToColor(val, fc_val_avg, color_map, color_map_p, color_map_n, color_fc && fc_exists, llimit, ulimit);
col = [reshape(col, [1, 3]), 0.5];
p = plot3(ax, [ROI_pos(n1, 1), ROI_pos(n2, 1)], [ROI_pos(n1, 2), ROI_pos(n2, 2)], [ROI_pos(n1, 3), ROI_pos(n2, 3)], 'Color', col, 'LineWidth', 5);
p = plot3(ax, [ROI_pos(n1, 1), ROI_pos(n2, 1)], [ROI_pos(n1, 2), ROI_pos(n2, 2)],...
[ROI_pos(n1, 3), ROI_pos(n2, 3)], 'Color', col, 'LineWidth', 5);
p.Annotation.LegendInformation.IconDisplayStyle = 'off';
end
end
end
end

function onePlot(ax, pos, color_mode, color_mat)
if color_mode == gfx.BrainColorMode.NONE
ROI_final_pos = gfx.drawROIsOnCortex(ax, net_atlas, ctx, mesh_alpha, ROI_radius, pos, surface_parcels, gfx.BrainColorMode.NONE);
drawEdges(ROI_final_pos, ax, net_atlas, net1, net2, color_map, color_map_p, color_map_n, color_fc, fc_exists, llimit, ulimit, edge_input_struct, edge_result, sig_based);
if color_mode == nla.gfx.BrainColorMode.NONE
ROI_final_pos = nla.gfx.drawROIsOnCortex(ax, net_atlas, ctx, mesh_alpha, ROI_radius, pos, surface_parcels,...
nla.gfx.BrainColorMode.NONE);
drawEdges(ROI_final_pos, ax, net_atlas, net1, net2, color_map, color_map_p, color_map_n, color_fc, fc_exists,...
llimit, ulimit, edge_input_struct, edge_result, sig_based);
else
ROI_final_pos = gfx.drawROIsOnCortex(ax, net_atlas, ctx, 1, ROI_radius, pos, surface_parcels, gfx.BrainColorMode.COLOR_ROIS, color_mat);
ROI_final_pos = nla.gfx.drawROIsOnCortex(ax, net_atlas, ctx, 1, ROI_radius, pos, surface_parcels,...
nla.gfx.BrainColorMode.COLOR_ROIS, color_mat);
end

if show_ROI_centroids
Expand All @@ -169,13 +173,13 @@ function onePlot(ax, pos, color_mode, color_mat)
end

if surface_parcels && ~islogical(net_atlas.parcels)
onePlot(subplot('Position',[.45,0.505,.53,.45]), gfx.ViewPos.LAT, gfx.BrainColorMode.COLOR_ROIS, color_mat);
onePlot(subplot('Position',[.45,0.055,.53,.45]), gfx.ViewPos.MED, gfx.BrainColorMode.COLOR_ROIS, color_mat);
onePlot(subplot('Position',[.45,0.505,.53,.45]), nla.gfx.ViewPos.LAT, nla.gfx.BrainColorMode.COLOR_ROIS, color_mat);
onePlot(subplot('Position',[.45,0.055,.53,.45]), nla.gfx.ViewPos.MED, nla.gfx.BrainColorMode.COLOR_ROIS, color_mat);
else
onePlot(subplot('Position',[.45,0.505,.26,.45]), gfx.ViewPos.BACK, gfx.BrainColorMode.NONE);
onePlot(subplot('Position',[.73,0.505,.26,.45]), gfx.ViewPos.FRONT, gfx.BrainColorMode.NONE);
onePlot(subplot('Position',[.45,0.055,.26,.45]), gfx.ViewPos.LEFT, gfx.BrainColorMode.NONE);
onePlot(subplot('Position',[.73,0.055,.26,.45]), gfx.ViewPos.RIGHT, gfx.BrainColorMode.NONE);
onePlot(subplot('Position',[.45,0.505,.26,.45]), nla.gfx.ViewPos.BACK, nla.gfx.BrainColorMode.NONE);
onePlot(subplot('Position',[.73,0.505,.26,.45]), nla.gfx.ViewPos.FRONT, nla.gfx.BrainColorMode.NONE);
onePlot(subplot('Position',[.45,0.055,.26,.45]), nla.gfx.ViewPos.LEFT, nla.gfx.BrainColorMode.NONE);
onePlot(subplot('Position',[.73,0.055,.26,.45]), nla.gfx.ViewPos.RIGHT, nla.gfx.BrainColorMode.NONE);
end

if color_fc
Expand All @@ -185,9 +189,9 @@ function onePlot(ax, pos, color_mode, color_mat)
end

if surface_parcels && ~islogical(net_atlas.parcels)
onePlot(ax, gfx.ViewPos.DORSAL, gfx.BrainColorMode.COLOR_ROIS, color_mat);
onePlot(ax, nla.gfx.ViewPos.DORSAL, nla.gfx.BrainColorMode.COLOR_ROIS, color_mat);
else
onePlot(ax, gfx.ViewPos.DORSAL, gfx.BrainColorMode.NONE);
onePlot(ax, nla.gfx.ViewPos.DORSAL, nla.gfx.BrainColorMode.NONE);
end

light('Position',[0,100,100],'Style','local');
Expand All @@ -206,7 +210,7 @@ function onePlot(ax, pos, color_mode, color_mat)
end
end
hold(ax, 'off');
gfx.hideAxes(ax);
nla.gfx.hideAxes(ax);

%% Display colormap
if color_fc
Expand Down
Loading