IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
data_rename_classlabels.m
Go to the documentation of this file.
1 %>@ingroup datasettools classlabelsgroup
2 %> @file
3 %> @brief searches and replaces class labels
4 %>
5 %> This function performs the search within class levels, not the whole labels. For example, in a label 'A|B|C', matched will be tried against 'A', 'B', and 'C' separately
6 %>
7 
8 %> @param data Dataset
9 %> @param map See syntax below: @code {old_label1, new_label1; old_label2, new_label2; ...} @endcode
10 %> @param levelstosearch Levels to search
11 %> @return Dataset with classlabels changed
12 function data = data_rename_classlabels(data, map, levelstosearch)
13 
14 comoassim = classlabels2cell(data.classlabels);
15 
16 if ~exist('levelstosearch', 'var') || isempty(levelstosearch)
17  levelstosearch = 1:(size(comoassim, 2)-4); % all levels
18 end;
19 
20 no_map = size(map, 1);
21 
22 new = {};
23 
24 for i = 1:data.nc
25  flag_first = 1;
26  s = '';
27  for j = 5:size(comoassim, 2)
28  if any(levelstosearch == j-4)
29  for k = 1:no_map
30  if strcmp(comoassim{i, j}, map{k, 1})
31  comoassim{i, j} = map{k, 2};
32  end;
33  end;
34  end;
35 
36  if ~flag_first
37  s = [s '|'];
38  end;
39  s = [s comoassim{i, j}];
40  flag_first = 0;
41  end;
42 
43  new{end+1} = s;
44 end;
45 
46 data.classlabels = new;
47 
48 
function data_rename_classlabels(in data, in map, in levelstosearch)
function classlabels2cell(in classlabels, in new_hierarchy)