kilosort2_5_master.m 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. try
  2. % prepare for kilosort execution
  3. addpath(genpath('/net/bs-filesvr01/export/group/hierlemann/spikesorting/sorters/Kilosort'));
  4. % set file path
  5. fpath = '/net/bs-filesvr01/export/group/hierlemann/Temp/Alessio/make_test_sorted_data/sorting_output/kilosort2_5';
  6. % add npy-matlab functions (copied in the output folder)
  7. addpath(genpath(fpath));
  8. % create channel map file
  9. run(fullfile('/net/bs-filesvr01/export/group/hierlemann/Temp/Alessio/make_test_sorted_data/sorting_output/kilosort2_5/kilosort2_5_channelmap.m'));
  10. % Run the configuration file, it builds the structure of options (ops)
  11. run(fullfile('/net/bs-filesvr01/export/group/hierlemann/Temp/Alessio/make_test_sorted_data/sorting_output/kilosort2_5/kilosort2_5_config.m'))
  12. ops.trange = [0 Inf]; % time range to sort
  13. % preprocess data to create temp_wh.dat
  14. rez = preprocessDataSub(ops);
  15. % NEW STEP TO DO DATA REGISTRATION
  16. rez = datashift2(rez, 1); % last input is for shifting data
  17. % ORDER OF BATCHES IS NOW RANDOM, controlled by random number generator
  18. iseed = 1;
  19. % main tracking and template matching algorithm
  20. rez = learnAndSolve8b(rez, iseed);
  21. % OPTIONAL: remove double-counted spikes - solves issue in which individual spikes are assigned to multiple templates.
  22. % See issue 29: https://github.com/MouseLand/Kilosort/issues/29
  23. %rez = remove_ks2_duplicate_spikes(rez);
  24. % final merges
  25. rez = find_merges(rez, 1);
  26. % final splits by SVD
  27. rez = splitAllClusters(rez, 1);
  28. % decide on cutoff
  29. rez = set_cutoff(rez);
  30. % eliminate widely spread waveforms (likely noise)
  31. rez.good = get_good_units(rez);
  32. fprintf('found %d good units \n', sum(rez.good>0))
  33. % write to Phy
  34. fprintf('Saving results to Phy \n')
  35. rezToPhy(rez, fullfile(fpath));
  36. catch
  37. fprintf('----------------------------------------');
  38. fprintf(lasterr());
  39. quit(1);
  40. end
  41. quit(0);