Skip to content

Commit

Permalink
Added more detailed interface for analysing MVA results
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanRace committed Oct 20, 2017
1 parent 41a83fe commit ce401cd
Show file tree
Hide file tree
Showing 5 changed files with 269 additions and 136 deletions.
Binary file modified lib/jimzMLParser/jimzMLParser-1.0-SNAPSHOT.jar
Binary file not shown.
4 changes: 4 additions & 0 deletions src/core/ProjectedDataInMemory.m
Expand Up @@ -34,6 +34,10 @@ function setData(obj, data, projectionMatrix, pixelSelection, isRowMajor, spectr
spectrum = SpectralData(spectrum.spectralChannels, intensities);
end

function spectrum = getProjectedSpectrum(obj, index)
spectrum = SpectralData(obj.spectralChannels, obj.projectionMatrix(:, index));
end

function [image] = getProjectedImage(obj, index)
image = zeros(obj.height, obj.width);

Expand Down
155 changes: 20 additions & 135 deletions src/gui/DataViewer.m
Expand Up @@ -27,8 +27,6 @@
% </html>
preprocessingWorkflow;

regionOfInterestList;

% Data that has been generated and should be shown in the
imageListGenerated;
imageList;
Expand Down Expand Up @@ -95,12 +93,6 @@
coefficientLabel;

regionOfInterestPanel;
regionOfInterestTable;
editRegionOfInterestButton;
saveRegionOfInterestButton;
loadRegionOfInterestButton;
infoRegionOfInterestButton;
selectedROIs;

preprocessingPanel;
preprocessingLabel;
Expand All @@ -115,7 +107,7 @@

statusBar;

regionOfInterestListEditor;
% regionOfInterestListEditor;
preprocessingWorkflowEditor;

postProcessingMethodEditor;
Expand Down Expand Up @@ -158,7 +150,8 @@

%obj.createFigure();

obj.regionOfInterestList = RegionOfInterestList();
% obj.regionOfInterestList = RegionOfInterestList();
% obj.regionOfInterestPanel.setRegionOfInterestList(obj.regionOfInterestList);
obj.spectrumList = SpectrumList();

obj.imageDisplay = ImageDisplay(obj, Image(1));
Expand Down Expand Up @@ -198,6 +191,8 @@


function switchSpectrumView(obj)
f = PCAInfoFigure(obj.dataRepresentation, obj.regionOfInterestPanel.regionOfInterestList);

isVisible = strcmp(get(obj.previousCoefficientButton, 'Visible'), 'on');

obj.makeCoefficientControlsVisible(~isVisible);
Expand Down Expand Up @@ -259,6 +254,7 @@ function coefficientEditBoxCallback(obj)

imageData = obj.dataRepresentation.getProjectedImage(value);
obj.imageDisplay.setData(Image(imageData));
obj.regionOfInterestPanel.setImageForEditor(Image(imageData));

if(sum(obj.dataRepresentation.data(:) < 0) > 0)
minVal = min(0, min(imageData(:)));
Expand Down Expand Up @@ -308,7 +304,7 @@ function generateSpectralRepresentation(obj, representationIndex)
else
obj.postProcessingMethodEditor = PostProcessingMethodEditor(obj.spectralRepresentationMethods{representationIndex});%MemoryEfficientPCAEditor(obj.spectrumDisplay.peakList, obj.preprocessingWorkflow);

obj.postProcessingMethodEditor.setRegionOfInterestList(obj.regionOfInterestList);
obj.postProcessingMethodEditor.setRegionOfInterestList(obj.regionOfInterestPanel.regionOfInterestList);

addlistener(obj.postProcessingMethodEditor, 'FinishedEditingPostProcessingMethod', @(src, evnt)obj.finishedEditingPostProcessingMethod());
end
Expand All @@ -329,7 +325,7 @@ function performDataReduction(obj, dataReductionIndex)
else
obj.postProcessingMethodEditor = PostProcessingMethodEditor(obj.dataReductionMethods{dataReductionIndex});%MemoryEfficientPCAEditor(obj.spectrumDisplay.peakList, obj.preprocessingWorkflow);

obj.postProcessingMethodEditor.setRegionOfInterestList(obj.regionOfInterestList);
obj.postProcessingMethodEditor.setRegionOfInterestList(obj.regionOfInterestPanel.regionOfInterestList);

addlistener(obj.postProcessingMethodEditor, 'FinishedEditingPostProcessingMethod', @(src, evnt)obj.finishedEditingPostProcessingMethod());
end
Expand All @@ -344,7 +340,7 @@ function performClustering(obj, clusteringIndex)
else
obj.postProcessingMethodEditor = PostProcessingMethodEditor(obj.clusteringMethods{clusteringIndex});

obj.postProcessingMethodEditor.setRegionOfInterestList(obj.regionOfInterestList);
obj.postProcessingMethodEditor.setRegionOfInterestList(obj.regionOfInterestPanel.regionOfInterestList);

addlistener(obj.postProcessingMethodEditor, 'FinishedEditingPostProcessingMethod', @(src, evnt)obj.finishedEditingPostProcessingMethod());
end
Expand Down Expand Up @@ -513,104 +509,21 @@ function peakSelected(obj, peakSelectionEvent)
end
end

function editRegionOfInterestList(obj)
% Check if we have already opened the
% RegionOfInterestListEditor and if so if it is still a valid
% instance of the class. If so show it, otherwise recreate it
if(isa(obj.regionOfInterestListEditor, 'RegionOfInterestListEditor') && isvalid(obj.regionOfInterestListEditor))
figure(obj.regionOfInterestListEditor.handle);
else
obj.regionOfInterestListEditor = RegionOfInterestListEditor(obj.imageDisplay.getData(), obj.regionOfInterestList);

addlistener(obj.regionOfInterestListEditor, 'FinishedEditing', @(src, evnt)obj.finishedEditingRegionOfInterestList());
end

assignin('base', 'dvroiList', obj.regionOfInterestList);
end

function finishedEditingRegionOfInterestList(obj)
obj.regionOfInterestList = obj.regionOfInterestListEditor.regionOfInterestList;

obj.updateRegionOfInterestList();
end

function saveRegionOfInterest(this)
this.regionOfInterestList.get(1)
for i = this.selectedROIs
variableName = inputdlg(['Please specifiy a variable name for ' this.regionOfInterestList.get(i).name ':'], 'Variable name', 1, {'roi'});

while(~isempty(variableName))
if(isvarname(variableName{1}))
assignin('base', variableName{1}, this.regionOfInterestList.get(i));
break;
else
variableName = inputdlg('Invalid variable name. Please specifiy a variable name:', 'Variable name', 1, variableName);
end
end
end
end

function loadRegionOfInterest(this)
variables = evalin('base', 'who');
rois = {};

for i = 1:length(variables)
if(evalin('base', ['isa(' variables{i} ', ''RegionOfInterest'')']))
rois{end+1} = variables{i};
end
end

[selection, ok] = listdlg('PromptString', 'Select ROI(s)', ...
'ListString', rois);

if(ok)
for i = selection
newROI = evalin('base', rois{i});

this.regionOfInterestList.add(newROI);
end

this.updateRegionOfInterestList();
end
end

function infoRegionOfInterest(this)
roiInfo = RegionOfInterestInfoFigure(this.regionOfInterestList, this.imageList);
roiInfo.selectImageIndex(1);
end

function setRegionOfInterestList(this, regionOfInterestList)
this.regionOfInterestList = regionOfInterestList;

this.updateRegionOfInterestList();
end

function selectRegionOfInterest(this, src, event)
this.selectedROIs = event.Indices(:, 1)';
roiInfo = RegionOfInterestInfoFigure(this.regionOfInterestPanel.regionOfInterestList, this.imageList);
roiInfo.selectImageIndex(1);
end

function updateRegionOfInterestList(this)
rois = this.regionOfInterestList.getObjects();
data = {};

for i = 1:numel(rois)
data{i, 1} = ['<HTML><font color="' rois{i}.getColour().toHex() '">' rois{i}.getName() '</font></HTML>' ];
data{i, 2} = false;
end

set(this.regionOfInterestTable, 'Data', data);

this.updateRegionOfInterestDisplay();
end

function updateRegionOfInterestDisplay(this)
this.imageDisplay.removeAllRegionsOfInterest();

roiData = get(this.regionOfInterestTable, 'Data');
roiData = get(this.regionOfInterestPanel.regionOfInterestTable, 'Data');

for i = 1:size(roiData, 1)
if(roiData{i, 2})
this.imageDisplay.addRegionOfInterest(this.regionOfInterestList.get(i));
this.imageDisplay.addRegionOfInterest(this.regionOfInterestPanel.regionOfInterestList.get(i));
end
end

Expand Down Expand Up @@ -936,6 +849,7 @@ function displayImage(obj, imageIndex)
set(obj.imageTitleLabel, 'String', obj.imageList(imageIndex).getDescription());

obj.imageDisplay.setData(obj.imageList(imageIndex));
obj.regionOfInterestPanel.setImageForEditor(obj.imageList(imageIndex));

set(obj.imageAxis, 'ButtonDownFcn', @(src, evnt)obj.imageAxisClicked());
end
Expand Down Expand Up @@ -1098,31 +1012,10 @@ function createFigure(obj)
'Callback', @(src, evnt) obj.loadImageListCallback(), ...
'TooltipString', 'Load image list');

