Skip to content

Commit ac9534f

Browse files
committed
bugs fix (read xlsx and assign animal groups)
1 parent b025438 commit ac9534f

File tree

2 files changed

+49
-29
lines changed

2 files changed

+49
-29
lines changed

segmentation/animal_groups.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,10 +339,10 @@ function ok_callback(varargin)
339339
k = 2;
340340
for i = 1:num_cols/2
341341
for j = 1:size(animal_ids{i},2)
342-
if isempty(Table{j+1,k})
342+
if isempty(Table{j,k})
343343
empty_g = 1;
344344
end
345-
user_groups = [user_groups str2num(Table{j+1,k})];
345+
user_groups = [user_groups str2num(Table{j,k})];
346346
end
347347
k = k+2;
348348
end
@@ -370,8 +370,8 @@ function ok_callback(varargin)
370370
k = 2;
371371
for i = 1:num_cols/2
372372
for j = 1:size(animal_ids{i},2)
373-
if isempty(Table{j+1,k})
374-
Table{j+1,k} = generated;
373+
if isempty(Table{j,k})
374+
Table{j,k} = generated;
375375
end
376376
end
377377
k = k+2;

segmentation/parse_data_simplified.m

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,57 @@
55
ids_temp = [];
66
session = 1;
77
f = dir(fullfile(path));
8+
89
% take the first folder
910
for k = 3:length(f)
1011
if f(k).isdir == 1
1112
fprintf('Parsing Animal IDs from folder: %s\n',f(k).name);
1213
new_path = [path '/' f(k).name];
13-
files = dir(fullfile([path '/' f(k).name], '/*.csv'));
14+
ext = {'/*.csv','/*.CSV','/*.xlsx','/*.XLSX'};
15+
for i = 1:length(ext)
16+
files = dir(fullfile([path '/' f(k).name], ext{i}));
17+
if ~isempty(files)
18+
break
19+
end
20+
end
1421
for j = 1:length(files)
15-
% open the csv file
16-
fid = fopen(fullfile(new_path,'/',files(j).name));
17-
% get the first line
18-
num_cols = fgetl(fid);
19-
% close it
20-
fclose(fid);
21-
% get the number of columns
22-
num_cols = length(find(num_cols==','))+1;
23-
% make the file format
24-
fmt = repmat('%s ',[1,num_cols]);
25-
% re-open the file and parse all its data
26-
fid = fopen(fullfile(new_path,'/',files(j).name));
27-
data = textscan(fid,fmt,'CollectOutput',1,'Delimiter',',');
28-
data = data{1};
29-
fclose(fid);
30-
% Search the Animal ID field and parse the ID number
31-
i = 1;
32-
while i <= size(data,1)
33-
if isequal(data{i,1},id_field)
34-
id = sscanf(data{i,2}, '%d');
35-
break;
36-
end
37-
i = i+1;
38-
end
22+
[~, ~, ext] = fileparts(fullfile(new_path,'/',files(j).name));
23+
if isequal(ext,'.CSV') || isequal(ext,'.csv')
24+
% open the file
25+
fid = fopen(fullfile(new_path,'/',files(j).name));
26+
% get the first line
27+
num_cols = fgetl(fid);
28+
% close it
29+
fclose(fid);
30+
% get the number of columns
31+
num_cols = length(find(num_cols==','))+1;
32+
% make the file format
33+
fmt = repmat('%s ',[1,num_cols]);
34+
% re-open the file and parse all its data
35+
fid = fopen(fullfile(new_path,'/',files(j).name));
36+
data = textscan(fid,fmt,'CollectOutput',1,'Delimiter',',');
37+
data = data{1};
38+
fclose(fid);
39+
% Search the Animal ID field and parse the ID number
40+
i = 1;
41+
while i <= size(data,1)
42+
if isequal(data{i,1},id_field)
43+
id = sscanf(data{i,2}, '%d');
44+
break;
45+
end
46+
i = i+1;
47+
end
48+
elseif isequal(ext,'.XLSX') || isequal(ext,'.xlsx')
49+
[~, ~, data] = xlsread(fullfile(new_path,'/',files(j).name));
50+
while i <= size(data,1)
51+
if isequal(data{i,1},id_field)
52+
id = data{i,2};
53+
break;
54+
end
55+
i = i+1;
56+
end
57+
end
58+
3959
% store the animal ids
4060
try
4161
ids_temp = [ids_temp, id];

0 commit comments

Comments
 (0)