Skip to content
This repository has been archived by the owner. It is now read-only.

Commit

Permalink
recent changes we made together at processing computer
Browse files Browse the repository at this point in the history
  • Loading branch information
MPIBR-vollrathf committed Aug 10, 2016
1 parent eac77cf commit 19bcf07
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 75 deletions.
98 changes: 50 additions & 48 deletions CellSortLoadSingleFiles.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,55 +9,57 @@
%go into trial folders and import files
wb = waitbar(0, 'Loading Files..');
for i=1:size(trialFolders,2)
waitbar(i/size(trialFolders,2));
%go into trialFodlers and import data
cd(num2str(i));
%import data
fileListGreen = dir(green);
fileListRed = dir(red);
numFilesGreen = size(fileListGreen,1);
numFilesRed = size(fileListRed,1);



if numFilesGreen ~= numFilesRed
disp('Green and Red Channel have different number of Images, take the smaller value..');
end
numFiles = min([numFilesRed, numFilesGreen]);
temp = readTiff(fileListGreen(1).name);
data_g_temp = zeros(size(temp,1), size(temp,2), numFiles, class(temp));
temp = readTiff(fileListRed(1).name);
data_r_temp = zeros(size(temp,1), size(temp,2), numFiles, class(temp));

for j=1:numFiles
temp = readTiff(fileListGreen(j).name);
data_g_temp(:,:,j) = temp;
temp = readTiff(fileListRed(j).name);
data_r_temp(:,:,j) = temp;
end

%if data is no existent, preallocate it one time when i == 1
if i==1 && ~exist('data_g', 'var') && ~exist('data_r','var')
data_g = data_g_temp;
data_r = data_r_temp;
else
temp_data = zeros(size(temp,1), size(temp,2), size(data_g,3)+numFiles, class(temp));
temp_data(:,:,1:size(data_g,3)) = data_g;
temp_data(:,:,(size(data_g,3)+1):end) = data_g_temp;
data_g = temp_data;

temp_data = zeros(size(temp,1), size(temp,2), size(data_r,3)+numFiles, class(temp));
temp_data(:,:,1:size(data_r,3)) = data_r;
temp_data(:,:,(size(data_r,3)+1):end) = data_r_temp;
data_r = temp_data;
if exist(num2str(i), 'dir')
waitbar(i/size(trialFolders,2));
%go into trialFodlers and import data
cd(num2str(i));
%import data
fileListGreen = dir(green);
fileListRed = dir(red);
numFilesGreen = size(fileListGreen,1);
numFilesRed = size(fileListRed,1);



if numFilesGreen ~= numFilesRed
disp('Green and Red Channel have different number of Images, take the smaller value..');
end
numFiles = min([numFilesRed, numFilesGreen]);
temp = readTiff(fileListGreen(1).name);
data_g_temp = zeros(size(temp,1), size(temp,2), numFiles, class(temp));
temp = readTiff(fileListRed(1).name);
data_r_temp = zeros(size(temp,1), size(temp,2), numFiles, class(temp));

parfor j=1:numFiles
temp = readTiff(fileListGreen(j).name);
data_g_temp(:,:,j) = temp;
temp = readTiff(fileListRed(j).name);
data_r_temp(:,:,j) = temp;
end

%if data is no existent, preallocate it one time when i == 1
if i==1 && ~exist('data_g', 'var') && ~exist('data_r','var')
data_g = data_g_temp;
data_r = data_r_temp;
else
temp_data = zeros(size(temp,1), size(temp,2), size(data_g,3)+numFiles, class(temp));
temp_data(:,:,1:size(data_g,3)) = data_g;
temp_data(:,:,(size(data_g,3)+1):end) = data_g_temp;
data_g = temp_data;

temp_data = zeros(size(temp,1), size(temp,2), size(data_r,3)+numFiles, class(temp));
temp_data(:,:,1:size(data_r,3)) = data_r;
temp_data(:,:,(size(data_r,3)+1):end) = data_r_temp;
data_r = temp_data;
end

%add data_g_temp and data_r_temp to outputData



%go back
cd ..;
end

%add data_g_temp and data_r_temp to outputData



