%BIODATA OBJECT
%
%Biodata class constructor method. This function creates and initialises a
%Biodata object.
%
%Syntax1: bd = Biodata(X, Classes, ReducedData)
%
%Parameters
% X: de datamatrix for the Biodata object
% Classes:
% - is a vector of class descriptions: if this vector doensn't contain
% numbers, a second class description vector 'nr' will be made wich
% contains a numerical class description vector
% - is a structure or structurearray with fields 'name' and
% 'classvalue' containing the names for the description vectors and
% the description vectors itself
% ReducedData: boolean value to indicate whether the data is already
% reduced by means of e.g. PCA
%
%
%Syntax2: bd = Biodata(X)
% X is a structure
% Generate a Biodata object based on the structure X, X must have the
% same fields as a Biodata object
% X is a string
% if 'default': return the default Biodata object
% X is numeric: returns a Biodata object with the data contained in the
% matrix X, but with no sample descriptions
%
%
%Syntax 3: bd = Biodata
% Returns an empty object with the default parameters.
%
%Example:
% newbd = Biodata (rand(20,50))
% newbd = AddEmptyClassdes (newbd, 'test')
%This software package is dual licensed. You can use it according to the terms
%of either the GPLv3 or the BSD license.
%
%The Biodata toolbox for MATLAB: a spectral database system for storing and
%processing spectra
%C 2004-2008, Kris De Gussem, Raman Spectroscopy Research Group, Department
%of analytical chemistry, Ghent University
%C 2009 Kris De Gussem
%
%This file is part of Biodata.
%
%Biodata is free software: you can redistribute it and/or modify
%it under the terms of the GNU General Public License as published by
%the Free Software Foundation, either version 3 of the License, or
%(at your option) any later version.
%
%Biodata is distributed in the hope that it will be useful,
%but WITHOUT ANY WARRANTY; without even the implied warranty of
%MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
%GNU General Public License for more details.
%
%You should have received a copy of the GNU General Public License
%along with Biodata. If not, see <http://www.gnu.org/licenses/>.
%Copyright (c) 2004-2009, Kris De Gussem
%All rights reserved.
%
%Redistribution and use in source and binary forms, with or without
%modification, are permitted provided that the following conditions are
%met:
%
% * Redistributions of source code must retain the above copyright
% notice, this list of conditions and the following disclaimer.
% * Redistributions in binary form must reproduce the above copyright
% notice, this list of conditions and the following disclaimer in
% the documentation and/or other materials provided with the distribution
% * Neither the name of Raman Spectroscopy Research Group, Department of
% analytical chemistry, Ghent University nor the names
% of its contributors may be used to endorse or promote products derived
% from this software without specific prior written permission.
%
%THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
%AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
%IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
%ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
%LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
%CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
%SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
%INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
%CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
%ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
%POSSIBILITY OF SUCH DAMAGE.
function bd = Biodata(X, Classes, ReducedData)
%make default Biodata structure
defstr = struct ('analysis', {[]}, 'classes', {[]}, 'ConfigRun', false, 'creationdate', {''}, 'data', {[]}, 'description', {''},...
'history', {[]}, 'modificationdate', {''}, 'operator', {''}, 'options', {[]}, 'PlotOptions', {[]}, 'preprocessdata', {[]},...
'reduceddata', {0}, 'userdata', {[]}, 'xaxis', {[]}, 'xaxisall', {[]}, 'xlabel', {[]},...
'ylabel', {[]}, 'updating', {true});
defstr.classes = [];
defstr.PlotOptions = [];
defstr = Config (defstr);
defstr.creationdate = date;
defstr.modificationdate = date;
defstr.history{1} = sprintf ('Created on: %s', date);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
bd = defstr;
switch nargin
case 0
bd = class(defstr,'Biodata');
case 1
if isa(X,'Biodata')
X = struct(X);
end
if isstruct (X)
%bd = X;
%elseif isstruct (X)
%assume Biodata structure: assign data
bd = class(bd,'Biodata');
bd = Config(bd); %initialize variables of newer Biodata versions
if isfield (X, 'analysis')
bd.analysis = X.analysis;
end
if isfield (X, 'classes')
bd.classes = X.classes;
end
if isfield (X, 'creationdate')
bd.creationdate = X.creationdate;
end
if isfield (X, 'ConfigRun')
bd.ConfigRun = X.ConfigRun;
end
if isfield (X, 'data')
bd.data = X.data;
end
if isfield (X, 'description')
bd.description = X.description;
end
if isfield (X, 'history')
bd.history = X.history;
end
if isfield (X, 'modificationdate')
bd.modificationdate = X.modificationdate;
end
if isfield (X, 'operator')
bd.operator = X.operator;
end
if isfield (X, 'options')
bd.options = orderfields(CombineStruct (bd.options, X.options));
end
if isfield (X, 'PlotOptions')
bd.PlotOptions = CombineStruct (bd.PlotOptions, X.PlotOptions);
end
if isfield (X, 'reduceddata')
bd.reduceddata = X.reduceddata;
end
if isfield (X, 'userdata')
bd.userdata = X.userdata;
end
if isfield (X, 'xaxis')
bd.xaxis = X.xaxis;
end
if isfield (X, 'xaxisall')
bd.xaxisall = X.xaxisall;
end
if isfield (X, 'xlabel')
bd.xlabel = X.xlabel;
end
if isfield (X, 'ylabel')
bd.ylabel = X.ylabel;
end
if isfield (X, 'updating')
bd.updating = X.updating;
end
elseif ischar(X)%strcmp (class(X), 'char')
%check if it's the string 'default', and if so return default
%structure
if strcmp (X, 'default')
bd = class (bd, 'Biodata');
end
elseif isnumeric (X)
bd.data = X;
bd = class(bd,'Biodata');
bd = AddNrClass(bd);
else
error ('Biodata:msg', 'If one parameter is given, it should be a Biodata object.');
end
case 3
%assign data
switch class (Classes)
case 'double'
%numeric array to define classes
Cl = MakeVector (Classes, 'Classes is not a vector');
Classes2.name = 'nr';
Classes2.classvalue = Cl;
case 'struct'
if ~isfield (Classes, 'name')
error ('Biodata:msg', 'Inputparameter Classes is an unsupported structure array.');
end
if ~isfield (Classes, 'classvalue')
error ('Biodata:msg', 'Inputparameter Classes is an unsupported structure array.');
end
case 'cell'
%stringlist describing the samples
Cl = MakeVector (Classes, 'Cell Array Classes is not a vector');
Classes2.name = 'nr';
Classes2.classvalue = Cl;
otherwise
error ('Biodata:msg', 'Inputparameter Classes is of an unsupported type');
end
clear Classes
bd.classes = Classes2;
bd.data = X;
bd.description = '';
if islogical (ReducedData)
bd.reduceddata = ReducedData;
else
try
bd.reduceddata = logical (ReducedData);
catch
warning ('Biodata:msg', 'Conversion of the input parameter ReducedData to boolean is not succesfull.\nSuggesting 0...\n');
end
bd.reduceddata = 0;
end
bd.operator='';
bd = class(bd,'Biodata');
otherwise
error ('Biodata:msg', 'Wrong number of assignent parameters to Biodata object.');
end
About (bd);
function Result = CombineStruct (struct1, struct2)
Result = struct1;
finames = fieldnames (struct2);
for i=1:length(finames)
field = finames{i};
Result.(field) = struct2.(field);
end