obj.regionOfInterestPanel = uipanel('Parent', obj.handle, 'Title', 'Region Of Interest', ...
'Position', [0.05 0.05 0.425 0.2]);
%Set up the region of interest table
columnNames = {'Region', 'Display'};
columnFormat = {'char', 'logical'};
columnEditable = [false, true];

obj.regionOfInterestTable = uitable('Parent', obj.regionOfInterestPanel, ...
'ColumnName', columnNames, 'ColumnFormat', columnFormat, 'ColumnEditable', columnEditable, ...
'RowName', [], 'CellEditCallback', @(src, evnt) obj.updateRegionOfInterestDisplay(), ...
'CellSelectionCallback', @obj.selectRegionOfInterest, ...
'Units', 'normalized', 'Position', [0.05 0.05 0.9 0.9]);
obj.editRegionOfInterestButton = uicontrol('Parent', obj.regionOfInterestPanel, 'String', 'Edit', ...
'Units', 'normalized', 'Position', [0.65 0.1 0.3 0.3], 'Callback', @(src, evnt)obj.editRegionOfInterestList(), ...
'TooltipString', 'Add/Edit regions of interest');
obj.saveRegionOfInterestButton = uicontrol('Parent', obj.regionOfInterestPanel, 'String', 'S', ...
'Units', 'normalized', 'Position', [0.1 0.1 0.1 0.3], 'Callback', @(src, evnt)obj.saveRegionOfInterest(), ...
'TooltipString', 'Save region of interest list');
obj.loadRegionOfInterestButton = uicontrol('Parent', obj.regionOfInterestPanel, 'String', 'L', ...
'Units', 'normalized', 'Position', [0.1 0.1 0.1 0.05], 'Callback', @(src, evnt)obj.loadRegionOfInterest(), ...
'TooltipString', 'Load region of interest list');
obj.infoRegionOfInterestButton = uicontrol('Parent', obj.regionOfInterestPanel, 'String', 'i', ...
'Units', 'normalized', 'Position', [0.1 0.1 0.1 0.05], 'Callback', @(src, evnt)obj.infoRegionOfInterest(), ...
'TooltipString', 'Display region of interest details');

