1 %> @brief
"Pirouette" TXT loader/saver
3 %> This is how a dataset will look like by selecting the whole spreadsheet in Pirouette (Informetrix Inc.) and pasting
4 %> it into Excel. See Figure 1 for specification.
6 %> @image html dataformat_pir.png
7 %> <center>Figure 1 - "Pirouette" TXT file type</center>
10 %> (optional) Image height. If specified, will assign it the loaded dataset
12 %> ='hor'. Whether the pixels are taken horizontally ('hor') or vertically ('ver') to form the image.
13 %> It was found that OPUS numbers the point in the image map left-right, bottom-up, hence 'hor'.
14 %> Same
as irdata.direction (although
irdata.direction has a different default).
20 function data = load(o)
28 mask_header = ['%q' repmat('%f', 1, no_cols-2) '%q'];
30 mask_data = ['%q' repmat('%f', 1, no_cols-2) '%q'];
32 % Opens for the second time in order to actually read the file
33 fid = fopen(o.filename);
34 c_header = textscan(fid, mask_header, 1, 'Delimiter', delimiter);
35 x = cell2mat(c_header(2:end-1));
39 trend = sign(x(i)-x(i-1));
40 elseif sign(x(i)-x(i-1)) ~= trend
41 irerror('There is something wrong with this text file!');
47 c_data = textscan(fid, mask_data, 'Delimiter', delimiter);
51 data.X = cell2mat(c_data(2:end-1));
54 % first column will be parsed to extract data.groupcodes
55 % all content at first dot and beyond is discarded
57 no_obs = length(labels);
58 data.groupcodes = cell(no_obs, 1);
61 idxs = regexp(label,
'\.');
64 idx = length(label)+1;
66 idx = idxs(end); % The aim is to take everything before the last '.'
69 data.groupcodes{i} = label(1:idx-1);
75 clalpha = c_data{end};
77 clalpha = cellfun(@num2str, num2cell(clalpha), 'UniformOutput', 0);
79 clalpha = cellfun(@
strip_quotes, clalpha, 'UniformOutput', 0);
80 data.classlabels = unique(clalpha)';
82 data.classes(no_obs, 1) = -1; %
pre-allocates
84 data.classes(i) = find(strcmp(data.classlabels, clalpha{i}))-1;
88 data.assert_not_nan();
89 data.filename = o.filename;
90 data.filetype =
'txt2';
91 data = data.make_groupnumbers();
93 data.height = o.height;
94 data.direction = o.direction;
100 function o = save(o, data)
102 h = fopen(o.filename, 'w');
104 irerror(sprintf('Could not create file ''%s''!', o.filename));
107 nel_group = size(data.groupcodes, 1);
110 fwrite(h, [sprintf('\t') sprintf('%g\t', data.fea_x) sprintf('\n')]);
115 groupcode = data.groupcodes{i};
117 fwrite(h, [groupcode sprintf(
'\t') sprintf(
'%g\t', data.X(i, :)) labels{i} sprintf(
'\n')]);
122 irverbose(sprintf(
'Just saved file "%s"', o.filename), 2);
function irverbose(in s, in level)
Pre-processing block base class.
function classes2labels(in classes, in labels)
Dataset loader/saver common class.
"Pirouette" TXT loader/saver
Analysis Session (AS) base class.
function strip_quotes(in s)
function get_no_cols_deli(in filename)