forked from open-ephys/analysis-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_session_info.m
136 lines (79 loc) · 4.15 KB
/
get_session_info.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
function info = get_session_info(directory)
% STEP 1: GET FULL PATH FOR DIRECTORY
directory = get_full_path(directory);
%%
% STEP 2: PARSE THE 'SETTINGS.XML' FILE
directory_contents = dir(directory);
DOMnode = xmlread([directory filesep 'settings.xml']);
xRoot =DOMnode.getDocumentElement;
processors = cell(0);
electrodes = cell(0);
% LOOP THROUGH TOP-LEVEL NODES
for i = 1:xRoot.getChildNodes.getLength-1
if strcmp(xRoot.item(i).getNodeName, 'SIGNALCHAIN')
xSignalChain = xRoot.item(i);
processorIndex = 0;
% LOOP THROUGH PROCESSOR NODES
for j = 1:xSignalChain.getChildNodes.getLength-1
if strcmp(xSignalChain.item(j).getNodeName, 'PROCESSOR')
processorIndex = processorIndex + 1;
xProcessor = xSignalChain.item(j);
nodeId = str2num(char(xProcessor.getAttributes.item(0).getValue));
processorName = char(xProcessor.getAttributes.item(2).getValue);
processors{processorIndex,1} = nodeId;
processors{processorIndex,2} = processorName;
processors{processorIndex,3} = []; % empty cell for channels
if strcmp(processorName, 'Filters/Spike Detector')
electrodeIndex = 0;
% LOOP THROUGH ELECTRODE NODES IN SPIKE DETECTOR
for k = 1:xProcessor.getChildNodes.getLength-1
if strcmp(xProcessor.item(k).getNodeName, 'ELECTRODE')
electrodeIndex = electrodeIndex + 1;
xElectrode = xProcessor.item(k);
electrodeName = char(xElectrode.getAttributes.item(0).getValue);
channels = [ ];
% LOOP THROUGH CHANNEL NODES FOR ELECTRODE
for m = 1:xElectrode.getChildNodes.getLength-1
if strcmp(xElectrode.item(m).getNodeName, 'SUBCHANNEL')
xChannel = xElectrode.item(m);
ch = str2num(char(xChannel.getAttributes.item(0).getValue));
channels = [channels ch];
end
end
electrodes{electrodeIndex,1} = electrodeName;
electrodes{electrodeIndex,2} = channels;
end
end
end
end
end
end
end
%%
% STEP 3: FIND THE AVAILABLE FILES
for filenum = 1:length(directory_contents)
if numel(strfind(directory_contents(filenum).name, '.continuous')) > 0
fname = directory_contents(filenum).name;
% disp(fname)
underscore = strfind(fname, '_');
chstr = strfind(fname, 'CH');
dot = strfind(fname, '.');
nodeId = str2num(fname(1:underscore-1));
chNum = str2num(fname(chstr+2:dot-1));
% disp(nodeId)
for n = 1:size(processors,1)
if nodeId == processors{n,1}
processors{n,3} = [processors{n,3} chNum];
end
end
elseif numel(strfind(directory_contents(filenum).name, '.spikes')) > 0
% don't need to do anything here
elseif numel(strfind(directory_contents(filenum).name, '.events')) > 0
info.events_file = directory_contents(filenum).name;
end
end
for n = 1:size(processors,1)
processors{n,3} = sort(processors{n,3});
end
info.electrodes = electrodes;
info.processors = processors;