obj.regionOfInterestPanel = RegionOfInterestPanel(obj);
addlistener(obj.regionOfInterestPanel, 'InfoButtonClicked', @(src, evnt) obj.infoRegionOfInterest());
addlistener(obj.regionOfInterestPanel, 'RegionOfInterestSelected', @(src, evnt) obj.updateRegionOfInterestDisplay());


% obj.imageAxis = axes('Parent', obj.handle, 'Position', [.25 .62 .7 .3]);

Expand Down Expand Up @@ -1296,16 +1189,8 @@ function sizeChanged(obj)
widthOfROIList = 200;
widthForImage = widthForImage - widthOfROIList - margin;

Figure.setObjectPositionInPixels(obj.regionOfInterestPanel, [newPosition(3)-widthOfROIList-margin, imageRegionY, widthOfROIList, imageRegionHeight]);

panelPosition = Figure.getPositionInPixels(obj.regionOfInterestPanel);

if(~isempty(panelPosition))
Figure.setObjectPositionInPixels(obj.regionOfInterestTable, [margin, buttonHeight + margin, panelPosition(3) - margin*2, panelPosition(4) - margin*2 - buttonHeight - 20]);
Figure.setObjectPositionInPixels(obj.editRegionOfInterestButton, [panelPosition(3)*2/3, margin, panelPosition(3)*1/3 - margin, buttonHeight]);
Figure.setObjectPositionInPixels(obj.saveRegionOfInterestButton, [margin, margin, panelPosition(3)/5 - margin*2, buttonHeight]);
Figure.setObjectPositionInPixels(obj.loadRegionOfInterestButton, [margin+panelPosition(3)*1/5, margin, panelPosition(3)/5 - margin*2, buttonHeight]);
Figure.setObjectPositionInPixels(obj.infoRegionOfInterestButton, [margin+panelPosition(3)*2/5, margin, panelPosition(3)/5 - margin*2, buttonHeight]);
if(~isempty(obj.regionOfInterestPanel))
Figure.setObjectPositionInPixels(obj.regionOfInterestPanel.handle, [newPosition(3)-widthOfROIList-margin, imageRegionY, widthOfROIList, imageRegionHeight]);
end
end

Expand Down

0 comments on commit ce401cd

Please sign in to comment.