Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Assaf
DeBiasCME
Commits
5b7c5476
Commit
5b7c5476
authored
Apr 25, 2016
by
Assaf
Browse files
(1) ROI-related bugs solved (2) integrated ZK's version
parent
f6b32a39
Changes
13
Hide whitespace changes
Inline
Side-by-side
code/DeBiasCmeCond1Cond2.m
View file @
5b7c5476
...
...
@@ -22,7 +22,7 @@ manualAnnotateROIMain(dirnameCond2,params.doAnnotate,master,slave1,slave2);
close
all
;
doColocalizationDirectories
(
dirnameCond1
,
params
,
master
,
slave1
,
slave2
);
doColocalizationDirectories
(
dirnameCond1
,
params
,
master
,
slave1
,
slave2
);
% TODO: implement MI, add flag for multiple measures
doColocalizationDirectories
(
dirnameCond2
,
params
,
master
,
slave1
,
slave2
);
if
params
.
doMetaAnalysis
...
...
@@ -31,6 +31,7 @@ end
end
%% Meta analysis: 2 conditions
% TODO: (1) implement slave2, (2)
function
[]
=
metaAnalysisDeBiasCMECond1Cond2
(
baseDirname
,
cond1Str
,
cond2Str
,
params
,
master
,
slave1
,
slave2
)
close
all
;
...
...
@@ -43,20 +44,35 @@ addpath(genpath('/home2/azaritsky/code/extern/export_fig'));
dirnameCond1
=
[
baseDirname
filesep
cond1Str
];
dirnameCond2
=
[
baseDirname
filesep
cond2Str
];
% MasterSlave1
%% MasterSlave1
% Cond1
load
([
dirnameCond1
filesep
'out.mat'
]);
GI_Cond1_MasterSlave1
=
GIsMasterSlave1
(
GIsMasterSlave1
<
7
);
LI_Cond1_MasterSlave1
=
LIsMasterSlave1
(
GIsMasterSlave1
<
7
);
CORR_Cond1_MasterSlave1
=
CORRsMasterSlave1
(
GIsMasterSlave1
<
7
);
nCCPs_Cond1_MasterSlave1
=
nCCPs
;
nCells_Cond1_MasterSlave1
=
nCells
;
% 201604
cond1MasterDists
{
1
}
=
masterDist
;
% Do we need the {1}? see getAccDistributions function
cond1Slave1Dists
{
1
}
=
slave1Dist
;
cond1MasterSlave1JointDists
{
1
}
=
jointDistMasterSlave1
;
% Cond2
load
([
dirnameCond2
filesep
'out.mat'
]);
GI_Cond2_MasterSlave1
=
GIsMasterSlave1
(
GIsMasterSlave1
<
7
);
LI_Cond2_MasterSlave1
=
LIsMasterSlave1
(
GIsMasterSlave1
<
7
);
CORR_Cond2_MasterSlave1
=
CORRsMasterSlave1
(
GIsMasterSlave1
<
7
);
nCCPs_Cond2_MasterSlave1
=
nCCPs
;
nCells_Cond2_MasterSlave1
=
nCells
;
% MasterSlave2
% 201604
cond2MasterDists
{
1
}
=
masterDist
;
cond2Slave1Dists
{
1
}
=
slave1Dist
;
cond2MasterSlave1JointDists
{
1
}
=
jointDistMasterSlave1
;
%% MasterSlave2
if
hasSlave2
load
([
dirnameCond1
filesep
'out.mat'
]);
GI_Cond1_MasterSlave2
=
GIsMasterSlave2
(
GIsMasterSlave2
<
7
);
...
...
@@ -64,54 +80,124 @@ if hasSlave2
CORR_Cond1_MasterSlave2
=
CORRsMasterSlave2
(
GIsMasterSlave2
<
7
);
nCCPs_Cond1_MasterSlave2
=
nCCPs
;
% 201604
cond1Slave2Dists
{
1
}
=
slave2Dist
;
cond1MasterSlave2JointDists
{
1
}
=
jointDistMasterSlave2
;
load
([
dirnameCond2
filesep
'out.mat'
]);
GI_Cond2_MasterSlave2
=
GIsMasterSlave2
(
GIsMasterSlave2
<
7
);
LI_Cond2_MasterSlave2
=
LIsMasterSlave2
(
GIsMasterSlave2
<
7
);
CORR_Cond2_MasterSlave2
=
CORRsMasterSlave2
(
GIsMasterSlave2
<
7
);
nCCPs_Cond2_MasterSlave2
=
nCCPs
;
% 201604
cond2Slave2Dists
{
1
}
=
slave2Dist
;
cond2MasterSlave2JointDists
{
1
}
=
jointDistMasterSlave2
;
end
%% Output
outdir
=
baseDirname
;
loggerFname
=
[
outdir
'log.txt'
];
logger
=
fopen
(
loggerFname
,
'w'
);
fclose
(
logger
);
%%
if
hasSlave2
error
(
'No implementation of MetaAnalysis for 3 channels - contact Assaf (assafzar@gmail.com) for such an implementation'
);
end
%% 201604: new analysis : calculate cumulative distributions, look at p-value of GI!
outStr1
=
sprintf
(
'\n *** %s - %s ***\n'
,
cond1Str
,
cond2Str
);
outStr2
=
sprintf
(
'GI pval = %f (%f vs. %f)\n'
,
ranksum
(
GI_Cond1_MasterSlave1
,
GI_Cond2_MasterSlave1
),
...
mean
(
GI_Cond1_MasterSlave1
),
mean
(
GI_Cond2_MasterSlave1
));
outStr3
=
sprintf
(
'LI pval = %f (%f vs. %f)\n'
,
ranksum
(
LI_Cond1_MasterSlave1
,
LI_Cond2_MasterSlave1
),
...
mean
(
LI_Cond1_MasterSlave1
),
mean
(
LI_Cond2_MasterSlave1
));
outStr4
=
sprintf
(
'RHO pval = %f (%f vs. %f)\n'
,
ranksum
(
CORR_Cond1_MasterSlave1
,
CORR_Cond2_MasterSlave1
),
...
mean
(
CORR_Cond1_MasterSlave1
),
mean
(
CORR_Cond2_MasterSlave1
));
fprintf
(
outStr1
);
fprintf
(
outStr2
);
fprintf
(
outStr3
);
fprintf
(
outStr4
);
outStr
=
[
outStr1
outStr2
outStr3
outStr4
];
logger
=
fopen
(
loggerFname
,
'a+'
);
fprintf
(
logger
,
outStr
);
fclose
(
logger
);
[
cond1MasterAccDist
,
cond1Slave1AccDist
,
cond1MasterSlave1JointDist
]
=
getAccDistributions
(
cond1MasterDists
,
cond1Slave1Dists
,
cond1MasterSlave1JointDists
);
[
cond2MasterAccDist
,
cond2Slave1AccDist
,
cond2MasterSlave1JointDist
]
=
getAccDistributions
(
cond2MasterDists
,
cond2Slave1Dists
,
cond2MasterSlave1JointDists
);
% fontsize = 22;
plotDeBiasCMEJointDistribution
(
cond1MasterSlave1JointDist
,
binsJointDist
,[
0
,
0.02
],[
outdir
'jointDistribution_'
cond1Str
'.eps'
]);
plotDeBiasCMEJointDistribution
(
cond2MasterSlave1JointDist
,
binsJointDist
,[
0
,
0.02
],[
outdir
'jointDistribution_'
cond2Str
'.eps'
]);
% TODO: replace master/slave1 with a relevant string (have it in the input triplet?)
plotDeBiasCMEDistribution
(
cond1MasterAccDist
,
binsDist
,
master
,[
outdir
'masterDistribution_'
cond1Str
'.eps'
]);
plotDeBiasCMEDistribution
(
cond1Slave1AccDist
,
binsDist
,
slave1
,[
outdir
'slave1Distribution_'
cond1Str
'.eps'
]);
plotDeBiasCMEDistribution
(
cond2MasterAccDist
,
binsDist
,
master
,[
outdir
'masterDistribution_'
cond2Str
'.eps'
]);
plotDeBiasCMEDistribution
(
cond2Slave1AccDist
,
binsDist
,
slave1
,[
outdir
'slave1Distribution_'
cond2Str
'.eps'
]);
%% LI as function of GI
% MasterSlave1
[
rho1_MasterSlave1
,
pval1_MasterSlave1
]
=
corr
(
LI_Cond1_MasterSlave1
',GI_Cond1_MasterSlave1'
);
[
rho2_MasterSlave1
,
pval2_MasterSlave1
]
=
corr
(
LI_Cond2_MasterSlave1
',GI_Cond2_MasterSlave1'
);
fprintf
(
sprintf
(
'MasterSlave1 LI/GI (n,m,rho,pval): %s(%d,%d,%.2f,%.5f), %s(%d,%d,%.2f,%.5f)\n'
,
...
cond1Str
,
length
(
LI_Cond1_MasterSlave1
),
nCCPs_Cond1_MasterSlave1
,
rho1_MasterSlave1
,
pval1_MasterSlave1
,
...
cond2Str
,
length
(
LI_Cond2_MasterSlave1
),
nCCPs_Cond2_MasterSlave1
,
rho2_MasterSlave1
,
pval2_MasterSlave1
));
% MasterSlave2
if
hasSlave2
[
rho1_MasterSlave2
,
pval1_MasterSlave2
]
=
corr
(
LI_Cond1_MasterSlave2
',GI_Cond1_MasterSlave2'
);
[
rho2_MasterSlave2
,
pval2_MasterSlave2
]
=
corr
(
LI_Cond2_MasterSlave2
',GI_Cond2_MasterSlave2'
);
fprintf
(
sprintf
(
'MasterSlave2 LI/GI (n,m,rho,pval): %s(%d,%d,%.2f,%.5f), %s(%d,%d,%.2f,%.5f)\n'
,
...
cond1Str
,
length
(
LI_Cond1_MasterSlave2
),
nCCPs_Cond1_MasterSlave2
,
rho1_MasterSlave2
,
pval1_MasterSlave2
,
...
cond2Str
,
length
(
LI_Cond2_MasterSlave2
),
nCCPs_Cond2_MasterSlave2
,
rho2_MasterSlave2
,
pval2_MasterSlave2
));
end
outStr
=
sprintf
(
'MasterSlave1 LI/GI (n,m,rho,pval): %s(%d,%d,%.2f,%.5f), %s(%d,%d,%.2f,%.5f)\n'
,
...
cond1Str
,
length
(
LI_Cond1_MasterSlave1
),
nCCPs_Cond1_MasterSlave1
,
rho1_MasterSlave1
,
pval1_MasterSlave1
,
...
cond2Str
,
length
(
LI_Cond2_MasterSlave1
),
nCCPs_Cond2_MasterSlave1
,
rho2_MasterSlave1
,
pval2_MasterSlave1
);
fprintf
(
outStr
);
logger
=
fopen
(
loggerFname
,
'a+'
);
fprintf
(
logger
,
outStr
);
fclose
(
logger
);
% % MasterSlave2
% if hasSlave2
% [rho1_MasterSlave2,pval1_MasterSlave2] = corr(LI_Cond1_MasterSlave2',GI_Cond1_MasterSlave2');
% [rho2_MasterSlave2,pval2_MasterSlave2] = corr(LI_Cond2_MasterSlave2',GI_Cond2_MasterSlave2');
% fprintf(sprintf('MasterSlave2 LI/GI (n,m,rho,pval): %s(%d,%d,%.2f,%.5f), %s(%d,%d,%.2f,%.5f)\n',...
% cond1Str,length(LI_Cond1_MasterSlave2),nCCPs_Cond1_MasterSlave2,rho1_MasterSlave2,pval1_MasterSlave2,...
% cond2Str,length(LI_Cond2_MasterSlave2),nCCPs_Cond2_MasterSlave2,rho2_MasterSlave2,pval2_MasterSlave2));
% end
%% Accumulate
labels
=
[
1
*
ones
(
length
(
GI_Cond1_MasterSlave1
),
1
);
2
*
ones
(
length
(
GI_Cond2_MasterSlave1
),
1
)];
% LI
featsLI_MasterSlave1
=
[
LI_Cond1_MasterSlave1
';LI_Cond2_MasterSlave1'
];
[
clsLI_MasterSlave1
,
resuberrorLI_MasterSlave1
,
nErrorsLI_MasterSlave1
,
RLI_MasterSlave1
,
normRLI_MasterSlave1
]
=
...
discreminateColocalization
(
featsLI_MasterSlave1
,
labels
,[
outdir
'LI_confusion_MasterSlave1.eps'
],
loggerFname
);
% GI + LI
featsGILI_MasterSlave1
=
[[
GI_Cond1_MasterSlave1
',LI_Cond1_MasterSlave1'
];[
GI_Cond2_MasterSlave1
',LI_Cond2_MasterSlave1'
]];
[
clsGILI_MasterSlave1
,
resuberrorGILI_MasterSlave1
,
nErrorsGILI_MasterSlave1
,
RGILI_MasterSlave1
,
normRGILI_MasterSlave1
]
=
...
discreminateColocalization
(
featsGILI_MasterSlave1
,
labels
,[
outdir
'GILI_confusion_MasterSlave1.eps'
]);
discreminateColocalization
(
featsGILI_MasterSlave1
,
labels
,[
outdir
'GILI_confusion_MasterSlave1.eps'
]
,
loggerFname
);
% CORR
featsCORR_MasterSlave1
=
[
CORR_Cond1_MasterSlave1
';CORR_Cond2_MasterSlave1'
];
[
clsCORR_MasterSlave1
,
resuberrorCORR_MasterSlave1
,
nErrorsCORR_MasterSlave1
,
RCORR_MasterSlave1
,
normRCORR_MasterSlave1
]
=
...
discreminateColocalization
(
featsCORR_MasterSlave1
,
labels
,[
outdir
'CORR_confusion_MasterSlave1.eps'
]);
if
hasSlave2
featsGILI_MasterSlave2
=
[[
GI_Cond1_MasterSlave2
',LI_Cond1_MasterSlave2'
];[
GI_Cond2_MasterSlave2
',LI_Cond2_MasterSlave2'
]];
[
clsGILI_MasterSlave2
,
resuberrorGILI_MasterSlave2
,
nErrorsGILI_MasterSlave2
,
RGILI_MasterSlave2
,
normRGILI_MasterSlave2
]
=
...
discreminateColocalization
(
featsGILI_MasterSlave2
,
labels
,[
outdir
'GILI_confusion_MasterSlave2.eps'
]);
featsCORR_MasterSlave2
=
[
CORR_Cond1_MasterSlave2
';CORR_Cond2_MasterSlave2'
];
[
clsCORR_MasterSlave2
,
resuberrorCORR_MasterSlave2
,
nErrorsCORR_MasterSlave2
,
RCORR_MasterSlave2
,
normRCORR_MasterSlave2
]
=
...
discreminateColocalization
(
featsCORR_MasterSlave2
,
labels
,[
outdir
'CORR_confusion_MasterSlave2.eps'
]);
end
discreminateColocalization
(
featsCORR_MasterSlave1
,
labels
,[
outdir
'CORR_confusion_MasterSlave1.eps'
],
loggerFname
);
% GI + CORR
featsGICORR_MasterSlave1
=
[[
GI_Cond1_MasterSlave1
',CORR_Cond1_MasterSlave1'
];[
GI_Cond2_MasterSlave1
',CORR_Cond2_MasterSlave1'
]];
[
clsGICORR_MasterSlave1
,
resuberrorGICORR_MasterSlave1
,
nErrorsGICORR_MasterSlave1
,
RGICORR_MasterSlave1
,
normGIRCORR_MasterSlave1
]
=
...
discreminateColocalization
(
featsGICORR_MasterSlave1
,
labels
,[
outdir
'GICORR_confusion_MasterSlave1.eps'
],
loggerFname
);
% if hasSlave2
% featsGILI_MasterSlave2 = [[GI_Cond1_MasterSlave2',LI_Cond1_MasterSlave2'];[GI_Cond2_MasterSlave2',LI_Cond2_MasterSlave2']];
% [clsGILI_MasterSlave2,resuberrorGILI_MasterSlave2,nErrorsGILI_MasterSlave2,RGILI_MasterSlave2,normRGILI_MasterSlave2] = ...
% discreminateColocalization(featsGILI_MasterSlave2,labels,[outdir 'GILI_confusion_MasterSlave2.eps']);
%
% featsCORR_MasterSlave2 = [CORR_Cond1_MasterSlave2';CORR_Cond2_MasterSlave2'];
% [clsCORR_MasterSlave2,resuberrorCORR_MasterSlave2,nErrorsCORR_MasterSlave2,RCORR_MasterSlave2,normRCORR_MasterSlave2] = ...
% discreminateColocalization(featsCORR_MasterSlave2,labels,[outdir 'CORR_confusion_MasterSlave2.eps']);
% end
%% LI & GI
plotGILI
(
...
...
...
@@ -123,16 +209,26 @@ plotGILI(...
[
outdir
'LIGI_MasterSlave1.eps'
]
...
);
if
hasSlave2
plotGILI
(
...
GI_Cond1_MasterSlave2
,
LI_Cond1_MasterSlave2
,
...
GI_Cond2_MasterSlave2
,
LI_Cond2_MasterSlave2
,
...
{
cond1Str
,
cond2Str
},
...
'LI'
,
...
% ylabel
clsGILI_MasterSlave2
,
...
[
outdir
'LIGI_MasterSlave2.eps'
]
...
);
end
%% CORR & GI
plotGILI
(
...
GI_Cond1_MasterSlave1
,
CORR_Cond1_MasterSlave1
,
...
GI_Cond2_MasterSlave1
,
CORR_Cond2_MasterSlave1
,
...
{
cond1Str
,
cond2Str
},
...
'CORR'
,
...
% ylabel
clsGICORR_MasterSlave1
,
...
[
outdir
'CORRGI_MasterSlave1.eps'
]
...
);
% if hasSlave2
% plotGILI(...
% GI_Cond1_MasterSlave2,LI_Cond1_MasterSlave2,...
% GI_Cond2_MasterSlave2,LI_Cond2_MasterSlave2,...
% {cond1Str,cond2Str},...
% 'LI',... % ylabel
% clsGILI_MasterSlave2,...
% [outdir 'LIGI_MasterSlave2.eps']...
% );
% end
%%
...
...
@@ -140,8 +236,15 @@ end
if
params
.
doStstisticalTest
pGILI_MasterSlave1
=
permutationTestCLS
(
featsGILI_MasterSlave1
,
labels
);
pCorr_MasterSlave1
=
permutationTestCLS
(
featsCORR_MasterSlave1
,
labels
);
fprintf
(
sprintf
(
'MasterSlave1: pval(GI,LI) = %f\n'
,
pGILI_MasterSlave1
));
fprintf
(
sprintf
(
'MasterSlave1: CORR pval = %f\n'
,
pCorr_MasterSlave1
));
outStr1
=
sprintf
(
'MasterSlave1: pval(GI,LI) = %f\n'
,
pGILI_MasterSlave1
);
outStr2
=
sprintf
(
'MasterSlave1: CORR pval = %f\n'
,
pCorr_MasterSlave1
);
fprintf
(
outStr1
);
fprintf
(
outStr2
);
logger
=
fopen
(
loggerFname
,
'a+'
);
fprintf
(
logger
,[
outStr1
,
outStr2
]);
fclose
(
logger
);
if
hasSlave2
pGILI_MasterSlave2
=
permutationTestCLS
(
featsGILI_MasterSlave2
,
labels
);
...
...
@@ -151,11 +254,36 @@ if params.doStstisticalTest
end
end
% TODO: move as an external parameter / flag
params
.
doCompareClassifiers
=
true
;
if
params
.
doCompareClassifiers
% New
[
aucGILI
,
aucLI
]
=
rocClsDeBias
(
clsGILI_MasterSlave1
,
clsLI_MasterSlave1
,
featsGILI_MasterSlave1
,
featsLI_MasterSlave1
,
labels
,[
outdir
'ROC_LI.eps'
]);
% [aucGIMI,aucMI] = rocClsDeBias(clsGIMI_MasterSlave1,clsMI_MasterSlave1,featsGIMI_MasterSlave1,featsMI_MasterSlave1,labels,[outdir 'ROC_MI.eps']);
[
aucGICORR
,
aucCORR
]
=
rocClsDeBias
(
clsGICORR_MasterSlave1
,
clsCORR_MasterSlave1
,
featsGICORR_MasterSlave1
,
featsCORR_MasterSlave1
,
labels
,[
outdir
'ROC_CORR.eps'
]);
outStr1
=
sprintf
(
'LI AUC = %.2f vs. %.2f\n'
,
aucGILI
,
aucLI
);
fprintf
(
outStr1
);
% fprintf(sprintf('MI = %.2f vs. %.2f\n',aucGIMI,aucMI));
outStr2
=
sprintf
(
'CORR AUC = %.2f vs. %.2f\n'
,
aucGICORR
,
aucCORR
);
fprintf
(
outStr2
);
% save([outdir 'compareClassifiers.mat'],...
% 'pFailLI','pFailEqLI','accuracyGILI','accuracyLI',...
% 'pFailCORR','pFailEqCORR','accuracyGICORR','accuracyCORR');
% % save([outdir 'compareClassifiers.mat'],'pFailLI','pFailEqLI','accuracyGILI','accuracyLI','pFailMI','pFailEqMI','accuracyGIMI','accuracyMI','pFailCORR','pFailEqCORR','accuracyGICORR','accuracyCORR');
logger
=
fopen
(
loggerFname
,
'a+'
);
fprintf
(
logger
,
outStr1
);
fprintf
(
logger
,
outStr2
);
fclose
(
logger
);
end
end
%% Utility functions
function
[
cls
,
resuberror
,
nErrors
,
R
,
normR
]
=
discreminateColocalization
(
feats
,
labels
,
outfile
)
function
[
cls
,
resuberror
,
nErrors
,
R
,
normR
]
=
discreminateColocalization
(
feats
,
labels
,
outfile
,
loggerFname
)
cls
=
fitcdiscr
(
feats
,
labels
);
resuberror
=
resubLoss
(
cls
);
nErrors
=
resuberror
*
cls
.
NumObservations
;
...
...
@@ -164,7 +292,11 @@ normR = R ./ repmat(sum(R,2),1,2);
nLabels
=
length
(
unique
(
labels
));
fprintf
(
sprintf
(
'%s: %.2f\n'
,
outfile
,
resuberror
));
outStr
=
sprintf
(
'%s: %.2f\n'
,
outfile
,
resuberror
);
fprintf
(
outStr
);
logger
=
fopen
(
loggerFname
,
'a+'
);
fprintf
(
logger
,
outStr
);
fclose
(
logger
);
h
=
figure
;
imagesc
(
normR
);
...
...
@@ -218,7 +350,7 @@ if strcmp(ylabelStr,'LI')
ylim
([
minLI
,
maxLI
]);
end
legend
(
legendsStr
{
1
},
legendsStr
{
2
}
,
'FontSize'
,
24
);
legend
(
legendsStr
{
1
},
legendsStr
{
2
});
xlabel
(
'GI'
,
'FontSize'
,
fontsize
);
ylabel
(
ylabelStr
,
'FontSize'
,
fontsize
);
haxes
=
get
(
h
,
'CurrentAxes'
);
...
...
code/DeBiasCmeCond1Cond2.m~
0 → 100644
View file @
5b7c5476
function [] = DeBiasCmeCond1Cond2(baseDirname,masterSlaves,params,cond1Str,cond2Str)
close all;
dirnameCond1 = [baseDirname filesep cond1Str];
dirnameCond2 = [baseDirname filesep cond2Str];
if ~exist(dirnameCond1,'dir')
error([dirnameCond1 'does not exists!']);
end
if ~exist(dirnameCond2,'dir')
error([dirnameCond2 'does not exists!']);
end
master = masterSlaves{1};
slave1 = masterSlaves{2};
slave2 = masterSlaves{3};
%% Set parameters
manualAnnotateROIMain(dirnameCond1,params.doAnnotate,master,slave1,slave2);
manualAnnotateROIMain(dirnameCond2,params.doAnnotate,master,slave1,slave2);
close all;
doColocalizationDirectories(dirnameCond1,params,master,slave1,slave2); % TODO: implement MI, add flag for multiple measures
doColocalizationDirectories(dirnameCond2,params,master,slave1,slave2);
if params.doMetaAnalysis
metaAnalysisDeBiasCMECond1Cond2(baseDirname,cond1Str,cond2Str,params,master,slave1,slave2);
end
end
%% Meta analysis: 2 conditions
% TODO: (1) implement slave2, (2)
function [] = metaAnalysisDeBiasCMECond1Cond2(baseDirname,cond1Str,cond2Str,params,master,slave1,slave2)
close all;
hasSlave2 = ~isempty(slave2);
addpath(genpath('/home2/azaritsky/code/DeBiasUtils'));
addpath(genpath('/home2/azaritsky/code/extern/export_fig'));
%% Input
dirnameCond1 = [baseDirname filesep cond1Str];
dirnameCond2 = [baseDirname filesep cond2Str];
%% MasterSlave1
% Cond1
load([dirnameCond1 filesep 'out.mat']);
GI_Cond1_MasterSlave1 = GIsMasterSlave1(GIsMasterSlave1<7);
LI_Cond1_MasterSlave1 = LIsMasterSlave1(GIsMasterSlave1<7);
CORR_Cond1_MasterSlave1 = CORRsMasterSlave1(GIsMasterSlave1<7);
nCCPs_Cond1_MasterSlave1 = nCCPs;
nCells_Cond1_MasterSlave1 = nCells;
% 201604
cond1MasterDists{1} = masterDist; % Do we need the {1}? see getAccDistributions function
cond1Slave1Dists{1} = slave1Dist;
cond1MasterSlave1JointDists{1} = jointDistMasterSlave1;
% Cond2
load([dirnameCond2 filesep 'out.mat']);
GI_Cond2_MasterSlave1 = GIsMasterSlave1(GIsMasterSlave1<7);
LI_Cond2_MasterSlave1 = LIsMasterSlave1(GIsMasterSlave1<7);
CORR_Cond2_MasterSlave1 = CORRsMasterSlave1(GIsMasterSlave1<7);
nCCPs_Cond2_MasterSlave1 = nCCPs;
nCells_Cond2_MasterSlave1 = nCells;
% 201604
cond2MasterDists{1} = masterDist;
cond2Slave1Dists{1} = slave1Dist;
cond2MasterSlave1JointDists{1} = jointDistMasterSlave1;
%% MasterSlave2
if hasSlave2
load([dirnameCond1 filesep 'out.mat']);
GI_Cond1_MasterSlave2 = GIsMasterSlave2(GIsMasterSlave2<7);
LI_Cond1_MasterSlave2 = LIsMasterSlave2(GIsMasterSlave2<7);
CORR_Cond1_MasterSlave2 = CORRsMasterSlave2(GIsMasterSlave2<7);
nCCPs_Cond1_MasterSlave2 = nCCPs;
% 201604
cond1Slave2Dists{1} = slave2Dist;
cond1MasterSlave2JointDists{1} = jointDistMasterSlave2;
load([dirnameCond2 filesep 'out.mat']);
GI_Cond2_MasterSlave2 = GIsMasterSlave2(GIsMasterSlave2<7);
LI_Cond2_MasterSlave2 = LIsMasterSlave2(GIsMasterSlave2<7);
CORR_Cond2_MasterSlave2 = CORRsMasterSlave2(GIsMasterSlave2<7);
nCCPs_Cond2_MasterSlave2 = nCCPs;
% 201604
cond2Slave2Dists{1} = slave2Dist;
cond2MasterSlave2JointDists{1} = jointDistMasterSlave2;
end
%% Output
outdir = baseDirname;
loggerFname = [outdir 'log.txt'];
%%
if hasSlave2
error('No implementation of MetaAnalysis for 3 channels - contact Assaf (assafzar@gmail.com) for such an implementation');
end
%% 201604: new analysis : calculate cumulative distributions, look at p-value of GI!
outStr1 = sprintf('\n *** %s - %s ***\n',cond1Str,cond2Str);
outStr2 = sprintf('GI pval = %f (%f vs. %f)\n',ranksum(GI_Cond1_MasterSlave1,GI_Cond2_MasterSlave1),...
mean(GI_Cond1_MasterSlave1),mean(GI_Cond2_MasterSlave1));
outStr3 = sprintf('LI pval = %f (%f vs. %f)\n',ranksum(LI_Cond1_MasterSlave1,LI_Cond2_MasterSlave1),...
mean(LI_Cond1_MasterSlave1),mean(LI_Cond2_MasterSlave1));
outStr4 = sprintf('RHO pval = %f (%f vs. %f)\n',ranksum(CORR_Cond1_MasterSlave1,CORR_Cond2_MasterSlave1),...
mean(CORR_Cond1_MasterSlave1),mean(CORR_Cond2_MasterSlave1));
fprintf(outStr1);
fprintf(outStr2);
fprintf(outStr3);
fprintf(outStr4);
outStr = [outStr1 outStr2 outStr3 outStr4];
logger = fopen(loggerFname,'a+');
fprintf(logger,outStr);
fclose(logger);
[cond1MasterAccDist,cond1Slave1AccDist,cond1MasterSlave1JointDist] = getAccDistributions(cond1MasterDists,cond1Slave1Dists,cond1MasterSlave1JointDists);
[cond2MasterAccDist,cond2Slave1AccDist,cond2MasterSlave1JointDist] = getAccDistributions(cond2MasterDists,cond2Slave1Dists,cond2MasterSlave1JointDists);
% fontsize = 22;
plotDeBiasCMEJointDistribution(cond1MasterSlave1JointDist,binsJointDist,[0,0.02],[outdir 'jointDistribution_' cond1Str '.eps']);
plotDeBiasCMEJointDistribution(cond2MasterSlave1JointDist,binsJointDist,[0,0.02],[outdir 'jointDistribution_' cond2Str '.eps']);
% TODO: replace master/slave1 with a relevant string (have it in the input triplet?)
plotDeBiasCMEDistribution(cond1MasterAccDist,binsDist,master,[outdir 'masterDistribution_' cond1Str '.eps']);
plotDeBiasCMEDistribution(cond1Slave1AccDist,binsDist,slave1,[outdir 'slave1Distribution_' cond2Str '.eps']);
plotDeBiasCMEDistribution(cond2MasterAccDist,binsDist,master,[outdir 'masterDistribution_' cond1Str '.eps']);
plotDeBiasCMEDistribution(cond2Slave1AccDist,binsDist,slave1,[outdir 'slave1Distribution_' cond2Str '.eps']);
%% LI as function of GI
% MasterSlave1
[rho1_MasterSlave1,pval1_MasterSlave1] = corr(LI_Cond1_MasterSlave1',GI_Cond1_MasterSlave1');
[rho2_MasterSlave1,pval2_MasterSlave1] = corr(LI_Cond2_MasterSlave1',GI_Cond2_MasterSlave1');
outStr = sprintf('MasterSlave1 LI/GI (n,m,rho,pval): %s(%d,%d,%.2f,%.5f), %s(%d,%d,%.2f,%.5f)\n',...
cond1Str,length(LI_Cond1_MasterSlave1),nCCPs_Cond1_MasterSlave1,rho1_MasterSlave1,pval1_MasterSlave1,...
cond2Str,length(LI_Cond2_MasterSlave1),nCCPs_Cond2_MasterSlave1,rho2_MasterSlave1,pval2_MasterSlave1);
fprintf(outStr);
logger = fopen(loggerFname,'a+');
fprintf(logger,outStr);
fclose(logger);
% % MasterSlave2
% if hasSlave2
% [rho1_MasterSlave2,pval1_MasterSlave2] = corr(LI_Cond1_MasterSlave2',GI_Cond1_MasterSlave2');
% [rho2_MasterSlave2,pval2_MasterSlave2] = corr(LI_Cond2_MasterSlave2',GI_Cond2_MasterSlave2');
% fprintf(sprintf('MasterSlave2 LI/GI (n,m,rho,pval): %s(%d,%d,%.2f,%.5f), %s(%d,%d,%.2f,%.5f)\n',...
% cond1Str,length(LI_Cond1_MasterSlave2),nCCPs_Cond1_MasterSlave2,rho1_MasterSlave2,pval1_MasterSlave2,...
% cond2Str,length(LI_Cond2_MasterSlave2),nCCPs_Cond2_MasterSlave2,rho2_MasterSlave2,pval2_MasterSlave2));
% end
%% Accumulate
labels = [1*ones(length(GI_Cond1_MasterSlave1),1);2*ones(length(GI_Cond2_MasterSlave1),1)];
% LI
featsLI_MasterSlave1 = [LI_Cond1_MasterSlave1';LI_Cond2_MasterSlave1'];
[clsLI_MasterSlave1,resuberrorLI_MasterSlave1,nErrorsLI_MasterSlave1,RLI_MasterSlave1,normRLI_MasterSlave1] = ...
discreminateColocalization(featsLI_MasterSlave1,labels,[outdir 'LI_confusion_MasterSlave1.eps']);
% GI + LI
featsGILI_MasterSlave1 = [[GI_Cond1_MasterSlave1',LI_Cond1_MasterSlave1'];[GI_Cond2_MasterSlave1',LI_Cond2_MasterSlave1']];
[clsGILI_MasterSlave1,resuberrorGILI_MasterSlave1,nErrorsGILI_MasterSlave1,RGILI_MasterSlave1,normRGILI_MasterSlave1] = ...
discreminateColocalization(featsGILI_MasterSlave1,labels,[outdir 'GILI_confusion_MasterSlave1.eps']);
% CORR
featsCORR_MasterSlave1 = [CORR_Cond1_MasterSlave1';CORR_Cond2_MasterSlave1'];
[clsCORR_MasterSlave1,resuberrorCORR_MasterSlave1,nErrorsCORR_MasterSlave1,RCORR_MasterSlave1,normRCORR_MasterSlave1] = ...
discreminateColocalization(featsCORR_MasterSlave1,labels,[outdir 'CORR_confusion_MasterSlave1.eps']);
% GI + CORR
featsGICORR_MasterSlave1 = [[GI_Cond1_MasterSlave1',CORR_Cond1_MasterSlave1'];[GI_Cond2_MasterSlave1',CORR_Cond2_MasterSlave1']];
[clsGICORR_MasterSlave1,resuberrorGICORR_MasterSlave1,nErrorsGICORR_MasterSlave1,RGICORR_MasterSlave1,normGIRCORR_MasterSlave1] = ...
discreminateColocalization(featsGICORR_MasterSlave1,labels,[outdir 'GICORR_confusion_MasterSlave1.eps']);
% if hasSlave2
% featsGILI_MasterSlave2 = [[GI_Cond1_MasterSlave2',LI_Cond1_MasterSlave2'];[GI_Cond2_MasterSlave2',LI_Cond2_MasterSlave2']];
% [clsGILI_MasterSlave2,resuberrorGILI_MasterSlave2,nErrorsGILI_MasterSlave2,RGILI_MasterSlave2,normRGILI_MasterSlave2] = ...
% discreminateColocalization(featsGILI_MasterSlave2,labels,[outdir 'GILI_confusion_MasterSlave2.eps']);
%
% featsCORR_MasterSlave2 = [CORR_Cond1_MasterSlave2';CORR_Cond2_MasterSlave2'];
% [clsCORR_MasterSlave2,resuberrorCORR_MasterSlave2,nErrorsCORR_MasterSlave2,RCORR_MasterSlave2,normRCORR_MasterSlave2] = ...
% discreminateColocalization(featsCORR_MasterSlave2,labels,[outdir 'CORR_confusion_MasterSlave2.eps']);
% end
%% LI & GI
plotGILI(...
GI_Cond1_MasterSlave1,LI_Cond1_MasterSlave1,...
GI_Cond2_MasterSlave1,LI_Cond2_MasterSlave1,...
{cond1Str,cond2Str},...
'LI',... % ylabel
clsGILI_MasterSlave1,...
[outdir 'LIGI_MasterSlave1.eps']...
);
%% CORR & GI
plotGILI(...
GI_Cond1_MasterSlave1,CORR_Cond1_MasterSlave1,...
GI_Cond2_MasterSlave1,CORR_Cond2_MasterSlave1,...
{cond1Str,cond2Str},...
'CORR',... % ylabel
clsGICORR_MasterSlave1,...
[outdir 'CORRGI_MasterSlave1.eps']...
);
% if hasSlave2
% plotGILI(...
% GI_Cond1_MasterSlave2,LI_Cond1_MasterSlave2,...
% GI_Cond2_MasterSlave2,LI_Cond2_MasterSlave2,...
% {cond1Str,cond2Str},...
% 'LI',... % ylabel
% clsGILI_MasterSlave2,...
% [outdir 'LIGI_MasterSlave2.eps']...
% );
% end
%%
%% statistics
if params.doStstisticalTest
pGILI_MasterSlave1 = permutationTestCLS(featsGILI_MasterSlave1,labels);
pCorr_MasterSlave1 = permutationTestCLS(featsCORR_MasterSlave1,labels);
outStr1 = sprintf('MasterSlave1: pval(GI,LI) = %f\n',pGILI_MasterSlave1);
outStr2 = sprintf('MasterSlave1: CORR pval = %f\n',pCorr_MasterSlave1);
fprintf(outStr1);
fprintf(outStr2);
logger = fopen(loggerFname,'a+');
fprintf(logger,[outStr1,outStr2]);
fclose(logger);
if hasSlave2
pGILI_MasterSlave2 = permutationTestCLS(featsGILI_MasterSlave2,labels);
pCorr_MasterSlave2 = permutationTestCLS(featsCORR_MasterSlave2,labels);
fprintf(sprintf('MasterSlave2: pval(GI,LI) = %f\n',pGILI_MasterSlave2));
fprintf(sprintf('MasterSlave2: CORR pval = %f\n',pCorr_MasterSlave2));
end
end
% TODO: move as an external parameter / flag
params.doCompareClassifiers = true;
if params.doCompareClassifiers
% New
[aucGILI,aucLI] = rocClsDeBias(clsGILI_MasterSlave1,clsLI_MasterSlave1,featsGILI_MasterSlave1,featsLI_MasterSlave1,labels,[outdir 'ROC_LI.eps']);
% [aucGIMI,aucMI] = rocClsDeBias(clsGIMI_MasterSlave1,clsMI_MasterSlave1,featsGIMI_MasterSlave1,featsMI_MasterSlave1,labels,[outdir 'ROC_MI.eps']);
[aucGICORR,aucCORR] = rocClsDeBias(clsGICORR_MasterSlave1,clsCORR_MasterSlave1,featsGICORR_MasterSlave1,featsCORR_MasterSlave1,labels,[outdir 'ROC_CORR.eps']);
outStr1 = sprintf('LI AUC = %.2f vs. %.2f\n',aucGILI,aucLI);
fprintf(outStr1);
% fprintf(sprintf('MI = %.2f vs. %.2f\n',aucGIMI,aucMI));
outStr2 = sprintf('CORR AUC = %.2f vs. %.2f\n',aucGICORR,aucCORR);
fprintf(outStr2);
% save([outdir 'compareClassifiers.mat'],...
% 'pFailLI','pFailEqLI','accuracyGILI','accuracyLI',...
% 'pFailCORR','pFailEqCORR','accuracyGICORR','accuracyCORR');
% % save([outdir 'compareClassifiers.mat'],'pFailLI','pFailEqLI','accuracyGILI','accuracyLI','pFailMI','pFailEqMI','accuracyGIMI','accuracyMI','pFailCORR','pFailEqCORR','accuracyGICORR','accuracyCORR');
logger = fopen(loggerFname,'a+');
fprintf(logger,outStr1);
fprintf(logger,outStr2);
fclose(logger);
end
end
%% Utility functions
function [cls,resuberror,nErrors,R,normR] = discreminateColocalization(feats,labels,outfile,logger)
cls = fitcdiscr(feats,labels);
resuberror = resubLoss(cls);
nErrors = resuberror * cls.NumObservations;
R = confusionmat(cls.Y,resubPredict(cls));
normR = R ./ repmat(sum(R,2),1,2);
nLabels = length(unique(labels));
fprintf(sprintf('%s: %.2f\n',outfile,resuberror));
h = figure;
imagesc(normR);
hold on;
haxes = findobj(h,'type','axes');
set(haxes,'XTick',1:nLabels);
set(haxes,'YTick',1:nLabels);
% set(haxes,'XTickLabel',kdStrings);
% set(get(gca,'xlabel'),'Rotation',45);
% set(haxes,'YTickLabel',kdStrings);
set(haxes,'FontSize',24);
caxis([0,1]);
colormap jet;
set(h,'Color','w');
hold off;
export_fig(outfile);
end
%%