|
| 1 | +function hdsort_compiled(outputFolder) |
| 2 | + try |
| 3 | + % cding to outputFolder is needed to save output files in the correct place |
| 4 | + cd(fullfile(outputFolder)) |
| 5 | + |
| 6 | + %% Load sorter configs and params |
| 7 | + load(fullfile(outputFolder, 'configsParams.mat')) |
| 8 | + |
| 9 | + if (strcmp(fileFormat, 'maxwell')) |
| 10 | + RAW = hdsort.file.MaxWellFile(rawFile); |
| 11 | + elseif (strcmp(fileFormat, 'mea1k')) |
| 12 | + RAW = hdsort.file.BELMEAFile(rawFile); |
| 13 | + end |
| 14 | + |
| 15 | + RAW.restrictToConnectedChannels(); % This line is very important to not sort empty electrodes! |
| 16 | + |
| 17 | + %% Create the object that performs the sorting: |
| 18 | + mainFolder = '.'; |
| 19 | + HDSorting = hdsort.Sorting(RAW, mainFolder, sortingName) |
| 20 | + |
| 21 | + %% Preprocess: |
| 22 | + % The preprocessor loads data from the file in chunks, filters it, and saves |
| 23 | + % the filtered data into a new hdf5 file that is standardized for all types |
| 24 | + % of input data. |
| 25 | + % It further performs a couple of operations for each local electrode group |
| 26 | + % (LEG) such as spike detection, spike waveform cutting and noise |
| 27 | + % estimation. The result is a folder named group000x for each LEG that |
| 28 | + % contains the data necessary to perform the parallel parts of the sorting. |
| 29 | + % This implementation minimizes the number of time-consuming file access |
| 30 | + % operations and thus speeds up the parallel processes significantly, even |
| 31 | + % allowing the parallel processes to be run on a small desktop computer or |
| 32 | + % laptop. |
| 33 | + |
| 34 | + chunkSize = chunkSize; % This number depends a lot on the available RAM |
| 35 | + HDSorting.preprocess('chunkSize', chunkSize, 'forceFileDeletionIfExists', true); |
| 36 | + |
| 37 | + %% Sort each LEG independently: |
| 38 | + HDSorting.sort('sortingMode', loopMode); % (default) |
| 39 | + % Alternative sorting modes are: |
| 40 | + % HDSorting.sort('sortingMode', 'local'); % for loop over each LEG |
| 41 | + % HDSorting.sort('sortingMode', 'grid'); % requires a computer grid architecture |
| 42 | + |
| 43 | + %% Combine the results of each LEG in the postprocessing step: |
| 44 | + HDSorting.postprocess() |
| 45 | + |
| 46 | + %% Export the results in an easy to read format: |
| 47 | + [sortedPopulation, sortedPopulation_discarded] = HDSorting.createSortedPopulation(mainFolder); |
| 48 | + |
| 49 | + %% When the sorting has already been run before, open the results from a file with: |
| 50 | + % sortedPopulation = hdsort.results.Population(HDSorting.files.results); |
| 51 | + catch |
| 52 | + fprintf('----------------------------------------'); |
| 53 | + fprintf(lasterr()); |
| 54 | + quit(1); |
| 55 | + end |
| 56 | + quit(0); |
| 57 | +end |
0 commit comments