Skip to content

Commit

Permalink
Merge branch 'master' into masterGitHub
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanRace committed Nov 18, 2016
2 parents 793569b + ad0a254 commit 02411dd
Show file tree
Hide file tree
Showing 138 changed files with 12,044 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
src/processing/postprocessing/tSNE/
*.mexw32
*.mexa64
*.mat
*.mexw64
*.asv
us.stackdump
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "src/gui/MOOGL"]
path = src/gui/MOOGL
url = https://github.com/AlanRace/MOOGL
6 changes: 6 additions & 0 deletions deploy.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
path = [fileparts(mfilename('fullpath')) filesep 'src'];

% Ensure all folders are on the path
addpath(genpath(path));

mcc -v -m SpectralAnalysis.m -a lib/ -a src/ -a *.m
43 changes: 43 additions & 0 deletions examples/SkeletonClasses/SkeletonParser.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
classdef SkeletonParser < Parser
methods (Static)
function filterSpec = getFilterSpec()
% TODO: Fill in this method by returning
end
end

methods
function this = SkeletonParser(filename)
this.filename = filename;

% TODO: Any other set up details here
end


function parse(this)
% Display a message to the user that parsing has started
notify(this, 'ParsingStarted');

% TODO: Perform any parsing of the data here. Making sure that width and height are filled in
this.width = ??;
this.height = ??;

% Close the message and notify the user that parsing is complete
notify(this, 'ParsingComplete');
end

function [spectralChannels, intensities] = getSpectrum(this, x, y)
% TODO: Read in the data for the spectrum at location (x, y). If one doesn't exist then set spectralChannels and intensities to be empty

spectralChannels = ??;
intensities = ??;
end

function image = getOverviewImage(this)
imageData = zeros(this.height, this.width);

