-
Notifications
You must be signed in to change notification settings - Fork 0
/
makeProbeMap_phoenix.m
130 lines (115 loc) · 3.64 KB
/
makeProbeMap_phoenix.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
function [] = makeProbeMap_phoenix(varargin)
%% this function takes an xml file with spike groups already assigned and
%% generates *.prb files for each shank for spike detection/masking/clustering
%% IMPORTANT: this function ASSUMES that the order of the channels for each shank
%% in the spike groups map onto a specific geometrical arrangement of channels on the shank
%% starting from the top left recording site, and moving right then downward to make the
%% nearest neighbor graph
if nargin == 3
folder=varargin{1};
xmlfile=varargin{2};
shank=varargin{3}
else
folder = pwd;
s = strsplit(folder,'/')
shank = str2num(s{end});
s{end}='';
folder = strjoin(s,'/')
cd ..
xmlfile = dir('*xml');
xmlfile = xmlfile.name;
end
parameters = LoadParameters([folder ]);
warning off
for shank = shank
% make a folder for each directory
% if ~exist([folder '/' num2str(shank)])
disp(['working on shank #' num2str(shank)])
mkdir([folder '/' num2str(shank)]);
channels = parameters.spikeGroups.groups{shank};
c=1;
for i=1:length(channels)-1
for j=1
l(c,:) = [channels(i),channels(i+j)];
c=1+c;
end
end
if length(channels) < 32
for i=1:length(channels)-2
for j=2
l(c,:) = [channels(i),channels(i+j)];
c=1+c;
end
end
for i=1:length(channels)-3
for j=3
l(c,:) = [channels(i),channels(i+j)];
c=1+c;
end
end
end
list = l;
s=['channel_groups = {\n' num2str(shank) ': {\n'];
s=[s, '\t"channels": [\n' ];
for i =1:length(channels)-1
s=[s, '' num2str(channels(i)) ', ' ];
end
s=[s, '' num2str(channels(i+1))];
s=[s, '],\n' ];
s=[s, '\t"graph": [\n' ];
for i =1:length(list)-1
s=[s, '\t(' num2str(list(i,1)) ', ' num2str(list(i,2)) '),\n'];
end
% s=[s, '\t(' num2str(list(i+1,1)) ', ' num2str(list(i+1,2)) ')\n'];
s=[s, '\t],\n' ];
s=[s, '\t"geometry": {\n' ];
for i =1:length(channels)
if mod(i,2)
pn = -1;
else
pn = 1;
end
% s=[s, '\t' num2str(channels(i)) ': [' num2str(pn*(-(20+1-i)*2)) ', ' num2str(-i*10) '], \n'];
s=[s, '\t' num2str(channels(i)) ': [' num2str(pn*20) ', ' num2str(-i*10) '], \n'];
end
s=[s, '\t},\n},\n}' ];
% write .prb files to each shank folder
fid = fopen([folder '/' num2str(shank) '/' num2str(shank) '.prb'],'wt');
fprintf(fid,s);
fclose(fid);
% write .prm file as well
fid = fopen('generic_spikedetekt.prm');
i = 1;
tline = fgetl(fid);
generic{i} = tline;
while ischar(tline)
i = i+1;
tline = fgetl(fid);
generic{i} = tline;
end
fclose(fid);
% change the location of the *.dat file in the *.prm file
% generic{4} = ;
fid = fopen([folder '/' num2str(shank) '/' xmlfile(1:end-4) '_sh' num2str(shank) '.prm'],'wt');
ss = ['EXPERIMENT_NAME = ''' folder '/' num2str(shank) '/' xmlfile(1:end-4) '_sh' num2str(shank) '''\n',...
'RAW_DATA_FILES=[''' folder '/' xmlfile(1:end-4) '.dat' ''']\n',...
'PRB_FILE = ''' num2str(shank) '.prb''\n',...
'NCHANNELS = ' num2str(parameters.nChannels) '\n',...
'sample_rate = ' num2str(parameters.rates.wideband) '.\n',...
'NBITS = ' num2str(parameters.nBits) '\n'];
fprintf(fid,ss);
for i = 1:numel(generic)
if generic{i+1} == -1
fprintf(fid,'%s', generic{i});
break
else
fprintf(fid,'%s\n', generic{i});
end
% end
clear s l list c ss
end
end
if nargin ~= 3
cd(num2str(shank))
end
end