-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProcess_RenameCopyNPX.m
145 lines (122 loc) · 3.74 KB
/
Process_RenameCopyNPX.m
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
function recList = Process_RenameCopyNPX(fbasename,varargin)
% Preprocess raw SpikeGLX data file and folders. Multiple folders are renamed
% with number (instead of _g*) and *imec* are remoed. Assuming only one
% NeuroPix probe
%
% USAGE
%
% recList = Process_RenameCopyNPX(fbasename,<optional> newfbasename)
%
% INPUT:
% fbasename the base name of the Intan recording (everything until
% the last '_g*', e.g. 'MouseXXX-YYMMDD')
% newfbsaneme change the file base name
%
% OUTPUT:
% recList a cell array containing the names of the new folders
%
% Dependencies: none
% Copyright (C) 2021 Adrien Peyrache
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
processName = [];
%Parameters:
eraseDir = 1; %Remove original directories
%cpVideo = 1; %Move and rename video files from original folders
%videoExt = {'avi';'mpg';'mov'};
if ~isempty(varargin)
newfbasename = varargin{1};
if length(varargin)>1
cpVideo = varargin{2};
end
else
newfbasename = fbasename;
end
%To access NPX_ReadMeta
addpath('/home/adrien/Toolbox/Neuropixel/SpikeGLX_Datafile_Tools/')
try
folders = dir([fbasename '_g*']);
nRec = 0;
recName = [];
for ii=1:length(folders)
if folders(ii).isdir
recName = [recName;{folders(ii).name}];
end
end
nRec = length(recName);
if nRec == 0
error('No data fodlers detected')
end
processName = 'listing folders';
recList = cell(nRec,1);
durations = [];
for ii=1:nRec
disp(ii)
nber = num2str(ii-1);
newFbase = [newfbasename '-' nber];
recList{ii} = newFbase;
processName = 'creating destination folder';
if ~exist(newFbase,'dir')
mkdir(newFbase)
end
keyboard
processName = 'create Epoch_TS.csv';
dataDir = fullfile(recName{ii},[recName{ii} '_imec0']);
fname = [recName{ii} '_t0.imec0.ap.bin'];
if exist(fullfile(dataDir,fname), 'file')
meta = NPX_ReadMeta(fname,dataDir);
durations = [durations;str2num(meta.fileTimeSecs)];
else
error(['Bin file ' fname ' does not exist in ' dataDir]);
end
fprintf([newFbase '.bin\n'])
processName = 'moving Spike Data';
movefile(fullfile(dataDir,fname),[newFbase '.bin'],'f')
fname = [recName{ii} '_t0.imec0.ap.meta'];
if exist(fullfile(dataDir,fname),'file')
movefile(fullfile(dataDir,fname),[newFbase '.meta'],'f')
else
warning(['Meta file ' fname ' does not exist'])
end
% processName = 'moving csv file';
% csvFile = dir(fullfile(recName{ii}, '*.csv'));
% if ~isempty(csvFile)
% fname = fullfile(recName{ii},csvFile.name);
% targetFile = fullfile(pwd, [newFbase, '.csv']);
% movefile(fname,targetFile,'f');
% else
% warning(['Found no csv file for ' recName{ii}]);
% end
%
% if eraseDir
% dirContent = dir(fullfile(recName{ii},'*'));
% if ~isempty(dirContent)
% answer = input('Original directory not empty, are you sure you want to remove it? [Y/N]','s');
% if strcmpi(answer,'y')
% try
% rmdir(recName{ii},'s')
% catch
% keyboard
% end
% end
% end
% end
end
%% Writing epochs.csv
epochs = zeros(nRec, 2);
start = 0;
%if length(durations) == nRec
for ii=1:nRec
epochs(ii,1) = start;
start = start + durations(ii);
epochs(ii,2) = start;
end
dlmwrite('Epoch_TS.csv',epochs,'precision','%.6f');
%end
catch
warning(lasterr)
warning(['Error while ' processName ])
end