IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
classsplitter.m
Go to the documentation of this file.
1 %>@file
2 %>@ingroup misc classlabelsgroup
3 
4 %> @brief Used by parse_classmaps.m
5 %>
6 %> Facilitates generation of lists of sub-datasets -- specified by the classes that go into each -- using expression
7 %> strings.
8 %>
9 %> This class implements operations: plus, not, and unary minus
10 %>
11 %> @sa parse_classmaps.m
12 classdef classsplitter
13  properties(Dependent)
14  classlabels;
15  %> Hierarchical level(s) that will be used to isolate only certain classes within the dataset to work on. When you call @ref
16  %> set_baselabel(), you will define which class labels mounted using the levels in @c hie_base only will be considered for the
17  %> arithmetical operations
18  hie_base;
19  %> Split level(s).
20  hie_split;
21  end;
22 
23  properties(Access=protected)
24  classlabels_;
25  hie_split_;
26  hie_base_;
27  %> Obtained using @c classlabels2cell() once @c classlabels and @c hie are set
28  cellmap_data;
29  %> Obtained using @c classlabels2cell() once @c classlabels and @c hie are set
30  cellmap_split;
31  %> Assigned by setting @c datalabel
32  activeidxs_;
33  end;
34 
35  properties(SetAccess=protected)
36  map;
37  end;
38 
39  methods
40  function o = set.classlabels(o, x)
41  o.classlabels_ = x;
42  o = o.calculate_cellmaps();
43  end;
44 
45  function z = get.classlabels(o)
46  z = o.classlabels_;
47  end;
48 
49  function o = set.hie_split(o, x)
50  o.hie_split_ = x;
51  o = o.calculate_cellmaps();
52  end;
53 
54  function z = get.hie_split(o)
55  z = o.hie_split_;
56  end;
57 
58  function o = set.hie_base(o, x)
59  o.hie_base_ = x;
60  o = o.calculate_cellmaps();
61  end;
62 
63  function z = get.hie_base(o)
64  z = o.hie_base_;
65  end;
66 
67  function o = calculate_cellmaps(o)
68  if ~isempty(o.classlabels)
69  if ~isempty(o.hie_split)
70  o.cellmap_split = classlabels2cell(o.classlabels_, o.hie_split_);
71  end;
72  if ~isempty(o.hie_base)
73  o.cellmap_data = classlabels2cell(o.classlabels_, o.hie_base_);
74  end;
75  end;
76  end;
77 
78  function o = set_baselabel(o, labels)
79  if ischar(labels)
80  labels = {labels};
81  end;
82 
83  boolidxs = zeros(1, length(o.classlabels_));
84  for i = 1:length(labels)
85  boolidxs = boolidxs | strcmp(labels{i}, o.cellmap_data(:, 3))';
86  end;
87  o.activeidxs_ = find(boolidxs);
88  o.map = {o.activeidxs_}; % Map is set initially to active indexes
89  end;
90 
91  function z = get.map(o)
92  z = o.map;
93  end;
94 
95 
96  function o = uminus(o)
97  splitclasses = cell2mat(o.cellmap_split(:, 4));
98  n = numel(unique(splitclasses));
99  o.map = cell(1, n);
100  for i = 1:n
101  o.map{i} = setxor(intersect(find(splitclasses == i-1), o.activeidxs_), o.activeidxs_);
102  end;
103  end;
104 
105  function o = plus(o, o2)
106  o.activeidxs_ = union(o.activeidxs_, o2.activeidxs_);
107  temp = o.map;
108  o.map = cell(1, numel(o.map)*numel(o2.map));
109  k = 0;
110  for i = 1:numel(temp)
111  for j = 1:numel(o2.map)
112  k = k+1;
113  o.map{k} = [temp{i}, o2.map{j}];
114  end;
115  end;
116  end;
117 
118  function o = not(o)
119  for i = 1:numel(o.map)
120  o.map{i} = setxor(o.map{i}, o.activeidxs_);
121  end;
122  end;
123  end;
124 end
Used by parse_classmaps.m.
Definition: classsplitter.m:12
function parse_classmaps(in ss, in classlabels, in hie_base, in hie_split)
function classlabels2cell(in classlabels, in new_hierarchy)