%go back
cd ..;
end
close(wb);
end
9 changes: 6 additions & 3 deletions CellSortShiftCorrection.m
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
function [data_g, data_r] = CellSortShiftCorrection(data_g, data_r)
function [data_g, data_r] = CellSortShiftCorrection(data_g, data_r, firstRedFrame)
%% shiftcorrection
%import green channel
disp('Performing Shift Correction..');
%shift correction
firstRedFrame = data_r(:,:,1);
parfor r = 2:size(data_g, 3)
% wb = waitbar(0, 'Performing Shift Correction..');
parfor r = 1:size(data_g, 3)
% waitbar(r/size(data_g, 3), wb,[num2str(r) ' of ' num2str(size(data_g, 3))]);
shiftVector = findshift(firstRedFrame, data_r(:,:,r), 'iter');
data_r(:,:,r) = shift(data_r(:,:,r),shiftVector);
data_g(:,:,r) = shift(data_g(:,:,r),shiftVector);

end
disp('finished');
% close(wb);
end
3 changes: 3 additions & 0 deletions CellSortTemporalBinning.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
class_r = class(data_r);

data_g = cast(binning(data_g, binningFactor, 'mean'), class_g);

data_r = cast(binning(data_r, binningFactor, 'mean'), class_r);


end
38 changes: 14 additions & 24 deletions main.m
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
%% load and prepare all single tiffs
%importing
[data_g, data_r] = CellSortLoadSingleFiles('ChanA_*_*.tif', 'ChanB_*_*.tif');
%shiftCorrection
% [data_g, data_r] = CellSortLoadSingleFiles('ChanA_*_*.tif', 'ChanB_*_*.tif', data_g, data_r);
%% matVis
matVis(data_r);
%% get ref frame for shift correction
interval = 1:20;
refFrame = cast(mean(data_r(:,:,interval), 3), class(data_r));
matVis(refFrame);
%% shiftCorrection
%generates shift corrected files for the green and red channels, needs
%DIPlib (available for free)
[data_g, data_r] = CellSortShiftCorrection(data_g, data_r);
[data_g, data_r] = CellSortShiftCorrection(data_g, data_r, refFrame);
%temporal binning
binningFactor = [1 1 2]; %x, y, t
[data_g, data_r] = CellSortTemporalBinning(data_g, data_r, binningFactor);
%% export
fn_green = 'green.tif';
fn_red = 'red.tif';

fn_green = 'green.tiff';
fn_red = 'red.tiff';
CellSortExportTifStack(data_g, fn_green);
CellSortExportTifStack(data_r, fn_red);
%% load files
%if you haven't used the shiftCorrection you have to load the already processed files
fn_green = 'green.tif';
fn_red = 'red.tif';
fn_green = 'green.tiff';
fn_red = 'red.tiff';
data_g = readTiff(fn_green);
data_r = readTiff(fn_red);
%% 1. PCA
Expand Down Expand Up @@ -88,23 +95,6 @@
%optionally, plot signals
figure(2)
CellsortICAplot('series', ica_filters, ica_sig, movm, tlims, dt, 1, 2, [1:20], spt, spc);
%% prepare georgis data for visualization
%optionally, if you want to use the alternative evaluation georgi was using, import the
%mask and run this section
fn='green_13.tiff';
info = imfinfo(fn);
num_images = numel(info);
data_g = readTiff(fn);
%make mask logical
mask1 = logical(mask.*(mask > 0));
ica_segments = permute(mask, [3 1 2]);
mask1 = repmat(mask, [1 1 1 size(data_g,3)]);
%generate cell_sig for every feature
cellsig = zeros(size(mask1,3), size(data_g,3));
for i=1:size(mask1,3)
cell_sig(i,:) = squeeze(mean(mean(squeeze(mask1(:,:,i,:)).*data_g(:,:,:),1),2));
end
clear mask
%% show signal of cells (cell_sig)
%caluclate correlation matrix for cell_sig
[ica_segments, cluster, subPlotCols, subPlotWidth, sortedIdx] = calcCorrEff(cell_sig, ica_segments);
Expand Down

0 comments on commit 19bcf07

Please sign in to comment.