-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart_analysis.m
More file actions
58 lines (58 loc) · 2.32 KB
/
start_analysis.m
File metadata and controls
58 lines (58 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
%% Set path and determine blocks
% Open level of interest in cd (likely animal)
nArr = {'rRFA','lRFA'}; % set array designations
currLoc = pwd;
level_list = dirr(currLoc); % directory at level
ndir = 0;
for i = 1:numel(level_list)
if isfolder(level_list(i).name) % checks for folders in directory
ndir=1+ndir;
block_list(ndir)=level_list(i); % folders are designated as blocks
end
end
nBlocks = length(block_list);
%% Make new analysis location
for i = 1:nBlocks
locB =(fullfile(currLoc, block_list(i).name, 'Analysis')); % define name/location of folder
if exist(locB,'dir')==0 % if non-existent, make new folder
mkdir(locB)
end
end
clearvars -except currLoc nArr block_list nBlocks
%% Load spike data and save spike trains
for i = 1:nBlocks % block level
locSp=(fullfile(currLoc, block_list(i).name,'_Spikes'));
load(fullfile(currLoc,[block_list(i).name,'_Block.mat']))
fs = blockObj.SampleRate;
lenMin = blockObj.Samples./fs./60;
lenSec = blockObj.Samples./fs;
totSamples = floor(blockObj.Samples);
ch_list = dirr(fullfile(locSp));
for ii = 1:length(ch_list) % channel level
store = load(fullfile(locSp,ch_list(ii).name));
sp = store.data;
pkTrain = zeros(totSamples,1);
ts = sp(:,4)*fs; % time stamps (by sample) for identified spikes
pkTrain(round(ts)) = 1; % set samples at timestamps to 1
spikes = sp(:,5:end);
artifact = [];
if contains(ch_list(ii).name,['P1','P2']) % change if less than 32ch arrays are being used
idx = (strfind(ch_list(ii).name,'Ch_'))+3;
nCh = str2num(ch_list(ii).name(idx:(idx+2)));
if contains(ch_list(ii).name,'P2')
nCh = nCh+16;
end
n = [block_list(i).name,'_ptrain_Ch_',nCh];
save(fullfile(arr1,n),'spikes','artifact','pkTrain','-v7.3')
else
idx = (strfind(ch_list(ii).name,'Ch_'))+3;
nCh = str2num(ch_list(ii).name(idx:(idx+2)));
if contains(ch_list(ii).name,'P4')
nCh = nCh+16;
end
n = [block_list(i).name '_ptrain_Ch_',nCh];
save(fullfile(arr2,n),'spikes','artifact','pkTrain','-v7.3')
end
end
end
clearvars -except currLoc nArr arr1 arr2 block_list