forked from jduffield65/iss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
quality_threshold.m
53 lines (47 loc) · 2.55 KB
/
quality_threshold.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
function QualOK = quality_threshold(o,Method)
% QualOK = o.quality_threshold
% quick function that returns a binary saying which spots are above quality
% threshold
%Method = 'DotProduct','Prob' or 'Pixel' to consider gene assignments given
%by o.SpotCodeNo, o.pSpotCodeNo and o.pxSpotCodeNo respectively.
if nargin<2 || isempty(Method)
Method = 'DotProduct';
end
if ~ismember({Method},o.CallMethods)
error('Method invalid, must be member of o.CallMethods.');
end
pf = o.CallMethodPrefix(Method);
if strcmpi('Prob',Method) || strcmpi('Pixel',Method) || strcmpi('GroundTruth',Method)
% QualOK = (o.([pf,'SpotScore'])>o.pScoreThresh & o.([pf,'SpotIntensity'])>o.pIntensityThresh2 | ...
% o.([pf,'SpotScore'])>o.pScoreThresh2 & o.([pf,'SpotScore'])+o.([pf,'LogProbOverBackground'])>o.pLogProbThresh2 &...
% o.([pf,'SpotIntensity'])>o.pIntensityThresh);
% QualOK = QualOK & o.([pf,'SpotScore'])>=0; %3rd best spots do more harm than good.
%QualOK = QualOK & o.pSpotIntensity2 > o.pIntensity2Thresh;
QualOK = o.([pf,'SpotScore'])>0 & o.([pf,'LogProbOverBackground'])+o.pQualParam1*o.([pf,'SpotScore'])>o.pQualThresh1 | ...
o.([pf,'SpotScore'])==0 & o.([pf,'LogProbOverBackground'])+o.pQualParam2*o.([pf,'SpotScore'])>o.pQualThresh2 | ...
o.([pf,'SpotScore'])<0 & o.([pf,'LogProbOverBackground'])>o.pQualThresh3 & o.([pf,'SpotScore'])>o.pQualThresh4;
elseif strcmpi('DotProduct',Method)
QualOK = o.([pf,'SpotCombi']) & o.([pf,'SpotScore'])>o.CombiQualThresh &...
o.([pf,'SpotIntensity'])>o.CombiIntensityThresh & o.([pf,'SpotScoreDev'])>o.CombiDevThresh;
elseif strcmpi('OMP',Method)
%Old method below
%QualOK = o.ompNeighbNonZeros>o.ompNeighbThresh | (o.ompSpotIntensity>o.ompIntensityThresh & o.ompNeighbNonZeros>o.ompNeighbThresh2);
%QualOK = QualOK & o.ompSpotIntensity2 > o.ompIntensity2Thresh;
%New method, found using PyTorch
QualOK = o.([pf,'NeighbNonZeros'])>o.ompNeighbThresh | o.([pf,'SpotIntensity'])>o.ompIntensityThresh |...
o.([pf,'SpotScore'])>o.ompScoreThresh;
elseif strcmpi('Spatial',Method)
QualOK = o.([pf,'SpotScore'])>0; %All spots at the moment.
else
%If new method, just accept everything
QualOK = o.([pf,'SpotCodeNo'])>0;
end
% % HACK ALERT
% QualOK = QualOK & o.cSpotIsolated;
% nCombiCodes = sum(~strcmp(o.CharCodes, 'EXTRA'));
%
% % now extras - they have their own thresholds, set manually for each type
% for i=1:size(o.ExtraCodes,1)
% MySpots = (o.SpotCodeNo == nCombiCodes+i);
% QualOK(MySpots) = o.SpotIntensity(MySpots)>o.ExtraCodes{i,4};
% end