% TODO: Create an image that describes the dataset. This is displayed in the `Select Data Representation' interface when loading a dataset

image = Image(imageData);
end
end
end
29 changes: 29 additions & 0 deletions examples/SkeletonClasses/SkeletonPreprocessing.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
classdef SkeletonPreprocessing < ?? % TODO: Change SpectralSmoothing to appropriate parent class
properties (Constant)
Name = 'Skeleton Preprocessing'; % TODO: Provide a sensible name
Description = 'This is just a template class';

% TODO: Fill in parameter definitions
ParameterDefinitions = [ParameterDescription('Skeleton Parameter 1', ParameterType.Integer, 5), ...
ParameterDescription('Skeleton Parameter 2', ParameterType.Double, 1.05)];
end

properties
skeletonParameter1;
skeletonParameter2;
end

methods
function this = MovingAverageSmoothing(skeletonParameter1, skeletonParameter2)
% Store the parameters for use in the smooth function
this.skeletonParameter1 = skeletonParameter1;
this.skeletonParameter2 = skeletonParameter2;
end

function [spectralChannels, intensities] = smooth(obj, spectralChannels, intensities)
% TODO: Smooth the spectrum using any parameters required

intensities = ??;
end
end
end
2 changes: 2 additions & 0 deletions files/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SpectralAnalysis 0.75
Alan Race
Binary file added lib/JSpectralAnalysis/JSIMS.jar
Binary file not shown.
Binary file added lib/JSpectralAnalysis/JSpectralAnalysis.jar
Binary file not shown.
Binary file added lib/jimzMLParser/jimzMLParser-1.0-SNAPSHOT.jar
Binary file not shown.
Binary file added lib/licence/SpectralAnalysisLicence.jar
Binary file not shown.
Binary file added lib/licence/public.key
Binary file not shown.
7 changes: 7 additions & 0 deletions runSpectralAnalysis.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
% Get location of current m-file
path = [fileparts(mfilename('fullpath')) filesep 'src'];

% Ensure all folders are on the path
addpath(genpath(path));

SpectralAnalysis
33 changes: 33 additions & 0 deletions src/SpectralAnalysis.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
%% SpectralAnalysis
% Spectral Imaging analysis software

% Get location of current m-file
if(isdeployed())
disp('Initialising MATLAB, please wait...');
path = ctfroot();
else
path = [fileparts(mfilename('fullpath'))];
end

% Ensure all folders are on the path
addpath(genpath(path));

% Ensure libraries are on the path
addJARsToClassPath();

% Launch spectral analysis interface
try
SpectralAnalysisInterface();
catch err
if(strcmp(err.identifier, 'MATLAB:class:undefinedMethod') && ~isempty(strfind(err.message, 'Figure')))
disp(['ERROR: Missing MOOGL. Download from https://github.com/AlanRace/MOOGL and place in src/gui folder']);
else
throw(err);
end
end


% Check that a valid licence exists, otherwise show the
if(~isValidLicence())
MissingLicenceFigure();
end
188 changes: 188 additions & 0 deletions src/core/BasepeakSpectrum.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
classdef BasepeakSpectrum < SpectralRepresentation
properties (Constant)
Name = 'Basepeak Spectrum';
Description = '';

ParameterDefinitions = [];
end

properties (SetAccess = protected)
numSpectra = 0;
end

methods
function spectrumList = process(this, dataRepresentation)
spectrumList = SpectrumList();

pixels = this.getPixelListToProcess(dataRepresentation);
rois = this.regionOfInterestList.getObjects();

% Set up the memory required
data = {};
pixelLists = {};
descriptions = {};

% if(isa(dataRepresentation, 'DataInMemory') && isempty(this.preprocessingWorkflow))
%
% else
% Check if the multithreaded methods implemented in Java
% can be used
canUseFastMethods = 0;
tic;

% Currently only the ImzMLParser can be used with the fast
% methods as it is the only one implemented in Java so far
if(isa(dataRepresentation.parser, 'ImzMLParser'))
roiList = com.alanmrace.JSpectralAnalysis.RegionOfInterest.createROIList();

if(this.processEntireDataset)
roi = com.alanmrace.JSpectralAnalysis.RegionOfInterest('Entire Dataset', dataRepresentation.regionOfInterest.width, dataRepresentation.regionOfInterest.height);
roi.addPixels(dataRepresentation.regionOfInterest.pixelSelection');
roiList.add(roi);
end

for i = 1:numel(rois)
roi = com.alanmrace.JSpectralAnalysis.RegionOfInterest(rois{i}.getName(), dataRepresentation.regionOfInterest.width, dataRepresentation.regionOfInterest.height);
roi.addPixels(rois{i}.pixelSelection');
roiList.add(roi);
end

if(this.preprocessEverySpectrum)
workflow = generateFastPreprocessingWorkflow(this.preprocessingWorkflow);
else
workflow = com.alanmrace.JSpectralAnalysis.PreprocessingWorkflow();
end

if(isempty(this.preprocessingWorkflow) || ~this.preprocessEverySpectrum || ~isempty(workflow))
canUseFastMethods = 1;
end

javaParser = com.alanmrace.JSpectralAnalysis.io.ImzMLParser(dataRepresentation.parser.imzML);
javaDataRepresentation = com.alanmrace.JSpectralAnalysis.datarepresentation.DataOnDisk(javaParser);
end

if(canUseFastMethods)
ped = ProgressEventData(0, ['Using fast methods. Generating Total Spectrum']);
notify(this, 'ProcessingProgress', ped);

try
spectrumGeneration = com.alanmrace.JSpectralAnalysis.spectralrepresentation.MultithreadedSpectralRepresentationGeneration(javaDataRepresentation, workflow, roiList);
spectrumGeneration.generateBasepeakSpectrum();

while(~spectrumGeneration.isDone())
ped = ProgressEventData(spectrumGeneration.getProgress(), ['Using fast methods. Generating Basepeak Spectrum']);
notify(this, 'ProcessingProgress', ped);

pause(0.05);
end

% if(spectrumGeneration.hasError())
% 'error'
% end
assignin('base', 'spectrumGeneration', spectrumGeneration);
sList = spectrumGeneration.getSpectrumList();
roiList
for i = 0:sList.size()-1
s = SpectralData(sList.get(i).getSpectralChannels(), sList.get(i).getIntensities());

name = char(roiList.get(i).getName());

s.setDescription([eval([class(this) '.Name']) ' ' name]);

spectrumList.add(s);
end
catch err

errBox = errordlg(err.message, err.identifier);

rethrow(err);
end

ped = ProgressEventData(1, ['Generated Basepeak Spectrum']);
notify(this, 'ProcessingProgress', ped);
else
for i = 1:size(pixels, 1)
spectrum = this.getProcessedSpectrum(dataRepresentation, pixels(i, 1), pixels(i, 2));

if(isempty(spectrum.intensities))
continue;
end

processDescription = ['Generating ' eval([class(this) '.Name'])];

% Create the data based on the first spectrum acquired
if(isempty(data))
channelSize = length(spectrum.spectralChannels);
peakList = spectrum.spectralChannels;

if(this.processEntireDataset)
data{end+1} = zeros(1, channelSize);
pixelLists{end+1} = pixels;
descriptions{end+1} = '(Entire Dataset)';
end

for roiIndex = 1:numel(rois)
pixelLists{end+1} = rois{roiIndex}.getPixelList();
data{end+1} = zeros(1, channelSize);
descriptions{end+1} = ['(' rois{roiIndex}.getName() ')'];
end
end

for pixelListIndex = 1:numel(pixelLists)
[pixel, row, col] = intersect(pixelLists{pixelListIndex}, pixels(i, :), 'rows');

if(~isempty(row))
data{pixelListIndex}(1, :) = max(data{pixelListIndex}(1, :), spectrum.intensities);
end
end

progressEvent = ProgressEventData(i / length(pixels), 'Calculating spectral representation');
notify(this, 'ProcessingProgress', progressEvent);
end

for i = 1:numel(data)
s = SpectralData(peakList', data{i});

s.setDescription([eval([class(this) '.Name']) ' ' descriptions{i}]);

spectrumList.add(s);
end
end
% end

toc;

% % This could be optimised for each data representation
%
% if(~obj.preprocessEverySpectrum && isa(dataRepresentation, 'DataInMemory'))
% maxIntensities = sum(dataRepresentation.data, 1);
% spectralChannels = dataRepresentation.spectralChannels;
%
% obj.numSpectra = sum(sum(dataRepresentation.data, 2) ~= 0);
% else
% for y = 1:dataRepresentation.height
% for x = 1:dataRepresentation.width
% spectrum = dataRepresentation.getSpectrum(x, y);
%
% spectralChannels = spectrum.spectralChannels;
%
% if(isempty(spectrum.intensities))
% continue;
% end
%
% if(~isempty(obj.preprocessingWorkflow) && obj.preprocessEverySpectrum)
% spectrum = obj.preprocessingWorkflow.performWorkflow(spectrum);
% end
%
% if(~isempty(spectrum.intensities))
% obj.numSpectra = obj.numSpectra + 1;
% maxIntensities = maxIntensities + spectrum.intensities;
% end
% end
% end
% end
%
% spectrum = SpectralData(spectralChannels, maxIntensities);
end
end
end
Loading

0 comments on commit 02411dd

Please sign in to comment.