Commit c48b21d8 authored by Antonio Politi's avatar Antonio Politi
Browse files

fix to properly process CC data

parent 626768d0
function master_workflow_fit_dye_subdirectories(wd)
% MASTER_WORKFLOW_FIT_DYE_SUBDIRECTORIES call workflow_fit_dye for all
% subdirectories in a main directory (wd)
% The program search only for one level down wd. Subdirectories should contain correlation traces generated by FA
% MASTER_WORKFLOW_FIT_DYE_SUBDIRECTORIES() - prompt for a main directory
% MASTER_WORKFLOW_FIT_DYE_SUBDIRECTORIES(wd) - use wd as main directory
%
% Antonio Politi, EMBL, April 2017
if nargin < 1
wd = uigetdir('.', 'Specify main directory where to search for subfolders');
cd(wd);
end
% get all subdirectories
[indirCell] = getAllFolders(wd, '.*');
indirCell = {wd, indirCell{:}};
% output subdiretoy to store results
outputdir = 'optimisedFit';
% range to fit kappa
kappaVal = [2:0.1:9]';
force = 0;
alexa488 = [464, 464, 464];
alexa568 = [521, 521, 521];
atto488 = [509, 509, 509];
FAsession = '1c';
for idir = 1:length(indirCell)
indir = indirCell{idir};
% check for xml files in this subdirectory otherwise move to next
% directory
if isempty(getAllFiles(indir, 'xml',['\.' FAsession '\.'], 0))
continue
end
display(['master_workflow_fit_dye processing directory ' num2str(idir) ' ' indir])
try
workflow_fit_dye(indir, kappaVal, outputdir, FAsession, force, alexa488);
catch ME
display(['failed master_workflow_fit_dye processing directory ' num2str(idir) ' ' indir ' ']);
display(getReport(ME))
end
end
\ No newline at end of file
......@@ -7,7 +7,6 @@ session = '2c'
force = 1;
if nargin <1
wd = uigetdir('.', 'Specify main directory where to search protein folders');
%wd = 'Z:\AntonioP_elltier1\CelllinesImaging\MitoSysPipelines';
cd(wd);
end
......@@ -16,7 +15,7 @@ if ~exist(fullfile(wd, 'ProcessingHelpFiles'));
end
if ~exist(fullfile(wd, 'ProcessingHelpFiles', 'protein2cfiles.mat')) || force
[indirCell] = getAllFolders(wd, '\Mito(s|S)ys\d');
[indirCell] = getAllFolders(wd, '(\Mito(s|S)ys\d)|(LSM880)');
resfiles = [];
for i = 1:length(indirCell)
resfiles = [resfiles; getAllFiles(indirCell{i}, 'res', [session '.res'], 0)];
......
function [focVolA, focVolfile] = workflow_fit_dye(indir, kappaVal, outputdir, FAsession, force)
function [focVolA, focVolfile] = workflow_fit_dye(indir, kappaVal, outputdir, FAsession, force, diffCoeff)
% COMPUTEDIRECTORY perform fitting of dye in a specific directory. program
% assumes that traces of one experiment are all in one directory!
% INPUT:
......@@ -20,7 +20,7 @@ function [focVolA, focVolfile] = workflow_fit_dye(indir, kappaVal, outputdir, FA
% 4. Repeat 1-3 with new kappa (this is repeated ~ 3 times)
%
% Antonio Politi, EMBL, January 2017
replot = 1;
%% default values
if nargin < 1
% prompt for a directory
......@@ -50,23 +50,31 @@ end
clear('MO');
MO = dyeFcsmodel();
% make outputdir if required
outdir = fullfile(indir, outputdir);
if ~exist(outdir)
mkdir(outdir);
if nargin == 6
MO.diffCoeff = diffCoeff;
end
% find files from ZEN and FA
zenfiles = getAllFiles(indir, 'fcs');
xmlFAfiles = getAllFiles(indir, 'xml',['\.' FAsession '\.']);
%corFiles = getAllFiles(indir,'cor', '1c'); this is obsolete as we do extract data from xml
%%
if isempty(xmlFAfiles) & isempty(zenfiles)
display('No FA xml or .fcs found stop here');
return
end
if isempty(xmlFAfiles)
display('No FA xml found use .fcs file instead');
cond = 3;
else
cond = 1;
end
% make outputdir if required
outdir = fullfile(indir, outputdir);
if ~exist(outdir)
mkdir(outdir);
end
switch cond
case 1 %fit using data from FA weighted with standard deviation
......@@ -109,27 +117,38 @@ if exist(fullfile(outdir, [prefix '.mat'])) %load result file if it exists alrea
process =1;
end
end
if (process || force)
%% load data into cell array dataC
if ZEN
dataC = MO.readZeissfcs(zenfiles{1});
else
dataC = MO.readFAxml(xmlFAfiles);
end
if isempty(dataC)
return
end
if (process || force)
%% load data into cell array dataC
if ZEN
dataC = MO.readZeissfcs(zenfiles{1});
else
dataC = MO.readFAxml(xmlFAfiles);
end
if isempty(dataC)
return
end
% starting value of kappa
kappa = 5;
% number of repeats for each fit (starts from random values)
%MO.maxfittry = 1;
%maxRounds = 1;
% MO.maxfittry = 1;
% maxRounds = 1;
MO.maxfittry = 5;
maxRounds = 3;
% struct to store data for each channel
Chfits = struct('outPar', [], 'kappaVal', kappaVal, 'kappa', [],'posBest', [], 'focRad', [], 'mfocRad', [], 'focVol', [], ...
'mfocVol', [], 'conc', [], 'mConc', [], 'normN', [], 'mNorm', []);
Chfits(2) = Chfits;
Chfits(2) = Chfits(1);
Chfits(3) = Chfits(1);
% for each channel
for iC = 1:2
for iC = 1:3
if (dataC{1}(1,iC*2) == 0) % do not process if channel has not been acquired
continue
end
......@@ -206,14 +225,15 @@ end
if (dataC{1}(1,4) == 0)
Chfits(2) = Chfits(1);
end
if (dataC{1}(1,6) == 0)
Chfits(3) = Chfits(1);
end
save(fullfile(outdir, [prefix '.mat']), 'Chfits');
end
% avoid cases were boundary of kappaVal is touched and use a value of kappa
% avoid cases where boundary of kappaVal is touched and use a value of kappa
% = 5.8 instead this is the average values obtained for many experiments
posB = find(kappaVal==5.8);
if all([Chfits.posBest] == [1 1]) || all([Chfits.posBest] == [lk lk])
if all([Chfits.posBest] == ones(1, length(Chfits))) || all([Chfits.posBest] == lk*ones(1, length(Chfits)))
posB = find(kappaVal==5.8);
elseif (Chfits(1).posBest == 1) || (Chfits(1).posBest == lk)
posB = Chfits(2).posBest;
......@@ -223,8 +243,8 @@ else
posB = round(mean([Chfits(1).posBest,Chfits(2).posBest]));
end
focVolA = [Chfits(1).mfocRad(posB) Chfits(1).mfocVol(posB) Chfits(1).kappaVal(posB);...
Chfits(2).mfocRad(posB) Chfits(2).mfocVol(posB) Chfits(2).kappaVal(posB); ...
sqrt(Chfits(1).mfocRad(posB)*Chfits(2).mfocRad(posB)) sqrt(Chfits(1).mfocVol(posB)*Chfits(2).mfocVol(posB)) Chfits(2).kappaVal(posB)];
Chfits(2).mfocRad(posB) Chfits(2).mfocVol(posB) Chfits(2).kappaVal(posB); ...
sqrt(Chfits(1).mfocRad(posB)*Chfits(2).mfocRad(posB)) sqrt(Chfits(1).mfocVol(posB)*Chfits(2).mfocVol(posB)) Chfits(2).kappaVal(posB)];
focVolfile = fullfile(indir, 'focalVolume.txt');
fid = fopen(focVolfile, 'w');
fprintf(fid,'w0_um\tVol_fl\tkappa\r\n');
......@@ -235,8 +255,8 @@ fclose(fid);
%% save all rounds of fit
if process || force
for iC = 1:2
if process || force || replot
for iC = 1:3
if (dataC{1}(1,iC*2) == 0) % do not process if channel has not been acquired
continue
end
......@@ -251,10 +271,10 @@ for iC = 1:2
fprintf(fid,'%.4e\r\n', outPar(i,end));
end
fclose(fid);
end
end
%% update xml files and write a res file
if ~ZEN
%% update xml files and write a res file
if ~ZEN
for iD = 1:length(dataC)
node = xmlFA.readnode(xmlFAfiles{iD});
[path, fout, ext] = fileparts(xmlFAfiles{iD});
......@@ -264,7 +284,7 @@ if ~ZEN
fit = zeros(Nfits, 3);
par = repmat(struct2array(MO.par),3,1);
nrPar = length(par);
for iC = 1:2
for iC = 1:3
if (dataC{iD}(1,iC*2) == 0) % do not process if channel has not been acquired
continue
end
......@@ -280,12 +300,12 @@ if ~ZEN
xmlFA.writefit(node, fit, idxs, MO.model);
xmlFA.writenode(fname_out, node);
end
end
end
%% plot results
for iC = 1:2
%% plot results
for iC = 1:3
if (dataC{1}(1,iC*2) == 0) % do not process if channel has not been acquired
continue
end
......@@ -344,6 +364,6 @@ for iC = 1:2
ylabel('Concentration (nM)')
xlabel('kappa')
saveas(hf,fullfile(outdir,[prefix '_Ch' num2str(iC) '.png']), 'png')
end
end
end
end
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment