Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
%% 1) Generalised workflow
% specify folder name where data of interested are saved
recording_dir = '\\storage.laur.corp.brain.mpg.de\Data_2\CoattiAlex\Experiments_2015\turtle_6March\Ale+6March_sampleT';
cd(recording_dir); content_folder = dir;
% specify data type (it depends on imaging system used)
data_type = 'RedShirt'; % 'Andor'
if strcmp(data_type, 'RedShirt' )
disp('show tsm files in current folder');
dir '*.tsm'
y = dir;
%find position of tsm file in current folder
idx = strfind({y(:).name},'.tsm');
out = find(cellfun(@(v) any(isfinite(v(:))), idx));
filename = cell(length(out),1);
if length(out) == 1
filename = y(out).name;
else
disp('there are more repeats in the same folder');
for j = 1:length(out)
filename{j} = y(out(j)).name;
end
end
elseif strcmp(data_type, 'Andor' )
% here ANDOR data
end
%% Initialize an object for VSD data
clear obj
for i = 1:length(filename)
recording_file = strcat(recording_dir,filesep,filename{i});
if strcmp(data_type, 'RedShirt' )
obj(i) = redShirt(recording_file);
elseif strcmp(data_type, 'Andor' )
% here ANDOR data
end
end
%% extract raw traces from subset of pixels
% ( 1 ) select pixels of ROIs (downsample image, reduce resolution) % % % % % % % % % % % % % % % % % % % % %
pix_linear_ind = reshape(1:256*256,256,256);
p_r = 8; p_c = 8; step_r = 1:p_r:256; step_c = 1:p_c:256;
roi_id = zeros(p_r * p_c * numel(step_r)*numel(step_c) ,1);
pxl_id = pix_linear_ind; % pxl_id = reshape(1:length(index{1})*length(index{2}),length(index{1}),length(index{2})); %reshape(1:256*256,256,256);
counter = 0;
for c = step_c
for r = step_r
counter = counter + 1;
tempid = pxl_id(r: r + p_r-1, c: c + p_c-1);
roi_id((1:p_r*p_c) + p_r*p_c*(counter-1) ) = tempid(:);
end
end
% select the ROIs of the final downsampled image that you want to extract
% traces from
pix_downsample = reshape(1:length(step_r)*length(step_c),length(step_r),length(step_c));
roi_selected = 1:length(step_r)*length(step_c); %[133,153,394,503,681,824];
% ( 2 ) INPUTs for getData method % % % % % % % % % % % % % % % % % % % % % %
% choose single pixels of the full 256*256 matrix of linear indices (pxl_linear_ind)
% channels can either be a n*1 vector or a n*m matrix in the case of
% equally sized rois (to be implemented: allow for non-equally sized rois
% by ordering selected pixels in channels as a linear vector and in
% roi_size vector put the total number of pixels in each successive roi
% e.g. roi1 = 10 pxl, roi2 = 15 pxl, roi3 = 5 pxl etc roi_size = [10, 15, 3 ....]
channels = [];
for i = 1:length(roi_selected);
if i == 1
channels = roi_id( (roi_selected(i)-1) * p_r*p_c +[1:p_r*p_c] );
else
channels = [channels; roi_id( (roi_selected(i)-1) * p_r*p_c +[1:p_r*p_c] )];
end
end
events_time = 0; % frame number from which to start extracting data
startTime_ms = events_time .* (1/obj.samplingFrequency *1000); %starting frame * duration in ms of one frame
window_frames = obj.recordingDuration_ms * obj.samplingFrequency/1000 ; % for full recording, obj.recordingDuration_ms * obj.samplingFrequency/1000
window_ms = repmat(window_frames * 1/obj.samplingFrequency *1000,1,length(startTime_ms)); % total number of frames in ms
% mode 1 = 'fullframe' it extracts traces from all pixels of one frame
% mode 2 = 'single_pixels' it extracts traces for each pixels
% entered in the channels input and treats them separately
% mode 3 = 'roi' (an easy outline for ROIs could be
% rectangular and implement ROIs with any type of shape
% later)
mode = 'fullframe';
name = [];
% flags_reading_data = [];
flags_reading_data = {'saveDataToFileMode',1,'DarkFrameSubtraction',1,'DarkFrame_Last',0,'recompose_channels',0} % default values {1,1,0,0}
[raw_data, time_intervals] = obj.getData(channels,startTime_ms,window_ms,mode,name,flags_reading_data);
nTrials = length(startTime_ms);
raw_frames = reshape(raw_data,256,256,nTrials,max(window_frames));
clear raw_data time_intervals
% - pool together multiple repeats - note :if it's multiple trials you should use
% the functionality of the object
max_window_frames = 10000; %max([obj(:).recordingDuration_ms] .* [obj(i).samplingFrequency/1000]);
data_multiple_trials = zeros(256,256,max_window_frames,length(filename),'uint16');
flags_reading_data = {'saveDataToFileMode',0,'DarkFrameSubtraction',1,'DarkFrame_Last',0,'recompose_channels',0}
for i = 1:length(filename)
channels = [];
events_time = 0; % frame number from which to start extracting data
startTime_ms = events_time .* (1/obj(i).samplingFrequency *1000); %starting frame * duration in ms of one frame
window_frames = 10000; % for full recording, obj.recordingDuration_ms * obj.samplingFrequency/1000
window_ms = repmat(window_frames * 1/obj(i).samplingFrequency *1000,1,length(startTime_ms)); % total number of frames in ms
[raw_data] = obj(i).getData(channels,startTime_ms,window_ms,mode,name,flags_reading_data);
data_multiple_trials(:,:,1:window_frames,i) = raw_data;
clear raw_data
end
[raw_pixels, time_intervals_pixels] = obj.getData(channels,startTime_ms,window_ms,mode,name);
% pixel order is subjected to two transformations by the algorithm for
% data extraction
% ind1 = NaN(1,256*256/2);
% ind2 = NaN(1,256*256/2);
% for c = 1:256
% ind1( [1:128]+128*(c-1) ) = [1:128] + 256*(c-1);
% ind2( [1:128]+128*(c-1) ) = fliplr([129:256] + 256*(c-1));
% end
% deinterleaving_matrix = cat(1,reshape(ind1,128,256),reshape(ind2,128,256));
% [~,ord] = sort(deinterleaving_matrix(channels));
% raw_temp = raw_pixels(ord,:,:);
% raw_pixels_in_frame = zeros( size(raw_temp) );
roi_mask = reshape(zeros(256*256,1),256,256);
roi_mask(channels) = 1;
% test to verify that the data read-in algorithm performs accurately
% (besides being more efficient)
figure,
subplot(121), imagesc(squeeze(squeeze(raw_frames(:,:,1,1))) .* roi_mask), axis square
subplot(122),
test_frame = reshape(zeros(256*256,1),256,256);
test_frame(channels) = raw_pixels(1:length(channels),1,1);
imagesc(test_frame), axis square