Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

SequenceDuration.m 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import tools.GetCSVs;
  2. pathdir = uigetdir();
  3. files = dir(pathdir);
  4. nfiles = size(files);
  5. disp(size(nfiles));
  6. % Take the first viable subject, then extract the conditions
  7. oldVersion = false;
  8. for i=1:nfiles[1];
  9. num = files(i).name;
  10. if files(i).isdir && ~isnan(str2double(num));
  11. subjPath = fullfile(pathdir, num, "Modules");
  12. conditions = GetCSVs(subjPath, "Mouse");
  13. % The old version used different names for the modules.
  14. if length(conditions) == 0;
  15. disp("Warning: this dataset was obtained from an old version of SEB3R.");
  16. conditions = GetCSVs(subjPath, "MouseX");
  17. end
  18. break
  19. end
  20. end
  21. nconditions = length(conditions);
  22. % Perform sequencing. This will result in a folder "Sequenced" containing
  23. % $nconditions folders, each
  24. for icond = 1:nconditions;
  25. clear FullSeqs;
  26. condition = conditions{icond};
  27. TotalFrames = 0;
  28. for i = 1:nfiles(1)
  29. if files(i).isdir()
  30. num = files(i).name;
  31. if ~isnan(str2double(num));
  32. subj = num;
  33. out=SingleSubjectCount(pathdir, subj, condition, oldVersion);
  34. [nmodules, cols] = size(out);
  35. FullSeqs(TotalFrames+1:TotalFrames+nmodules, :) = out;
  36. TotalFrames = TotalFrames + nmodules;
  37. end
  38. end
  39. end
  40. outdir = fullfile(pathdir, "Sequenced");
  41. mkdir(outdir);
  42. writematrix(FullSeqs, fullfile(outdir, condition + ".csv"));
  43. end
  44. function frameCount = SingleSubjectCount(pathdir, subject, condition, oldVersion)
  45. parentPath = fullfile(pathdir, subject, "Modules");
  46. % this is pretty ugly
  47. mouseStr = 'Mouse';
  48. if oldVersion;
  49. mouseStr = 'MouseX';
  50. end
  51. path = fullfile(parentPath, [mouseStr condition '.csv']);
  52. frameData = readmatrix(path);
  53. [rows, cols] = size(frameData);
  54. frameModules = frameData(:, cols); % last column = BM
  55. frameCount = CountFrames(frameModules);
  56. outPath = fullfile(parentPath, "Sequenced" + condition + ".csv");
  57. %writematrix(frameCount, outPath);
  58. end
  59. function out=CountFrames(frames)
  60. if length(frames) == 0;
  61. error("Expecting non-empty numerical array, found an empty array. Is your subject data complete?");
  62. end
  63. lastSeen = frames(1);
  64. counter = 1;
  65. foundSeqs = 1;
  66. for i=2:length(frames)
  67. if frames(i) == lastSeen;
  68. counter = counter + 1;
  69. else
  70. out(foundSeqs, :) = [lastSeen, counter];
  71. lastSeen = frames(i);
  72. counter = 1;
  73. foundSeqs = foundSeqs + 1;
  74. end
  75. end
  76. % The last iteration is always left out
  77. out(foundSeqs, :) = [lastSeen, counter];
  78. end