-
Notifications
You must be signed in to change notification settings - Fork 0
/
NoGOA_NtNEC.m
223 lines (191 loc) · 6.43 KB
/
NoGOA_NtNEC.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
function [] = NoGOA_NtNEC( dataseth,datasetr,ECs,goObj,GOs)
% 此处显示详细说明
fprintf('start %s at %s\n,==Method:%s==',dataseth, datestr(now),'NoisyGOA_NtN+EC');
load(dataseth);
load(datasetr);
load(ECs);
% datapath=[pwd,filesep,'results3',filesep];%pwd is the current work directory
% addpath(datapath);
selGOs=GOs;
size_go=length(selGOs);
% if size_go==3739
if size_go==3765
gnd1=hGO.ccLabels;
gnd2=rGO.ccLabels;
gnd3=hGO.ccECs;
EC=ECs.ccECs;
rootGO=5575; %ccroot
end
% if size_go==10031
if size_go==9878
gnd1=hGO.mfLabels;
gnd2=rGO.mfLabels;
gnd3=hGO.mfECs;
EC=ECs.mfECs;
rootGO=3674; %mfroot
end
% if size_go==25954
if size_go==27342
gnd1=hGO.bpLabels;
gnd2=rGO.bpLabels;
gnd3=hGO.bpECs;
EC=ECs.bpECs;
rootGO=8150; %bproot
end
gnd_h=full(gnd1);
gnd_r=full(gnd2);
gnd_hec=gnd3;
%only test on annotated proteins
index=find(sum(gnd_h,2)==0);
gnd_h(index,:)=[];
gnd_r(index,:)=[];
gnd_hec(index,:)=[];
[~,Nfun]=size(gnd_h);
minT=1;% the minimum size of member proteins
% maxT=300;
fun_stat_h=sum(gnd_h,1);
fun_stat_r=sum(gnd_r,1);
sel_funh_idx=find(fun_stat_h>=minT);
sel_funr_idx=find(fun_stat_r>=minT);
sel_fun_idx=union(sel_funh_idx,sel_funr_idx);
% sel_fun_idx=intersect(sel_funh_idx,sel_funr_idx);
selGOs=GOs(sel_fun_idx);
gndh=gnd_h(:,sel_fun_idx);
[Ndata, Nfun]=size(gndh);
rootidx=getGOIdx(rootGO,selGOs);
gnd_r=gnd_r(:,sel_fun_idx);
gnd_h=gnd_h(:,sel_fun_idx);
gnd_hec=gnd_hec(:,sel_fun_idx);
num_perprotein_noise=zeros(Ndata,1); %the number of noisy annotations of each protein
gnd=gnd_r-gnd_h;
sub_goObj=getSelGoObj(selGOs,goObj);%filter the goObj to speedup computation
% DirectchildGOs=getDirectChildGOs(selGOs, selGOs,sub_goObj);
childGOs=getChildGOs(selGOs, selGOs,sub_goObj);
% DirectparGOs=getDirectParentGOs(selGOs, selGOs,sub_goObj);
Depth = getSelGOsDepth(selGOs,sub_goObj, rootGO);
parGOs=getParentGOs(selGOs, selGOs,sub_goObj);
%% count the number of noisy annotations
for ii=1:Ndata
idx=find(gnd(ii,:)==-1);
noiseidx{ii}=idx;
num_perprotein_noise(ii)=length(idx);
end
%% Identifying Noisy Gene Ontology Annotations
[gnd_hw1] = EvidenceCode1(gnd_h, gnd_hec, selGOs, Ndata, parGOs, percentage);
[gnd_hw] = NtN(gnd_h, selGOs, childGOs, Depth ) ; %加权
k=round(Nfun*0.5);
[U,S,V] = svd(gnd_hw); %返回一个与X 同大小的对角矩阵S,两个酉矩阵U 和V,
Sk=S(1:k,1:k);
Uk=U(:,1:k);
Vk=V(1:k,:);
newgnd=Uk*Sk*Vk;
% newgnd=a*newgnd+(1-a)*gnd_hw1;
Idx=find(gnd_h==0);
newgnd(Idx)=0;
% dt=sum(newgnd,2);
% idx_dt = (dt>eps);
% dt(idx_dt) = 1./dt(idx_dt);
% newgnd=diag(dt)*newgnd;
% newgnd2=zeros(Ndata,Nfun);
% for ii=1:Ndata
% newgnd2(ii,:)= TPR_DAG(newgnd(ii,:),gnd_h(ii,:),DirectchildGOs,DirectparGOs,selGOs,rootidx);
% end
% % %
% newgnd=newgnd2;
% newgnd=newgnd+gnd_h;
newgnd=1./newgnd;
newgnd(newgnd>=inf&newgnd<=inf)=0;
[value,ind]=sort(newgnd,2,'descend');
newgnd2=gnd_h;
for ii=1:Ndata
Idx=find(newgnd2(ii,:)>0);
noise=ind(ii,1:num_perprotein_noise(ii));
childnoise=childGOs(noise);
newgnd2(ii,noise)=0;
for jj=1:length(childnoise)
childidxp=getGOIdx(childnoise{jj},selGOs);
childIdx=intersect(childidxp,Idx);
newgnd2(ii,childIdx)=0;
end
end
%% compute precision, recall and f1-measure
Y=gnd_r;
Z =newgnd2(1:Ndata,:);
% ratio=0.8;
% time=500;
% data=length(find(num_perprotein_noise>0));
% selNdata=round(Ndata*ratio);
% per_truePositive=zeros(time,selNdata);
% per_precision=zeros(time,selNdata);
% per_recall=zeros(time,selNdata);
% per_F1score=zeros(time,selNdata);
% for run=1:time
% sortprotein=randperm(Ndata);
% protein_idx=sortprotein(1:selNdata);
% rangnd_h=gnd_h(protein_idx,:);
% ranY=Y(protein_idx,:);
% ranZ=Z(protein_idx,:);
% [tp,per_pre,per_re,per_f1]=PRF(rangnd_h,ranY,ranZ);
% per_truePositive(run,:)=tp;
% per_precision(run,:)=per_pre;
% per_recall(run,:)=per_re;
% per_F1score(run,:)=per_f1;
% end
% ave_truePositive=sum(per_precision,2)/data;
% ave_precision=sum(per_precision,2)/data;
% ave_recall=sum(per_precision,2)/data;
% ave_fvalue=sum(per_F1score,2)/data;
%
% truePositives=sum(ave_truePositive)/time;
% precisions=sum(ave_precision)/time;
% recalls=sum(ave_recall)/time;
% fvalue=sum(ave_fvalue)/time;
[tp,per_pre,per_re,per_f1,Miprecisions,Mirecall,num_candidate]=PRF1(gnd_h,Y,Z);
data=length(find(num_perprotein_noise>0));
[maprecisions,marecalls,mafvalue,miprecisions,mirecalls,mifvalue,ave_maprecision,ave_marecall,ave_mafvalue,ave_miprecision,ave_mirecall,ave_mifvalue]=bootstrapping(tp,per_pre,per_re,per_f1,num_candidate,num_perprotein_noise);
prec_seq='tp,per_pre,per_re,per_f1,Macropre,Macrore,Macrof1,Maprecisions,Marecall,Maf1,Miprecisions,Mirecall,Mif1,maprecisions,marecalls,mafvalue,miprecisions,mirecalls,mifvalue,ave_maprecision,ave_marecall,ave_mafvalue,ave_miprecision,ave_mirecall,ave_mifvalue,num_perprotein_noise,num_candidate';
precision=cell(30,1);
precision{1}=tp;
precision{2}=per_pre;
precision{3}=per_re;
precision{4}=per_f1;
precision{5}=sum(per_pre)/data;
precision{6}=sum(per_re)/data;
precision{7}=sum(per_f1)/data;
precision{8}=Miprecisions;
precision{9}=Mirecall;
precision{10}=2*Miprecisions*Mirecall/(Miprecisions+Mirecall);
precision{11}=maprecisions;
precision{12}=marecalls;
precision{13}=mafvalue;
precision{14}=miprecisions;
precision{15}=mirecalls;
precision{16}=mifvalue;
precision{17}=ave_maprecision;
precision{18}=ave_marecall;
precision{19}=ave_mafvalue;
precision{20}=ave_miprecision;
precision{21}=ave_mirecall;
precision{22}=ave_mifvalue;
precision{23}=num_perprotein_noise;
precision{24}=num_candidate;
%
stds=cell(30,1);
stds{11}=std(ave_maprecision,0,1);
stds{12}=std(ave_marecall,0,1);
stds{13}=std(ave_mafvalue,0,1);
stds{14}=std(ave_miprecision,0,1);
stds{15}=std(ave_mirecall,0,1);
stds{16}=std(ave_mifvalue,0,1);
if rootGO==5575
evalstr=['save resultsinternot1605070922',filesep,dataseth, '_NoisyGOA_NtN+EC_hr_cc_new.mat precision stds prec_seq'];
end
if rootGO==3674
evalstr=['save resultsinternot1605070922',filesep,dataseth, '_NoisyGOA_NtN+EC_hr_mf_new.mat precision stds prec_seq'];
end
if rootGO==8150
evalstr=['save resultsinternot1605070922',filesep,dataseth, '_NoisyGOA_NtN+EC_hr_bp_new.mat precision stds prec_seq'];
end
eval(evalstr);
fprintf('\n =====finish NoisyGOA_SP_hr time=%s\n',datestr(now));
end