Skip to content

Commit

Permalink
updating pipelines
Browse files Browse the repository at this point in the history
  • Loading branch information
emilyasterjones committed Mar 11, 2024
1 parent 9244c48 commit b7127c4
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 7 deletions.
8 changes: 4 additions & 4 deletions eaj_qualityMetrics_pipeline.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
%% set paths
clearvars
probe = 0;
sessions = readtable('D:\WT_Sequences\all_sessions.csv');
for s = 201:height(sessions) %[97,101-200]
sessions = readtable('Z:\WT_Sequences\2024_winter\Preprocessed_Data\Provenance\all_sessions.csv');
for s = 1:height(sessions)
epoch = string(sessions{s,'Epoch'});
rec_error = string(sessions{s,'Recording_Error'});
if strcmp(epoch, 'g1') && strcmp(rec_error, 'FALSE')
if strcmp(epoch, 'g0') && strcmp(rec_error, 'FALSE')
% generate the path to the directory containing the ap.bin file
base_dir = string(sessions{s,'Base_Directory'});
base_dir = strrep(base_dir, '/', '\');
ecephys_path = strcat(base_dir, '\Preprocessed_Data\Spikes\g1');
ecephys_path = strcat(base_dir, '\Preprocessed_Data\Spikes');

rec_file_stem = split(string(sessions{s,'File'}),'/');
rec_file_stem = convertStringsToChars(rec_file_stem(2));
Expand Down
5 changes: 2 additions & 3 deletions eaj_qualityMetrics_pipeline_2point0.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@

%% set paths
clearvars
%%%sessions = readtable('D:\WT_Sequences\all_sessions.csv');
sessions = readtable('Z:\WT_Sequences\2023_spring\Preprocessed_Data\Provenance\all_sessions.csv');
for s = 350
sessions = readtable('Z:\WT_Sequences\2024_winter\Preprocessed_Data\Provenance\all_sessions.csv');
for s = 1:height(sessions)
task = string(sessions{s,'Task'});
rec_error = string(sessions{s,'Recording_Error'});
for probe = 0:1
Expand Down
58 changes: 58 additions & 0 deletions eaj_qualityMetrics_pipeline_WenSorscher2023.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
%% ~~ EAJ bombcell pipeline ~~
% Adjust the paths in the 'set paths' section and the parameters in bc_qualityParamValues
% This pipeline will run bombcell on your data and save the output

addpath(genpath("C:\Users\Niflheim\Documents\GitHub\External\bombcell"))
addpath(genpath("C:\Users\Niflheim\Documents\GitHub\External\npy-matlab"))
addpath(genpath("C:\Users\Niflheim\Documents\GitHub\External\prettify_matlab"))

%% set paths
clearvars
sessions = readtable('//oak-smb-giocomo.stanford.edu/groups/giocomo/export/data/Projects/JohnKei_NPH3/WenSorscher2023_revisions/all_sessions.csv');
%'Z:\WT_Sequences\2023_spring\Preprocessed_Data\Provenance\all_sessions.csv'
for s = 29
%rec_error = string(sessions{s,'Recording_Error'});
for probe = 0
% generate the path to the directory containing the ap.bin file
base_dir = string(sessions{s,'Base_Directory'});
base_dir = strrep(base_dir, '/', '\');
ecephys_path = base_dir;

rec_file_stem = split(string(sessions{s,'File'}),'/');
rec_file_stem = convertStringsToChars(rec_file_stem);
rec_file_path = sprintf('%s\\%s\\SuperCat\\%s\\supercat_%s\\%s_imec%d',...
ecephys_path, string(sessions{s,'Animal'}),...
rec_file_stem(1:end-3), rec_file_stem,...
rec_file_stem, probe);

% set variables for BombCell
mainDir = rec_file_path;
ephysKilosortPath = sprintf('%s/imec%d_ks',rec_file_path,probe);
rec_file_base = sprintf('%s/%s_tcat.imec%d.ap',rec_file_path,rec_file_stem, probe);
rawFile = [rec_file_base,'.bin'];
ephysMetaFile = [rec_file_base,'.meta'];

saveLocation = mainDir;
savePath = fullfile(saveLocation, 'qMetrics');

% load data
[spikeTimes_samples, spikeTemplates, templateWaveforms, templateAmplitudes, pcFeatures, ...
pcFeatureIdx, channelPositions] = bc_loadEphysData(ephysKilosortPath);

% which quality metric parameters to extract and thresholds
param = eaj_qualityParamValues(ephysMetaFile, rawFile, ephysKilosortPath);
% param = bc_qualityParamValuesForUnitMatch(ephysMetaDir, rawFile) % Run this if you want to use UnitMatch after

%% compute quality metrics
[qMetric, unitType] = bc_runAllQualityMetrics(param, spikeTimes_samples, spikeTemplates, ...
templateWaveforms, templateAmplitudes,pcFeatures,pcFeatureIdx,channelPositions, savePath);

%% save to cluster_group.tsv
% overwrite ecephys cluster labels if any units were found to be noise
cluster_group_file = [ephysKilosortPath filesep 'cluster_group.tsv'];
cluster_group = readtable(cluster_group_file, 'FileType', 'text', 'Delimiter', '\t');
cluster_group(unitType==0,'group') = {'noise'};
writetable(cluster_group, cluster_group_file, 'FileType', 'text', 'Delimiter', '\t');

end
end

0 comments on commit b7127c4

Please sign in to comment.