-
Notifications
You must be signed in to change notification settings - Fork 3
/
parseInputGroupKey_v1.m
71 lines (61 loc) · 2.27 KB
/
parseInputGroupKey_v1.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
function [subjectID, indexVec, groupNames]=parseInputGroupKey_v1(pathToKey)
%parseInputGroupKey(pathToKey)
%
%This function is an attempt at providing a robust parsing function for
%extracting subject group membership
%
% INPUTS
%
% pathToKey: a path to either a directory or file containing the group
% membership information stored as either a excel file or a csv.
%
% OUTPUTS:
%
% subjectID: a vector containing all subject IDs
%
% indexVec: A 1x[# of subjects] vector containing integers corresponding
% to the entry in the <groupNames> which indicates the group membership of
% this subject
%
% groupNames: a vector containing all group names
%
% by Dan Bullock 24 Jan 2020
%% Begin code
subjectID=[];
indexVec=[];
groupNames=[];
if isfile(pathToKey) %single keyfile case
[~,~,ext] = fileparts(pathToKey)
if strcmp(ext,'xlsx') %ignore xls case for now
[~,holdText]=xlsread(pathToKey)
%finish making this robust at some later point
keyboard
elseif strcmp(ext,'xlsx') %csv case
tableContents=readtable(pathToKey)
%finish making this robust at some later point
keyboard
end %end extension casing
elseif isfolder(pathToKey)
keyDirContents=dir(pathToKey);
inputDirFileNames = {keyDirContents(~[keyDirContents(:).isdir]).name};
for iInputKeyFiles=1:length(inputDirFileNames) %iuterate across input key files
currentFileName=fullfile(pathToKey,inputDirFileNames{iInputKeyFiles});
[~,curGroupLabel,ext] = fileparts(currentFileName);
%append current group name
groupNames=vertcat(groupNames,{curGroupLabel});
if strcmp(ext,'.xlsx') %ignore xls case for now
[~,tableContents]=xlsread(currentFileName);
%append current subjIds
subjectID=vertcat(subjectID,tableContents);
curIndexVec=ones(length(tableContents),1);
curIndexVec(:)=iInputKeyFiles;
indexVec=vertcat(indexVec,curIndexVec);
%finish making this robust at some later point
elseif strcmp(ext,'.csv') %csv case
tableContents=readtable(pathToKey);
%finish making this robust at some later point
keyboard
end %end extension casing
end
end
end