|
| 1 | +% nix.Source class is used to describe the provenance of other entities |
| 2 | +% of the NIX data model. |
| 3 | +% |
| 4 | +% The Source entity is used to note the provenance of the data and offers the |
| 5 | +% option to bind simple, low level additional metadata. |
| 6 | +% One special feature of the Source is the possibility to reference other Sources as |
| 7 | +% children thus building up a tree of Sources. |
| 8 | +% This can, for example, be used to specify that a Source 'electrode array' contains |
| 9 | +% multiple electrodes as its child Sources. |
| 10 | +% |
| 11 | +% nix.Source dynamic properties: |
| 12 | +% id (char): read-only, automatically created id of the entity. |
| 13 | +% name (char): read-only, name of the entity. |
| 14 | +% type (char): read-write, type can be used to give semantic meaning to an |
| 15 | +% entity and expose it to search methods in a broader context. |
| 16 | +% definition (char): read-write, additional description of the entity. |
| 17 | +% |
| 18 | +% nix.Source dynamic child entity properties: |
| 19 | +% sources access to all nix.Source child entities. |
| 20 | +% |
| 21 | +% See also nix.Block, nix.DataArray, nix.Tag, nix.MultiTag, nix.Section. |
| 22 | +% |
| 23 | +% |
1 | 24 | % Copyright (c) 2016, German Neuroinformatics Node (G-Node)
|
2 | 25 | %
|
3 | 26 | % All rights reserved.
|
|
7 | 30 | % LICENSE file in the root of the Project.
|
8 | 31 |
|
9 | 32 | classdef Source < nix.NamedEntity & nix.MetadataMixIn
|
10 |
| - % Source nix Source object |
11 | 33 |
|
12 | 34 | properties (Hidden)
|
13 |
| - % namespace reference for nix-mx functions |
14 |
| - alias = 'Source' |
| 35 | + alias = 'Source' % nix-mx namespace to access Source specific nix backend functions. |
15 | 36 | end
|
16 | 37 |
|
17 | 38 | methods
|
18 | 39 | function obj = Source(h)
|
19 | 40 |
|
20 | 41 |
|
21 | 42 |
|
22 |
| - % assign relations |
| 43 | + % assign child entities |
23 | 44 | nix.Dynamic.addGetChildEntities(obj, 'sources', @nix.Source);
|
24 | 45 | end
|
25 | 46 |
|
|
28 | 49 | % ------------------
|
29 | 50 |
|
30 | 51 | function r = sourceCount(obj)
|
| 52 | + % Get the number of direct child nix.Sources. |
| 53 | + % |
| 54 | + % Returns: (uint) The number of child Sources. |
| 55 | + % |
| 56 | + % Example: sc = currSource.sourceCount(); |
| 57 | + |
31 | 58 | r = nix.Utils.fetchEntityCount(obj, 'sourceCount');
|
32 | 59 | end
|
33 | 60 |
|
34 | 61 | function r = createSource(obj, name, type)
|
| 62 | + % Create a new nix.Source entity associated with the invoking Source. |
| 63 | + % |
| 64 | + % name (char): The name of the Source, has to be unique within the file. |
| 65 | + % type (char): The type of the Source. |
| 66 | + % |
| 67 | + % Returns: (nix.Source) The newly created Source. |
| 68 | + % |
| 69 | + % Example: newSource = currSource.createSource('cell5', 'pyramidal'); |
| 70 | + |
35 | 71 | fname = strcat(obj.alias, '::createSource');
|
36 | 72 | h = nix_mx(fname, obj.nixhandle, name, type);
|
37 | 73 | r = nix.Utils.createEntity(h, @nix.Source);
|
38 | 74 | end
|
39 | 75 |
|
40 | 76 | function r = hasSource(obj, idName)
|
| 77 | + % Check if a nix.Source exists as a direct child of the invoking Source. |
| 78 | + % |
| 79 | + % idName (char): Name or ID of the Source. |
| 80 | + % |
| 81 | + % Returns: (logical) True if the Source exists, false otherwise. |
| 82 | + % |
| 83 | + % Example: check = currSource.hasSource('some-source-id'); |
| 84 | + % check = currFile.blocks{1}.sources{1}.hasSource('cell5'); |
| 85 | + |
41 | 86 | r = nix.Utils.fetchHasEntity(obj, 'hasSource', idName);
|
42 | 87 | end
|
43 | 88 |
|
44 |
| - function r = deleteSource(obj, del) |
45 |
| - r = nix.Utils.deleteEntity(obj, 'deleteSource', del, 'nix.Source'); |
| 89 | + function r = deleteSource(obj, idNameEntity) |
| 90 | + % Deletes a nix.Source and its children from the invoking Source. |
| 91 | + % |
| 92 | + % When a Source is deleted, all its sub-Sources |
| 93 | + % will be deleted recursively from the Source as well. |
| 94 | + % |
| 95 | + % idNameEntity (char/nix.Source): Name or id of the entity to |
| 96 | + % be deleted or the entity itself. |
| 97 | + % |
| 98 | + % Returns: (logical) True if the Source has been removed, false otherwise. |
| 99 | + % |
| 100 | + % Example: check = currSource.deleteSource('23bb8a99-1812-4bc6-a52c'); |
| 101 | + % check = currSource.deleteSource('cell5'); |
| 102 | + % check = currFile.blocks{1}.sources{1}.deleteSource(newSource); |
| 103 | + |
| 104 | + r = nix.Utils.deleteEntity(obj, 'deleteSource', idNameEntity, 'nix.Source'); |
46 | 105 | end
|
47 | 106 |
|
48 | 107 | function r = openSource(obj, idName)
|
| 108 | + % Retrieves an existing direct Source from the invoking Source. |
| 109 | + % |
| 110 | + % idName (char): Name or ID of the Source. |
| 111 | + % |
| 112 | + % Returns: (nix.Source) The nix.Source or an empty cell, |
| 113 | + % if the Source was not found. |
| 114 | + % |
| 115 | + % Example: getSource = currSource.openSource('23bb8a99-1812-4bc6-a52c'); |
| 116 | + % getSource = currFile.blocks{1}.sources{1}.openSource('cell5'); |
| 117 | + |
49 | 118 | r = nix.Utils.openEntity(obj, 'openSource', idName, @nix.Source);
|
50 | 119 | end
|
51 | 120 |
|
52 | 121 | function r = openSourceIdx(obj, index)
|
| 122 | + % Retrieves an existing nix.Source from the invoking Source, |
| 123 | + % accessed by index. |
| 124 | + % |
| 125 | + % index (double): The index of the Source to read. |
| 126 | + % |
| 127 | + % Returns: (nix.Source) The Source at the given index. |
| 128 | + % |
| 129 | + % Example: getSource = currSource.openSourceIdx(1); |
| 130 | + |
53 | 131 | idx = nix.Utils.handleIndex(index);
|
54 | 132 | r = nix.Utils.openEntity(obj, 'openSourceIdx', idx, @nix.Source);
|
55 | 133 | end
|
56 | 134 |
|
57 | 135 | function r = parentSource(obj)
|
| 136 | + % Returns the parent Source of the invoking Source. Method performs a search, |
| 137 | + % may thus not be the most efficient way. |
| 138 | + % |
| 139 | + % Returns: (nix.Source) The parent Source if there is any, |
| 140 | + % an empty cell array otherwise. |
| 141 | + % |
| 142 | + % Example: getSource = currSource.parentSource(); |
| 143 | + |
58 | 144 | r = nix.Utils.fetchObj(obj, 'parentSource', @nix.Source);
|
59 | 145 | end
|
60 | 146 |
|
61 | 147 | function r = referringDataArrays(obj)
|
| 148 | + % Returns all nix.DataArrays which referrence the invoking Source. |
| 149 | + % |
| 150 | + % Returns: ([nix.DataArray]) A cell array of all DataArray entities |
| 151 | + % referring to the invoking Source. |
| 152 | + % |
| 153 | + % Example: getSource = currSource.referringDataArrays(); |
| 154 | + % |
| 155 | + % See also nix.DataArray. |
| 156 | + |
62 | 157 | r = nix.Utils.fetchObjList(obj, 'referringDataArrays', @nix.DataArray);
|
63 | 158 | end
|
64 | 159 |
|
65 | 160 | function r = referringTags(obj)
|
| 161 | + % Returns all nix.Tags which referrence the invoking Source. |
| 162 | + % |
| 163 | + % Returns: ([nix.Tag]) A cell array of all Tag entities |
| 164 | + % referring to the invoking Source. |
| 165 | + % |
| 166 | + % Example: getSource = currSource.referringTags(); |
| 167 | + % |
| 168 | + % See also nix.Tag. |
| 169 | + |
66 | 170 | r = nix.Utils.fetchObjList(obj, 'referringTags', @nix.Tag);
|
67 | 171 | end
|
68 | 172 |
|
69 | 173 | function r = referringMultiTags(obj)
|
| 174 | + % Returns all nix.MultiTags which referrence the invoking Source. |
| 175 | + % |
| 176 | + % Returns: ([nix.MultiTag]) A cell array of all MultiTag entities |
| 177 | + % referring to the invoking Source. |
| 178 | + % |
| 179 | + % Example: getSource = currSource.referringMultiTags(); |
| 180 | + % |
| 181 | + % See also nix.MultiTag. |
| 182 | + |
70 | 183 | r = nix.Utils.fetchObjList(obj, 'referringMultiTags', @nix.MultiTag);
|
71 | 184 | end
|
72 | 185 |
|
73 | 186 | function r = filterSources(obj, filter, val)
|
| 187 | + % Get a filtered cell array of all direct child Sources |
| 188 | + % of the invoking Source. |
| 189 | + % |
| 190 | + % filter (nix.Filter): the nix.Filter to be applied. |
| 191 | + % val (char): Value that is applied with the selected |
| 192 | + % filter. |
| 193 | + % |
| 194 | + % Returns: ([nix.Source]) A cell array of Sources filtered according |
| 195 | + % to the applied nix.Filter. |
| 196 | + % |
| 197 | + % Example: getSources = currSource.filterSources(nix.Filter.type, 'pyramidal'); |
| 198 | + % |
| 199 | + % See also nix.Filter. |
| 200 | + |
74 | 201 | r = nix.Utils.filter(obj, 'sourcesFiltered', filter, val, @nix.Source);
|
75 | 202 | end
|
76 | 203 |
|
77 |
| - % maxdepth is an index where idx = 0 corresponds to the calling source |
78 | 204 | function r = findSources(obj, maxDepth)
|
| 205 | + % Get all Sources and their child Sources in the invoking Source recursively. |
| 206 | + % |
| 207 | + % This method traverses the trees of all Sources in the Source and adds all |
| 208 | + % Sources to the resulting cell array, until the maximum depth of the nested |
| 209 | + % Sources has been reached. The traversal is accomplished via breadth first |
| 210 | + % and adds the Sources accordingly. |
| 211 | + % |
| 212 | + % maxDepth (double): The maximum depth of traversal to retrieve nested |
| 213 | + % Sources. Should be handled like an index, |
| 214 | + % where idx = 0 corresponds to the calling source. |
| 215 | + % |
| 216 | + % Example: allSources = currSource.findSources(2); |
| 217 | + % % will add all Sources until including the 2nd layer of Sources. |
| 218 | + |
79 | 219 | r = obj.filterFindSources(maxDepth, nix.Filter.acceptall, '');
|
80 | 220 | end
|
81 | 221 |
|
82 |
| - % maxdepth is an index where idx = 0 corresponds to the calling source |
83 | 222 | function r = filterFindSources(obj, maxDepth, filter, val)
|
| 223 | + % Get all Sources and their child Sources in the invoking Source recursively. |
| 224 | + % |
| 225 | + % This method traverses the trees of all Sources of the invoking Source. |
| 226 | + % The traversal is accomplished via breadth first and can be limited in depth. |
| 227 | + % On each node or Source a nix.Filter is applied. If the filter returns true, |
| 228 | + % the respective Source will be added to the result list. |
| 229 | + % |
| 230 | + % maxDepth (double): The maximum depth of traversal to retrieve nested |
| 231 | + % Sources. Should be handled like an index, |
| 232 | + % where idx = 0 corresponds to the calling source. |
| 233 | + % filter (nix.Filter): The nix.Filter to be applied. Supports |
| 234 | + % the filters 'acceptall', 'id', 'ids', |
| 235 | + % 'name' and 'type'. |
| 236 | + % val (char): Value that is applied with the selected |
| 237 | + % filter. |
| 238 | + % |
| 239 | + % Example: allSources = currSource.filterFindSources(... |
| 240 | + % 2, nix.Filter.type, 'ephys'); |
| 241 | + % |
| 242 | + % See also nix.Filter. |
| 243 | + |
84 | 244 | r = nix.Utils.find(obj, 'findSources', maxDepth, filter, val, @nix.Source);
|
85 | 245 | end
|
86 | 246 | end
|
|
0 commit comments