function [subjectData] = getSubjectData (sSubjectName, sVisualArea, sPenNumber, sDataType, sSelectedTimeWins) % varargin = sSubjectName, sVisualArea, sPenNumber, sDataType, sSelectedTimeWins // sSorted, sSNRThreshold % gets all of the data you may want for a selected subject % DEPENDS ON getSubjectInfos % % sSubjectName [monkey 1, monkey 2] *REQUIRED FIELD % sVisualArea [V1, V4] *REQUIRED FIELD % sPenNumber [double, GOOD, ALL] ALL is default % sDataType [LFPs, MUAEs, ALL] ALL is default % sSelectedTimeWins [PreStim, PostStim, Stationary, PostCue, PeFirstDim, PreSecondDim, PreThirdDim, ALL] MUTUALLY EXCLUSIVE, ALL is default %% PARSING INPUT PARAMETERS AND DEFAULT ASSIGNMENTS if nargin<5 if nargin<4 if nargin<3 if nargin<2 error('You should at least select a Subject Name and a Visual Area.'); end sPenNumber='ALL'; end sDataType='LFPs'; end sSelectedTimeWins='ALL'; end %% CHECKING SUBJECT NAME if ~sum(cellfun(@(x) strcmp(sSubjectName,x),{'Wyman','Taylor','monkey 1','monkey 2'})) error(['The selected Subject Name "' sSubjectName '" is not valid.']); elseif strcmpi(sSubjectName,'Wyman'); sSubjectName='monkey 1'; elseif strcmpi(sSubjectName,'Taylor'); sSubjectName='monkey 2'; end %% CHECKING VISUAL AREA if ~sum(cellfun(@(x) strcmp(sVisualArea,x),{'V1','V4'})) error(['The selected Visual Area "' sVisualArea '" is not valid.']); end %% PARSING PEN NUMBERS subjectInfos=getSubjectInfos(sSubjectName); if strcmp(sPenNumber,'ALL') penValues=subjectInfos.penIDs; penIndices=1:length(penValues); elseif strcmp(sPenNumber,'GOOD') penVec=subjectInfos.penIDs; px=1; for pp=1:length(penVec) if strcmp(subjectInfos.penInfos(pp).([sVisualArea 'Contacts']).Quality,'BAD') warning(['PEN ID ' num2str(penVec(pp)) ' was discarded, ' sSubjectName ' ' sVisualArea ' data have BAD quality.']); else penIndices(px)=pp; penValues(px)=penVec(pp); px=px+1; end end else % if you provide a penID or interval of penIDs penVec=str2num(sPenNumber); px=1; penIndices=[]; for pv=1:length(penVec) penIndex=find(subjectInfos.penIDs==penVec(pv)); if isempty(penIndex) warning(['PEN ID ' num2str(penVec(pv)) ' was discarded, not valid for ' sSubjectName ' ' sVisualArea '.']); else penIndices(px)=penIndex; penValues(px)=penVec(pv); px=px+1; end end end %% CHECKING PEN NUMBERS - DISCARDING NO V1/V4 DATA if ~isempty(penIndices) rmPenIndices=zeros(1,length(penIndices)); for pv=1:length(penIndices) if strcmp(subjectInfos.penInfos(penIndices(pv)).([sVisualArea 'Contacts']).Quality,['NO ' sVisualArea ' DATA']) % REJECT (MAY BE IMPROVED) warning(['NO ' sVisualArea ' DATA for ' sSubjectName ' PEN ' num2str(penValues(pv))]); rmPenIndices(pv)=1; end end penIndices(logical(rmPenIndices))=[]; penValues(logical(rmPenIndices))=[]; if isempty(penIndices) error(['None of the selected PEN IDs "' sPenNumber '" is valid for ' sSubjectName ' ' sVisualArea '.']); end else error(['None of the selected PEN IDs "' sPenNumber '" is valid for ' sSubjectName ' ' sVisualArea '.']); end %% CHECKING DATATYPE if ~sum(cellfun(@(x) strcmp(sDataType,x),{'LFPs','iCSDs','MUAes','ALL'})) error(['The selected Data Type "' sDataType '" is not valid.']); end %% CHECKING THE TIME WINDOWS allTimeWins={'PreStim','PostStim','Stationary','PostCue','PreFirstDim','PreSecondDim','PreThirdDim','ALL'}; % Parsing selected time windows if ~strcmp(sSelectedTimeWins,'ALL') error('Selecting a single timewin is not supported yet, write some code'); end if ~sum(cellfun(@(x) strcmp(sSelectedTimeWins,x),allTimeWins)) error(['The selected Time Window "' sSelectedTimeWins '" is not valid.']); end %% INITIALIZE THE DATA STRUCTURE subjectData.subjectName=sSubjectName; subjectData.penIDs=subjectInfos.penIDs(penIndices); for pp=1:length(penIndices) %% PARSING LAYERS TO GET DATA FROM OR PARSING SNRs - EVENTUALLY LATER %% GETTING LFPs if strcmp(sDataType,'LFPs') || strcmp(sDataType,'ALL') disp(['Loading ' sSelectedTimeWins ' LFPs for ' sSubjectName ' ' sVisualArea ' PEN ' num2str(penValues(pp))]); LLStr=load(subjectInfos.penInfos(penIndices(pp)).selectedTimeWinsFilePaths.([sVisualArea 'Contacts']).LFPs); if ~isempty(LLStr.LfpStruct) subjectData.LfpStruct(pp).Sorted=LLStr.LfpStruct.Sorted; subjectData.LfpStruct(pp).penNum=subjectInfos.penIDs(penIndices(pp)); end clear LLStr end %% GETTING MUAes if strcmp(sDataType,'MUAEs') || strcmp(sDataType,'ALL') disp(['Loading ' sSelectedTimeWins ' MUAs for ' sSubjectName ' ' sVisualArea ' PEN ' num2str(penValues(pp))]); MMstr=load(subjectInfos.penInfos(penIndices(pp)).selectedTimeWinsFilePaths.([sVisualArea 'Contacts']).MUAs); if ~isempty(MMstr.MUAStruct) subjectData.MUAStruct(pp).Sorted=MMstr.MUAStruct.Sorted; subjectData.MUAStruct(pp).penNum=subjectInfos.penIDs(penIndices(pp)); end clear MMstr end %% Appending penInfos subjectData.penInfos(pp)=subjectInfos.penInfos(penIndices(pp)); end end