getSubjectData.m 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. function [subjectData] = getSubjectData (sSubjectName, sVisualArea, sPenNumber, sDataType, sSelectedTimeWins)
  2. % varargin = sSubjectName, sVisualArea, sPenNumber, sDataType, sSelectedTimeWins, sSorted,
  3. % sSNRThreshold)
  4. % gets all of the data you may want for a selected subject
  5. % DEPENDS ON getSubjectInfos
  6. %
  7. % sSubjectName [Jones, Wyman, Taylor] *REQUIRED FIELD
  8. % sVisualArea [V1, V4] *REQUIRED FIELD
  9. % sPenNumber [double, GOOD, ALL] ALL is default
  10. % sDataType [LFPs, MUAEs, ALL] ALL is default
  11. % sSelectedTimeWins [PreStim, PostStim, Stationary, PostCue, PeFirstDim, PreSecondDim, PreThirdDim, ALL] MUTUALLY EXCLUSIVE, ALL is default
  12. %% PARSING INPUT PARAMETERS AND DEFAULT ASSIGNMENTS
  13. if nargin<5
  14. if nargin<4
  15. if nargin<3
  16. if nargin<2
  17. error('You should at least select a Subject Name and a Visual Area.');
  18. end
  19. sPenNumber='ALL';
  20. end
  21. sDataType='ALL';
  22. end
  23. sSelectedTimeWins='ALL';
  24. end
  25. %% CHECKING SUBJECT NAME
  26. if ~sum(cellfun(@(x) strcmp(sSubjectName,x),{'Wyman','Taylor','monkey 1','monkey 2'}))
  27. error(['The selected Subject Name "' sSubjectName '" is not valid.']);
  28. elseif strcmpi(sSubjectName,'monkey 1'); sSubjectName='Wyman';
  29. elseif strcmpi(sSubjectName,'monkey 2'); sSubjectName='Taylor';
  30. end
  31. %% CHECKING VISUAL AREA
  32. if ~sum(cellfun(@(x) strcmp(sVisualArea,x),{'V1','V4'}))
  33. error(['The selected Visual Area "' sVisualArea '" is not valid.']);
  34. end
  35. %% PARSING PEN NUMBERS
  36. subjectInfos=getSubjectInfos(sSubjectName);
  37. if strcmp(sPenNumber,'ALL')
  38. penValues=subjectInfos.penIDs;
  39. penIndices=1:length(penValues);
  40. elseif strcmp(sPenNumber,'GOOD')
  41. penVec=subjectInfos.penIDs;
  42. px=1;
  43. for pp=1:length(penVec)
  44. if strcmp(subjectInfos.penInfos(pp).([sVisualArea 'Contacts']).Quality,'BAD')
  45. warning(['PEN ID ' num2str(penVec(pp)) ' was discarded, ' sSubjectName ' ' sVisualArea ' data have BAD quality.']);
  46. else
  47. penIndices(px)=pp;
  48. penValues(px)=penVec(pp);
  49. px=px+1;
  50. end
  51. end
  52. else % if you provide a penID or interval of penIDs
  53. penVec=str2num(sPenNumber);
  54. px=1;
  55. penIndices=[];
  56. for pv=1:length(penVec)
  57. penIndex=find(subjectInfos.penIDs==penVec(pv));
  58. if isempty(penIndex)
  59. warning(['PEN ID ' num2str(penVec(pv)) ' was discarded, not valid for ' sSubjectName ' ' sVisualArea '.']);
  60. else
  61. penIndices(px)=penIndex;
  62. penValues(px)=penVec(pv);
  63. px=px+1;
  64. end
  65. end
  66. end
  67. %% CHECKING PEN NUMBERS - DISCARDING NO V1/V4 DATA
  68. if ~isempty(penIndices)
  69. rmPenIndices=zeros(1,length(penIndices));
  70. for pv=1:length(penIndices)
  71. if strcmp(subjectInfos.penInfos(penIndices(pv)).([sVisualArea 'Contacts']).Quality,['NO ' sVisualArea ' DATA']) % REJECT (MAY BE IMPROVED)
  72. warning(['NO ' sVisualArea ' DATA for ' sSubjectName ' PEN ' num2str(penValues(pv))]);
  73. rmPenIndices(pv)=1;
  74. end
  75. end
  76. penIndices(logical(rmPenIndices))=[];
  77. penValues(logical(rmPenIndices))=[];
  78. if isempty(penIndices)
  79. error(['None of the selected PEN IDs "' sPenNumber '" is valid for ' sSubjectName ' ' sVisualArea '.']);
  80. end
  81. else
  82. error(['None of the selected PEN IDs "' sPenNumber '" is valid for ' sSubjectName ' ' sVisualArea '.']);
  83. end
  84. %% CHECKING DATATYPE
  85. if ~sum(cellfun(@(x) strcmp(sDataType,x),{'LFPs','iCSDs','MUAes','ALL'}))
  86. error(['The selected Data Type "' sDataType '" is not valid.']);
  87. end
  88. %% CHECKING THE TIME WINDOWS
  89. allTimeWins={'PreStim','PostStim','Stationary','PostCue','PreFirstDim','PreSecondDim','PreThirdDim','ALL'};
  90. % Parsing selected time windows
  91. if ~strcmp(sSelectedTimeWins,'ALL')
  92. error('Selecting a single timewin is not supported yet, write some code');
  93. end
  94. if ~sum(cellfun(@(x) strcmp(sSelectedTimeWins,x),allTimeWins))
  95. error(['The selected Time Window "' sSelectedTimeWins '" is not valid.']);
  96. end
  97. %% INITIALIZE THE DATA STRUCTURE
  98. subjectData.subjectName=sSubjectName;
  99. subjectData.penIDs=subjectInfos.penIDs(penIndices);
  100. for pp=1:length(penIndices)
  101. %% PARSING LAYERS TO GET DATA FROM OR PARSING SNRs - EVENTUALLY LATER
  102. %% GETTING LFPs
  103. if strcmp(sDataType,'LFPs') || strcmp(sDataType,'ALL')
  104. disp(['Loading ' sSelectedTimeWins ' LFPs for ' sSubjectName ' ' sVisualArea ' PEN ' num2str(penValues(pp))]);
  105. LLStr=load(subjectInfos.penInfos(penIndices(pp)).selectedTimeWinsFilePaths.([sVisualArea 'Contacts']).LFPs);
  106. if ~isempty(LLStr.LfpStruct)
  107. subjectData.LfpStruct(pp).Sorted=LLStr.LfpStruct.Sorted;
  108. end
  109. subjectData.LfpStruct(pp).penNum=subjectInfos.penIDs(penIndices(pp));
  110. clear LLStr
  111. end
  112. %% GETTING MUAes
  113. if strcmp(sDataType,'MUAEs') || strcmp(sDataType,'ALL')
  114. disp(['Loading ' sSelectedTimeWins ' MUAs for ' sSubjectName ' ' sVisualArea ' PEN ' num2str(penValues(pp))]);
  115. MMstr=load(subjectInfos.penInfos(penIndices(pp)).selectedTimeWinsFilePaths.([sVisualArea 'Contacts']).MUAs);
  116. if ~isempty(MMstr.MUAStruct)
  117. subjectData.MUAStruct(pp).Sorted=MMstr.MUAStruct.Sorted;
  118. end
  119. subjectData.MUAStruct(pp).penNum=subjectInfos.penIDs(penIndices(pp));
  120. clear MMstr
  121. end
  122. %% Appending penInfos
  123. subjectData.penInfos(pp)=subjectInfos.penInfos(penIndices(pp));
  124. end
  125. end