-
Notifications
You must be signed in to change notification settings - Fork 9
/
getPixIdFromROIFile.m
110 lines (101 loc) · 4.98 KB
/
getPixIdFromROIFile.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
function [pixId imageName] = getPixIdFromROIFile(imageName, omeroUser, omeroServer)
%Pass in a filename and return the matching pixelsId as read from the
%roiFileMap.xml system file.
%
%Author Michael Porter
% Copyright (C) 2009-2014 University of Dundee.
% All rights reserved.
%
% This program 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 2 of the License, or
% (at your option) any later version.
%
% This program 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 this program; if not, write to the Free Software Foundation, Inc.,
% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
%[imageName, remain] = strtok(imageName, '.');
%On Windows systems...
if ispc;
sysUserHome = getenv('userprofile');
sysUser = getenv('username');
defaultUserPath = userpath;
if strcmp(defaultUserPath(1), 'H')
%This is a really horrible hack to get around working on this Domain.
%Sorry!!!!
mapPath = 'H:\omero\roiFileMap.xml';
else
mapPath = [sysUserHome '\omero\roiFileMap.xml'];
end
mapStruct = xml2struct(mapPath);
for thisServer = 1:length(mapStruct.children)
if strcmp(mapStruct.children(thisServer).name, '#text')
continue;
end
if strcmpi(mapStruct.children(thisServer).attributes(1).value, omeroServer)
for thisUser = 1:length(mapStruct.children(thisServer).children)
if strcmp(mapStruct.children(thisServer).children(thisUser).name, '#text')
continue;
end
if strcmpi(mapStruct.children(thisServer).children(thisUser).attributes(1).value, omeroUser)
for thisImage = 1:length(mapStruct.children(thisServer).children(thisUser).children)
if strcmp(mapStruct.children(thisServer).children(thisUser).children(thisImage).name, '#text')
continue;
end
for thisFile = 1:length(mapStruct.children(thisServer).children(thisUser).children(thisImage).children)
if strcmp(mapStruct.children(thisServer).children(thisUser).children(thisImage).children(thisFile).name, '#text')
continue;
end
partName = mapStruct.children(thisServer).children(thisUser).children(thisImage).children(thisFile).attributes(1).value;
% while ~isempty(partName)
% [nameProc, partName] = strtok(partName, '\');
% end
%[imageNameFromStruct, remain] =
%strtok(nameProc, '.');
% imageNameScanned = textscan(imageName, '%s', 'Delimiter', '/');
% imageNameNoPaths = imageNameScanned{1}{end};
if strcmp(partName, imageName)
pixId = mapStruct.children(thisServer).children(thisUser).children(thisImage).attributes(1).value;
return;
else
pixId = [];
end
end
end
end
end
end
end
clear mapStruct;
else
%On Mac and Unix systems...
sysUser = getenv('HOME');
mapPath = [sysUser, '/omero/roiFileMap.xml'];
mapStruct = xml2struct(mapPath);
for thisServer = 1:length(mapStruct.children)
if strcmpi(mapStruct.children(thisServer).attributes(1).value, omeroServer)
for thisUser = 1:length(mapStruct.children(thisServer).children)
if strcmpi(mapStruct.children(thisServer).children(thisUser).attributes(1).value, omeroUser)
for thisImage = 1:length(mapStruct.children(thisServer).children(thisUser).children)
[nameProc, partName] = strtok(mapStruct.children(thisServer).children(thisUser).children(thisImage).children.attributes(1).value, '/');
while ~isempty(partName)
[nameProc, partName] = strtok(partName, '/');
end
[imageNameFromStruct, remain] = strtok(nameProc, '.');
if strcmp(imageNameFromStruct, imageName)
pixId = mapStruct.children(thisServer).children(thisUser).children(thisImage).attributes(1).value;
return;
end
end
end
end
end
end
clear mapStruct;
end
end