Commit ff4be57e authored by mikec1's avatar mikec1
Browse files

Added the ability for the bids import button to work with derivatives.

parent 45c9de42
function out=pop_rfind(root)
filePattern = fullfile(root, 'sub-*'); % Change to whatever pattern you need.
allFiles = dir(filePattern);
% pop_rfind() - Search for BIDS compliant files inside of query folders.
%
% Usage:
% >> pop_rfind(projRoot,searchRoot)
%
% Inputs:
% projRoot - Root name of the project.
% searchRoot - Path to begin searching from.
%
% Outputs:
% Formatted pop_runhtb compliant paths to each .set file inside of a
% given searchRoot folder.
%
% See also:
% pop_runhtb();
%
% Copyright (C) 2017 Brock University Cognitive and Affective Neuroscience Lab
%
% Code written by Tyler K. Collins
%
% 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 (LICENSE.txt file in the root directory); if not,
% write to the Free Software Foundation, Inc., 59 Temple Place,
% Suite 330, Boston, MA 02111-1307 USA
function out=pop_rfind(projRoot, searchRoot)
out = '';
split = strsplit(projRoot,'/'); % Get project name.
projName = split(end);
filePattern = fullfile(searchRoot, 'sub-*'); % Search for BIDS pattern.
allFiles = dir(filePattern);
% Loops over all results
for k = 1 : length(allFiles)
subj = allFiles(k).name;
singleFile = dir(fullfile(sprintf('%s/%s/eeg/',root,subj),'*.set'));
out = sprintf('%sbids/%s/eeg/%s\n',out,subj,singleFile.name);
% Search for the generic path, and then if it exists, grab the
% file name. Afterwards, the absolute path is created.
fileSearch = fullfile(sprintf('%s/%s/eeg/',searchRoot,subj),'*.set');
singleFile = dir(fileSearch);
fullPath = strrep(fileSearch,'*.set',singleFile.name);
% Split the absolute path into a cell array, and find where the
% project name is in the array. Only include path information from
% that point on.
reSplit = strsplit(fullPath,'/');
ind = find(ismember(reSplit,projName));
finalPath = '';
for i = ind+1 : length(reSplit) % Matlab doesn't have a cell2str...
finalPath = sprintf('%s%s/',finalPath, reSplit{i});
end
% Build return variable.
out = sprintf('%s%s\n',out,finalPath);
end
end
end
\ No newline at end of file
......@@ -135,7 +135,8 @@ if nargin < 4
{'Style', 'pushbutton', 'string', 'BIDS import', ...
'callback', ...
['rootF = uigetdir();',...
'fNames = pop_rfind(rootF);', ... % call to recursive crawl method
'[exitCode, projRoot] = system(''pwd'');',...
'fNames = pop_rfind(projRoot,rootF);', ... % call to recursive crawl method
'set(findobj(gcbf,''tag'',''lst_dfn''),''string'',deblank(fNames));']} ... %5 data file push button
{'Style', 'text', 'string', 'path:'} ... %6 path: text
{'Style', 'edit', 'tag','edt_dfp'} ... %7 data path edit box
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment