diff --git a/CellSortLoadSingleFiles.m b/CellSortLoadSingleFiles.m index b0172a0..2a06796 100644 --- a/CellSortLoadSingleFiles.m +++ b/CellSortLoadSingleFiles.m @@ -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 \ No newline at end of file diff --git a/CellSortShiftCorrection.m b/CellSortShiftCorrection.m index c06ea8f..f395b4b 100644 --- a/CellSortShiftCorrection.m +++ b/CellSortShiftCorrection.m @@ -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 \ No newline at end of file diff --git a/CellSortTemporalBinning.m b/CellSortTemporalBinning.m index ac371bd..6b1af3e 100644 --- a/CellSortTemporalBinning.m +++ b/CellSortTemporalBinning.m @@ -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 diff --git a/main.m b/main.m index 89dd598..018ece7 100644 --- a/main.m +++ b/main.m @@ -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 @@ -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);