saveNEVTetrodes.m 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. function saveNEVTetrodes(NEVFullFilename)
  2. % saveNEVTetrodes
  3. %
  4. % Opens saves a new NEV file and splits it into smaller NEV files
  5. % containing only the tetrodes according to the associated CCF file. The
  6. % CCF file should have the same name as the data file.
  7. %
  8. % NEVFullFilename: The full path to the NEV to be opened.
  9. % DEFAULT: If the filename is not provided, the user will
  10. % be prompted to select a file.
  11. %
  12. % Use saveNEVTetrodes(NEVFullFilename)
  13. %
  14. % Example: saveNEVTetrodes('c:\datafolder\datafile.nev');
  15. %
  16. % The function will open datafile.nev and datafile.ccf and based on the
  17. % tetrode information saved in datafile.ccf, it will split datafile.nev
  18. % into smaller chunks that will only contain channels associated to that
  19. % particular tetrode.
  20. %
  21. % Kian Torab
  22. % ktorab@blackrockmicro.com
  23. % Blackrock Microsystems
  24. % Version 1.0.0.0
  25. %
  26. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  27. % Version History
  28. %
  29. % 1.0.0.0:
  30. % - Initial release.
  31. %
  32. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  33. % Opening the file
  34. if ~exist('NEVFullFilename', 'var')
  35. [dataFilename dataFolder] = getFile('*.nev');
  36. NEVFullFilename = [dataFolder dataFilename];
  37. elseif exist(NEVFullFilename, 'file') ~= 2
  38. disp('The NEV file name does not exist.');
  39. return;
  40. else
  41. [filepath filename fileext] = fileparts(NEVFullFilename);
  42. dataFolder = [filepath '/'];
  43. dataFilename = [filename fileext];
  44. end
  45. %% Openning the associated CCF file
  46. ccfFullFilename = [dataFolder dataFilename(1:end-3) 'ccf'];
  47. if exist(ccfFullFilename, 'file') ~= 2 % for 2.x file type
  48. ccfFullFilename = [dataFolder dataFilename(1:end-8) '.ccf'];
  49. if exist(ccfFullFilename, 'file') ~= 2 % for TOC file type
  50. disp('Cannot find the associated CCF file.');
  51. disp('This function requires the CCF file used during the recording.');
  52. disp('The CCF must have the same name as the original recorded file.');
  53. return;
  54. end
  55. end
  56. ccf = openCCF(ccfFullFilename);
  57. % Calculating the number of NTrode groups in the file
  58. if isfield(ccf, 'NTrodeInfo')
  59. if isfield(ccf.NTrodeInfo, 'NTrodeMembers')
  60. numberOfNTrodeGroups = size(ccf.NTrodeInfo.NTrodeMembers,2);
  61. else
  62. disp('This data file does not contain any tetrodes.');
  63. return;
  64. end
  65. else
  66. disp('There is an error in the CCF file.');
  67. return;
  68. end
  69. % Splitting the data file according to the information saved in the
  70. % associated CCF file.
  71. for idx = 1:numberOfNTrodeGroups
  72. fprintf('Saving tetrode %d containing channels %s.\n', idx, num2str(ccf.NTrodeInfo.NTrodeMembers{idx}));
  73. saveNEVSubSpikes(ccf.NTrodeInfo.NTrodeMembers{idx}, NEVFullFilename, 'tet');
  74. end