kilosort_folder_denoised = join(denoised_folder, 'Kilosort') clean.cleanup_kilosorted_data(kilosort_folder_denoised, number_of_channels_in_binary_file=const. NUMBER_OF_AP_CHANNELS_IN_BINARY_FILE, binary_data_filename=binary_data_filename, prb_file=const.prb_file, type_of_binary=const.BINARY_FILE_ENCODING, order_of_binary='F', sampling_frequency=20000, num_of_shanks_for_vis=5) # ------------------------------------------------------------------------- # ------------------------------------------------------------------------- # CREATE TEMPLATE INFO ---------------------------------------------------- spp.generate_probe_positions_of_templates(kilosort_folder_denoised) spp.view_grouped_templates_positions(kilosort_folder_denoised, const.BRAIN_REGIONS, const.PROBE_DIMENSIONS, const.POSITION_MULT) #template_info = preproc_kilo.generate_template_info_after_cleaning(kilosort_folder_denoised, sampling_freq) template_info = np.load(join(kilosort_folder_denoised, 'template_info.df')) templates_in_cortex = template_info[ template_info['position Y'] * const.POSITION_MULT > const.BRAIN_REGIONS['CA1']] templates_in_cortex.index = np.arange(len(templates_in_cortex)) templates_in_cortex['number of spikes'].sum()
np.argwhere(np.in1d(spike_templates_v, templates_clean_index_v))) spike_templates_clean_v = spike_templates_v[spikes_clean_index_v] template_markings_a = np.load(join(base_folder_a, 'template_marking.npy')) spike_templates_a = np.load(join(base_folder_a, 'spike_templates.npy')) templates_clean_index_a = np.argwhere(template_markings_a) spikes_clean_index_a = np.squeeze( np.argwhere(np.in1d(spike_templates_a, templates_clean_index_a))) spike_templates_clean_a = spike_templates_a[spikes_clean_index_a] weighted_average_postions_v, spike_distance_on_probe_v = \ pos.generate_probe_positions_of_spikes(base_folder_v, binary_v, number_of_channels_in_binary_file, spikes_clean_index_v) weighted_template_positions_v = pos.generate_probe_positions_of_templates( base_folder_v, threshold=0.1) weighted_average_postions_a, spike_distance_on_probe_a = \ pos.generate_probe_positions_of_spikes(base_folder_a, binary_a, number_of_channels_in_binary_file, spikes_clean_index_a) weighted_template_positions_a = pos.generate_probe_positions_of_templates( base_folder_a, threshold=0.1) position_mult = 2.25 probe_dimensions = [100, 8100] brain_regions_v = { 'AuD': 5208, 'Au1': 4748, 'AuV': 2890,
number_of_channels_in_binary_file=const. NUMBER_OF_AP_CHANNELS_IN_BINARY_FILE, binary_data_filename=binary_data_filename, prb_file=const.prb_file, type_of_binary=const.BINARY_FILE_ENCODING, order_of_binary='F', sampling_frequency=20000, num_of_shanks_for_vis=5) # ---------------------------------------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------------------------------------- # STEP 5: CREATE TEMPLATE INFO OF ALL THE CLEANED TEMPLATES # a) Create the positions of the templates on the probe (and have a look) spp.generate_probe_positions_of_templates(kilosort_folder_denoised) spp.view_grouped_templates_positions(kilosort_folder_denoised, const.BRAIN_REGIONS, const.PROBE_DIMENSIONS, const.POSITION_MULT) # b) Create the template_info.df dataframe (or load it if you already have it) # template_info = preproc_kilo.generate_template_info_after_cleaning(kilosort_folder_denoised, sampling_freq) template_info = np.load(join(kilosort_folder_denoised, 'template_info.df'), allow_pickle=True) # ---------------------------------------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------------------------------------- # STEP 6: PICK THE CORTICAL SPIKES AND T-SNE THEM
print('Single: {}'.format(len(np.argwhere(template_marking == 1)))) print('Contaminated: {}'.format(len(np.argwhere(template_marking == 2)))) print('Putative: {}'.format(len(np.argwhere(template_marking == 3)))) print('Multi: {}'.format(len(np.argwhere(template_marking == 4)))) print('Non Multi: {}'.format(len(np.argwhere(template_marking == 1)) + len(np.argwhere(template_marking == 2)) +len(np.argwhere(template_marking == 3)))) # </editor-fold> # ---------------------------------------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------------------------------------- # <editor-fold desc = "STEP 2: CREATE TEMPLATE INFO OF ALL THE CLEANED TEMPLATES" # a) Create the positions of the templates on the probe (and have a look) _ = spp.generate_probe_positions_of_templates(kilosort_folder) bad_channel_positions = spp.get_y_spread_regions_of_bad_channel_groups(kilosort_folder, const.bad_channels) # b) Create the template_info.df dataframe (or load it if you already have it) # template_info = preproc_kilo.generate_template_info_after_cleaning(kilosort_folder, sampling_freq) template_info = np.load(join(kilosort_folder, 'template_info.df'), allow_pickle=True) # c) Make the spike info from the initial, cleaned, kilosort results # spike_info = preproc_kilo.generate_spike_info_after_cleaning(kilosort_folder) spike_info = np.load(join(kilosort_folder, 'spike_info_after_cleaning.df'), allow_pickle=True) # </editor-fold> # ----------------------------------------------------------------------------------------------------------------------
type_of_binary = np.uint16 # CLEANING KILOSORT RESULTS ------------------------- cdc.generate_average_over_spikes_per_template_multiprocess(base_folder=kilosort_folder, binary_data_filename=join(data_folder, amplifier_file), number_of_channels_in_binary_file=number_of_channels_in_binary_file, cut_time_points_around_spike=80) ckt.cleanup_kilosorted_data(kilosort_folder, number_of_channels_in_binary_file=number_of_channels_in_binary_file, binary_data_filename=join(data_folder, amplifier_file), prb_file=prb_file, type_of_binary=type_of_binary, order_of_binary='F', sampling_frequency=30000) # --------------------------------------------------- # Generate positions on probe weighted_template_positions = pos.generate_probe_positions_of_templates(kilosort_folder, threshold=0.1) np.save(join(kilosort_folder, 'weighted_template_positions.npy'), weighted_template_positions) # --------------------------- # REDOING TSNE ON CLEAN KILOSORT RESULTS ------------ spike_clusters = np.load(join(kilosort_folder, 'spike_clusters.npy')) template_marking = np.load(join(kilosort_folder, 'template_marking.npy')) spikes_used = np.array([spike_index for spike_index in np.arange(len(spike_clusters)) if template_marking[spike_clusters[spike_index]] > 0]) np.save(join(tsne_folder, 'indices_of_spikes_used.npy'), spikes_used) template_features_sparse_clean = \ preproc.calculate_template_features_matrix_for_tsne(kilosort_folder, save_to_folder=tsne_folder, spikes_used_with_original_indexing=spikes_used) template_features_sparse_clean = np.load(join(tsne_folder, 'data_to_tsne_(272886, 140).npy'))