forked from cansyl/HPO2GO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHPO2GO_Source_Code.m
1163 lines (1000 loc) · 62.3 KB
/
HPO2GO_Source_Code.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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% HPO2GO v1.1
%
% Mapping between Human Phenotype Ontology (HPO) and Gene Ontology (GO)
% terms for the prediction of gene/protein - function - phenotype - disease
% associations.
%
% ------------------------------------------------------------------------
%
% HPO2GO: Prediction of Human Phenotype Ontology Term Associations with
% Cross Ontology Annotation Co-occurrences
%
% Author: Tunca Dogan1,2,3,*
%
% 1 Cancer Systems Biology Laboratory (CanSyL), Graduate School of
% Informatics, METU, Ankara, 06800, Turkey
% 2 Department of Health Informatics, Graduate School of Informatics, METU,
% Ankara, 06800, Turkey
% 3 European Molecular Biology Laboratory, European Bioinformatics
% Institute (EMBL-EBI), Hinxton, Cambridge, CB10 1SD, UK
%
% ------------------------------------------------------------------------
%
% Copyright (C) 2018 CanSyL
%
% This program is free software: you can redistribute it and/or modify it
% under the terms of the GNU General Public License as published by the
% Free Software Foundation, either version 3 of the License, or (at your
% option) any later version.
%
% This program is distributed in the hope that it will be useful, but
% WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
% Public License for more details.
%
% You should have received a copy of the GNU General Public License along
% with this program. If not, see http://www.gnu.org/licenses/.
%
% ------------------------------------------------------------------------
%
%
%
% ----------------------------------
% Source Code of the Whole Analysis
% ----------------------------------
% Loading HPO annotation data:
[HPO_gene_id,HPO_gene_symbol,HPO_Name,HPO_ID]=textread('HPO_gene_to_phenotype_annotation_01_2017_ALL_SOURCES_ALL_FREQUENCIES.txt', '%s %s %s %s', 'delimiter', '\t','headerlines',1);
HPO_gene_annotation=[HPO_gene_id HPO_gene_symbol HPO_Name HPO_ID];
HPO_gene_annotation=uniqueRowsCA(HPO_gene_annotation);
save HPO2GO_Files/HPO_test_HPO_gene_annotation.mat HPO_gene_annotation -v7
HPO_gene_symbol_unique=unique(HPO_gene_annotation(:,2));
dlmcell('HPO2GO_Files/HPO_gene_symbol_unique.txt',HPO_gene_symbol_unique);
% Loading all GO annoatation data for human proteins with manual evidence code:
[~,GO_UniProt_acc_all,GO_gene_symbol_all,~,GO_term_id_all,GO_term_name_all,GO_term_aspect_all,~,~,~,~,~,~]=textread('GOA_UniProt_human_protein_annotation.tsv', '%s %s %s %s %s %s %s %s %s %s %s %s %s', 'delimiter', '\t','headerlines',1);
GO_annot_manual_human_all=[GO_gene_symbol_all GO_term_id_all];
GO_annot_manual_human_all=uniqueRowsCA(GO_annot_manual_human_all);
save HPO2GO_Files/HPO_test_GO_annotation_all.mat GO_annot_manual_human_all -v7
GO_annot_manual_human_all_addcol=[GO_gene_symbol_all GO_term_id_all GO_term_name_all GO_term_aspect_all];
GO_annot_manual_human_all_addcol=uniqueRowsCA(GO_annot_manual_human_all_addcol);
save HPO2GO_Files/HPO_test_GO_annotation_all_addcol.mat GO_annot_manual_human_all_addcol -v7
% Saving the processed GO annotation file will additional columns as text:
GO_annot_manual_human_all_addcol_txt=GO_annot_manual_human_all_addcol';
fid=fopen('HPO2GO_Files/GO_annot_human_proteins_UniProtGOA_01_2017.txt', 'w');
fprintf(fid, '%s\t%s\t%s\t%s\n', GO_annot_manual_human_all_addcol_txt{:});
fclose(fid);
GO_annot_manual_human_all_uniprotacc=[GO_UniProt_acc_all GO_gene_symbol_all GO_term_id_all];
GO_annot_manual_human_all_uniprotacc=uniqueRowsCA(GO_annot_manual_human_all_uniprotacc);
save HPO2GO_Files/HPO_test_GO_annotation_all_uniprotacc.mat GO_annot_manual_human_all_uniprotacc -v7
% Selecting the GO annotations for the HPO annotated protein list:
[Lia,Locb]=ismember(GO_annot_manual_human_all(:,1),HPO_gene_symbol_unique);
GO_annot_manual_human=GO_annot_manual_human_all(Lia==1,:);
save HPO2GO_Files/HPO_test_GO_annotation.mat GO_annot_manual_human -v7
% Generating the HPO and GO term pairs:
to=0;
HPO_GO_mapping_ind=zeros(2000000,2);
for i=1:length(HPO_gene_symbol_unique);
disp(['Mapping HPO terms with GO terms with gene #: ', num2str(i), ' / ', num2str(length(HPO_gene_symbol_unique))])
[Lia,Locb]=ismember(HPO_gene_annotation(:,2),HPO_gene_symbol_unique(i,1));
[Lia2,Locb2]=ismember(GO_annot_manual_human(:,1),HPO_gene_symbol_unique(i,1));
if sum(Lia2)>0
siz=sum(Lia)*sum(Lia2);
[A,B]=meshgrid(find(Lia==1),find(Lia2==1));
c=cat(2,A',B');
d=reshape(c,[],2);
HPO_GO_mapping_ind(to+1:to+siz,:)=d;
to=to+siz;
end
end
HPO_GO_mapping_ind(HPO_GO_mapping_ind(:,1)==0,:)=[];
HPO_GO_mapping_terms=HPO_gene_annotation(HPO_GO_mapping_ind(:,1),4);
HPO_GO_mapping_terms(:,2)=GO_annot_manual_human(HPO_GO_mapping_ind(:,2),2);
save HPO2GO_Files/HPO_GO_mapping_terms.mat HPO_GO_mapping_terms -v7
% Generating CAFA id vs. gene symbol vs. entry name vs. UniProt acc. mapping file:
% (downloading all swissprot human proteins with necessary columns)
[Humprot_UniProt_acc,Humprot_gene_symbol,Humprot_entry_name]=textread('HPO2GO_Files/Protein_acc_name_mapping.tab', '%s %s %s', 'delimiter', '\t','headerlines',1);
Humprot_gene_symbol=strtok(Humprot_gene_symbol);
save HPO2GO_Files/Humprot_mapping_variables.mat Humprot_UniProt_acc Humprot_gene_symbol Humprot_entry_name -v7
[CAFA3_Targets_human_headers,~]=fastaread('CAFA3_targets/Target files/target.9606.fasta');
CAFA3_Targets_human_headers=CAFA3_Targets_human_headers';
CAFA3_Targets_human_idmapping=cellfun(@(x) strsplit(x,' '), CAFA3_Targets_human_headers(:),'uni',0);
CAFA3_Targets_human_idmapping=vertcat(CAFA3_Targets_human_idmapping{:,1});
save HPO2GO_Files/CAFA3_HPO_target_variables.mat CAFA3_Targets_human_headers CAFA3_Targets_human_idmapping -v7
[~,Locb]=ismember(CAFA3_Targets_human_idmapping(:,2),Humprot_entry_name);
Locb(Locb==0,1)=length(Humprot_entry_name)+1;
Humprot_entry_name(end+1,1)=cellstr(' ');
Humprot_UniProt_acc(end+1,1)=cellstr(' ');
Humprot_gene_symbol(end+1,1)=cellstr(' ');
CAFA3_Targets_human_all_mappings=CAFA3_Targets_human_idmapping;
CAFA3_Targets_human_all_mappings(:,3)=Humprot_UniProt_acc(Locb,1);
CAFA3_Targets_human_all_mappings(:,4)=Humprot_gene_symbol(Locb,1);
save HPO2GO_Files/CAFA3_Targets_human_all_mappings.mat CAFA3_Targets_human_all_mappings -v7
% Calculating the co-occurrence similarity between ontology terms:
[HPO_GO_mapping_terms_unique,I,J]=uniqueRowsCA(HPO_GO_mapping_terms);
HPO_GO_mapping_terms_freq=sort(J);
HPO_GO_mapping_terms_pair_hist=hist(HPO_GO_mapping_terms_freq,0.5:1:max(HPO_GO_mapping_terms_freq)+0.5);
HPO_GO_mapping_terms_pair_hist=HPO_GO_mapping_terms_pair_hist(1,1:end-1)';
save HPO2GO_Files/HPO_GO_mapping_terms_unique.mat HPO_GO_mapping_terms_unique -v7
save HPO2GO_Files/HPO_GO_mapping_terms_pair_hist.mat HPO_GO_mapping_terms_pair_hist -v7
[HPO_terms_unique,~,N]=unique(HPO_gene_annotation(:,4));
HPO_terms_annot_hist=hist(N,0.5:1:max(N)+0.5);
HPO_terms_annot_hist=HPO_terms_annot_hist(1,1:end-1)';
save HPO2GO_Files/HPO_terms_unique.mat HPO_terms_unique -v7
save HPO2GO_Files/HPO_terms_annot_hist.mat HPO_terms_annot_hist -v7
[GO_terms_unique,~,N]=unique(GO_annot_manual_human(:,2));
GO_terms_annot_hist=hist(N,0.5:1:max(N)+0.5);
GO_terms_annot_hist=GO_terms_annot_hist(1,1:end-1)';
save HPO2GO_Files/GO_terms_unique.mat GO_terms_unique -v7
save HPO2GO_Files/GO_terms_annot_hist.mat GO_terms_annot_hist -v7
[~,HPO_GO_mapping_unique_array_ind]=ismember(HPO_GO_mapping_terms_unique(:,1),HPO_terms_unique);
[~,HPO_GO_mapping_unique_array_ind(:,2)]=ismember(HPO_GO_mapping_terms_unique(:,2),GO_terms_unique);
HPO_GO_mapping_sematic_sim_high_det=zeros(length(HPO_GO_mapping_terms_unique),5);
for i=1:length(HPO_GO_mapping_terms_unique);
disp(['Calculating the semantic similarity between the HPO ang GO term pair #: ', num2str(i), ' / ', num2str(length(HPO_GO_mapping_terms_unique))])
t1=HPO_GO_mapping_terms_pair_hist(i,1);
t2=HPO_terms_annot_hist(HPO_GO_mapping_unique_array_ind(i,1),1);
t3=GO_terms_annot_hist(HPO_GO_mapping_unique_array_ind(i,2),1);
HPO_GO_mapping_sematic_sim_high_det(i,1:5)=[i (2*t1)/(t2+t3) t1 t2 t3]; % columns: indice of mapping, semantic similarity of the mapped terms, # of co-annotated genes, total # of annotation of the mapped HPO term on different genes, total # of annotation of the mapped GO term on different genes
end
save HPO2GO_Files/HPO_GO_mapping_sematic_sim_high_det.mat HPO_GO_mapping_sematic_sim_high_det -v7
HPO_GO_Raw_Mapping_merged=[HPO_GO_mapping_terms_unique num2cell(HPO_GO_mapping_sematic_sim_high_det(:,2:end))];
save HPO2GO_Files/HPO_GO_Raw_Mapping_merged.mat HPO_GO_Raw_Mapping_merged -v7
% Saving the original raw mapping file as text:
HPO_GO_Raw_Mapping_merged_txt=HPO_GO_Raw_Mapping_merged';
fid=fopen('HPO_GO_Raw_Original_Mapping.txt', 'w');
fprintf(fid, '%s\t%s\t%.4f\t%d\t%d\t%d\n', HPO_GO_Raw_Mapping_merged_txt{:});
fclose(fid);
% Extracting the statistics for the original mapping - part of Table 1:
HPO_GO_mapping_sematic_sim=HPO_GO_mapping_sematic_sim_high_det(:,2);
S=1.1;
Mapping_stat=0;
for i=1:10;
S=S-0.1;
Mapping_stat(i,1)=S;
Mapping_stat(i,2)=length(find(HPO_GO_mapping_sematic_sim>=S));
Mapping_stat(i,3)=length(unique(HPO_GO_mapping_terms_unique(HPO_GO_mapping_sematic_sim>=S,1)));
Mapping_stat(i,4)=length(unique(HPO_GO_mapping_terms_unique(HPO_GO_mapping_sematic_sim>=S,2)));
Mapping_stat(i,5)=length(find(ismember(HPO_gene_annotation(:,4),unique(HPO_GO_mapping_terms_unique(HPO_GO_mapping_sematic_sim>=S,1)))==1));
Mapping_stat(i,6)=length(find(ismember(GO_annot_manual_human(:,2),unique(HPO_GO_mapping_terms_unique(HPO_GO_mapping_sematic_sim>=S,2)))==1));
end
Mapping_table_title={['Threshold'], ['# of unique mappings'], ['# of unique HPO terms'], ['# of unique GO terms'], ['Total # of annot with HPO term'], ['Total # of annot with GO term']};
Mapping_stat_cel=num2cell(Mapping_stat);
Mapping_table=vertcat(Mapping_table_title,Mapping_stat_cel);
save HPO2GO_Files/HPO_sematic_sim_Mapping_stat_table.mat Mapping_table -v7
% Plotting the original co-occurrence similarity distributions for different numbers of co-annotated
% genes - Figure 3 (only when m=0) and part of Figure 1:
n=[1 5 25 50];
m=[0 0.1 0.2];
for i=1:4;
for j=1:3;
P=HPO_GO_mapping_sematic_sim_high_det(HPO_GO_mapping_sematic_sim_high_det(:,3)>=(n(1,i)),2);
X=max(hist(P,0.00005:0.01:1.00005));
P=P(P>=m(1,j));
figure;hist(P,0.00005:0.01:1.00005);
hold on;
x_lab=xlabel('Co-occurrence similarity bins');
y_lab=ylabel('# of unique mappings');
set(x_lab,'FontSize',14);
set(y_lab,'FontSize',14);
eval(['title(''Co-occurrence Similarity Distribution (n >= ', num2str(n(1,i)), ')'',''FontSize'',16);'])
grid on
axis([0 0.3 0 (X*(11/10))])
hold off;
end
end
% Generating the randomized set (for comparison with the original set, to determine the thresholds):
GO_annot_manual_human_rand=randsample(GO_annot_manual_human(:,1),length(GO_annot_manual_human(:,1)));
GO_annot_manual_human_rand(:,2)=randsample(GO_annot_manual_human(:,2),length(GO_annot_manual_human(:,2)));
GO_annot_manual_human_rand=uniqueRowsCA(GO_annot_manual_human_rand);
HPO_gene_annotation_rand=randsample(HPO_gene_annotation(:,2),length(HPO_gene_annotation(:,2)));
HPO_gene_annotation_rand(:,2)=randsample(HPO_gene_annotation(:,4),length(HPO_gene_annotation(:,4)));
HPO_gene_annotation_rand=uniqueRowsCA(HPO_gene_annotation_rand);
to=0;
HPO_GO_mapping_ind_rand=zeros(2000000,2);
for i=1:length(HPO_gene_symbol_unique);
disp(['Mapping HPO terms with GO terms with gene #: ', num2str(i), ' / ', num2str(length(HPO_gene_symbol_unique))])
[Lia,Locb]=ismember(HPO_gene_annotation_rand(:,1),HPO_gene_symbol_unique(i,1));
[Lia2,Locb2]=ismember(GO_annot_manual_human_rand(:,1),HPO_gene_symbol_unique(i,1));
if sum(Lia2)>0
siz=sum(Lia)*sum(Lia2);
[A,B]=meshgrid(find(Lia==1),find(Lia2==1));
c=cat(2,A',B');
d=reshape(c,[],2);
HPO_GO_mapping_ind_rand(to+1:to+siz,:)=d;
to=to+siz;
end
end
HPO_GO_mapping_ind_rand(HPO_GO_mapping_ind_rand(:,1)==0,:)=[];
HPO_GO_mapping_terms_rand=HPO_gene_annotation_rand(HPO_GO_mapping_ind_rand(:,1),2);
HPO_GO_mapping_terms_rand(:,2)=GO_annot_manual_human_rand(HPO_GO_mapping_ind_rand(:,2),2);
save HPO2GO_Files/HPO_GO_mapping_terms_rand.mat HPO_GO_mapping_terms_rand -v7
[HPO_GO_mapping_terms_unique_rand,I,J]=uniqueRowsCA(HPO_GO_mapping_terms_rand);
HPO_GO_mapping_terms_freq_rand=sort(J);
HPO_GO_mapping_terms_pair_hist_rand=hist(HPO_GO_mapping_terms_freq_rand,0.5:1:max(HPO_GO_mapping_terms_freq_rand)+0.5);
HPO_GO_mapping_terms_pair_hist_rand=HPO_GO_mapping_terms_pair_hist_rand(1,1:end-1)';
save HPO2GO_Files/HPO_GO_mapping_terms_unique_rand.mat HPO_GO_mapping_terms_unique_rand -v7
save HPO2GO_Files/HPO_GO_mapping_terms_pair_hist_rand.mat HPO_GO_mapping_terms_pair_hist_rand -v7
[HPO_terms_unique_rand,~,N]=unique(HPO_gene_annotation_rand(:,2));
HPO_terms_annot_hist_rand=hist(N,0.5:1:max(N)+0.5);
HPO_terms_annot_hist_rand=HPO_terms_annot_hist_rand(1,1:end-1)';
[GO_terms_unique_rand,~,N]=unique(GO_annot_manual_human_rand(:,2));
GO_terms_annot_hist_rand=hist(N,0.5:1:max(N)+0.5);
GO_terms_annot_hist_rand=GO_terms_annot_hist_rand(1,1:end-1)';
[~,HPO_GO_mapping_unique_array_ind_rand]=ismember(HPO_GO_mapping_terms_unique_rand(:,1),HPO_terms_unique_rand);
[~,HPO_GO_mapping_unique_array_ind_rand(:,2)]=ismember(HPO_GO_mapping_terms_unique_rand(:,2),GO_terms_unique_rand);
HPO_GO_mapping_sematic_sim_high_det_rand=zeros(length(HPO_GO_mapping_terms_unique_rand),5);
for i=1:length(HPO_GO_mapping_terms_unique_rand);
disp(['Calculating the semantic similarity between the HPO ang GO term pair #: ', num2str(i), ' / ', num2str(length(HPO_GO_mapping_terms_unique_rand))])
t1=HPO_GO_mapping_terms_pair_hist_rand(i,1);
t2=HPO_terms_annot_hist_rand(HPO_GO_mapping_unique_array_ind_rand(i,1),1);
t3=GO_terms_annot_hist_rand(HPO_GO_mapping_unique_array_ind_rand(i,2),1);
HPO_GO_mapping_sematic_sim_high_det_rand(i,1:5)=[i (2*t1)/(t2+t3) t1 t2 t3]; % columns: indice of mapping, semantic similarity of the mapped terms, no of co-annotation of the mapped terms on different genes, total no of annotation of the mapped HPO term on different genes, total no of annotation of the mapped GO term on different genes
end
save HPO2GO_Files/HPO_GO_mapping_sematic_sim_high_det_rand.mat HPO_GO_mapping_sematic_sim_high_det_rand -v7
HPO_GO_random_mapping_merge=[HPO_GO_mapping_terms_unique_rand num2cell(HPO_GO_mapping_sematic_sim_high_det_rand(:,2:end))];
save HPO2GO_Files/HPO_GO_random_mapping_merge.mat HPO_GO_random_mapping_merge -v7
% Saving the randomized mapping file as text:
HPO_GO_random_mapping_merge_txt=HPO_GO_random_mapping_merge';
fid=fopen('HPO_GO_Random_Mapping.txt', 'w');
fprintf(fid, '%s\t%s\t%.4f\t%d\t%d\t%d\n', HPO_GO_random_mapping_merge_txt{:});
fclose(fid);
% Extracting the statistics for the randomized mapping - part of Table 1:
HPO_GO_mapping_sematic_sim_rand=HPO_GO_mapping_sematic_sim_high_det_rand(:,2);
S=1.1;
Mapping_stat_rand=0;
for i=1:10;
S=S-0.1;
Mapping_stat_rand(i,1)=S;
Mapping_stat_rand(i,2)=length(find(HPO_GO_mapping_sematic_sim_rand>=S));
Mapping_stat_rand(i,3)=length(unique(HPO_GO_mapping_terms_unique_rand(HPO_GO_mapping_sematic_sim_rand>=S,1)));
Mapping_stat_rand(i,4)=length(unique(HPO_GO_mapping_terms_unique_rand(HPO_GO_mapping_sematic_sim_rand>=S,2)));
Mapping_stat_rand(i,5)=length(find(ismember(HPO_gene_annotation_rand(:,2),unique(HPO_GO_mapping_terms_unique_rand(HPO_GO_mapping_sematic_sim_rand>=S,1)))==1));
Mapping_stat_rand(i,6)=length(find(ismember(GO_annot_manual_human_rand(:,2),unique(HPO_GO_mapping_terms_unique_rand(HPO_GO_mapping_sematic_sim_rand>=S,2)))==1));
end
Mapping_table_title_rand={['Threshold'], ['# of unique mappings'], ['# of unique HPO terms'], ['# of unique GO terms'], ['Total # of annot with HPO term'], ['Total # of annot with GO term']};
Mapping_stat_cel_rand=num2cell(Mapping_stat_rand);
Mapping_table_rand=vertcat(Mapping_table_title_rand,Mapping_stat_cel_rand);
save HPO2GO_Files/HPO_sematic_sim_Mapping_stat_table_rand.mat Mapping_table_rand -v7
% Plotting the randomized co-occurrence similarity distributions for different numbers of co-annotated genes:
n=[1 5 25 75];
for i=1:4;
P=HPO_GO_mapping_sematic_sim_high_det_rand(HPO_GO_mapping_sematic_sim_high_det_rand(:,3)>=(n(1,i)),2);
figure;hist(P,0.00005:0.01:1.00005);
hold on;
x_lab=xlabel('Co-occurrence similarity bins');
y_lab=ylabel('# of unique mappings');
set(x_lab,'FontSize',14);
set(y_lab,'FontSize',14);
eval(['title(''Co-occurrence Similarity Distribution of Random Mapping (n >= ', num2str(n(1,i)), ')'',''FontSize'',16);'])
grid on
axis([0 0.3 0 (max(hist(P,0.00005:0.01:1.00005))*(11/10))])
hold off;
end
% Plotting the number of mappings against threshold selections (normal vs. random) - Figure 4:
load HPO2GO_Files/HPO_GO_mapping_sematic_sim_high_det.mat
load HPO2GO_Files/HPO_GO_mapping_sematic_sim_high_det_rand.mat
n=0;
for j=1:5;
n=n+1;
S=1.1;
for i=1:20;
if S>0.11 % using 0.11 is crucial since matlab has a weird behaviour if 0.1 is used
S=S-0.1;
else
S=S-0.01;
end
plo_nor(j,21-i)=length(find(HPO_GO_mapping_sematic_sim_high_det(HPO_GO_mapping_sematic_sim_high_det(:,2)>=S,3)>=n));
plo_rand(j,21-i)=length(find(HPO_GO_mapping_sematic_sim_high_det_rand(HPO_GO_mapping_sematic_sim_high_det_rand(:,2)>=S,3)>=n));
end
thres=[0:0.01:0.09 0.1:0.1:1];
figure;
hold on;
F=plot(thres,log(plo_nor(j,:)));
set(F,'Color',[0.2 0.2 1],'LineWidth',2)
R=plot(thres,log(plo_rand(j,:)));
set(R,'Color',[1 0.2 0.2],'LineWidth',2)
legendo=legend('Original','Randomized');
set(legendo,'FontSize',14,'Location','northeast');
x_lab=xlabel('Co-occurrence Similarity Threshold');
y_lab=ylabel('Log ( total # of unique mappings )');
set(x_lab,'FontSize',14);
set(y_lab,'FontSize',14);
eval(['title(''Cumulative # of Mappings - Original vs. Randomized Distributions (n >= ', num2str(n), ')'',''FontSize'',16);'])
grid on
axis([0 1 (min(log(plo_rand(j,:)))*(4/5)) (max(log(plo_nor(j,:)))*(6/5))])
hold off;
end
% Significance test (kstest and ttest):
% (to differentiate between normal and random at different similarity thresholds (S) and number of co-occurences on different genes (n) )
sig_kstest=NaN(5,7);
sig_ttest=NaN(5,7);
n=0;
for j=1:5;
n=n+1;
S=-0.1;
for i=1:7;
S=S+0.1;
dist1=HPO_GO_mapping_sematic_sim_high_det(HPO_GO_mapping_sematic_sim_high_det(:,2)>=S,:);
dist1=sort(dist1(dist1(:,3)>=n,2));
dist2=HPO_GO_mapping_sematic_sim_high_det_rand(HPO_GO_mapping_sematic_sim_high_det_rand(:,2)>=S,:);
dist2=sort(dist2(dist2(:,3)>=n,2));
dist1_hist=hist(dist1,20);
dist2_hist=hist(dist2,20);
dist1_hist(dist1_hist==0)=NaN; % if not set to NaN zeros in both histograms are treated as if they are the same actual values and the p-value is incorrectly adjusted in these cases
dist2_hist(dist2_hist==0)=NaN;
if length(dist1)>10 && length(dist2)>10
[~,sig_kstest(j,i)]=kstest2(dist1_hist,dist2_hist);
[~,sig_ttest(j,i)]=ttest2(dist1_hist,dist2_hist,'Vartype','unequal');
else
sig_kstest(j,i)=NaN;
sig_ttest(j,i)=NaN;
end
end
end
save HPO2GO_Files/HPO_KStest_result_table.mat sig_kstest -v7
save HPO2GO_Files/HPO_ttest_result_table.mat sig_ttest -v7
% (checking the number of unique HPO and GO terms we used at different thresholds)
n=0;
for j=1:10;
n=n+1;
S=1.1;
for i=1:20
if S>0.1001 % using 0.11 is crucial since matlab has a weird behaviour if 0.1 is used
S=S-0.1;
else
S=S-0.01;
end
HPO_GO_mapping_sematic_sim_high_det_thres=HPO_GO_mapping_sematic_sim_high_det(HPO_GO_mapping_sematic_sim_high_det(:,2)>S,:);
HPO_GO_mapping_sematic_sim_high_det_thres_membnum=HPO_GO_mapping_sematic_sim_high_det_thres(HPO_GO_mapping_sematic_sim_high_det_thres(:,3)>=n,:);
HPO_GO_mapping_terms_unique_thres_membnum=HPO_GO_mapping_terms_unique(HPO_GO_mapping_sematic_sim_high_det_thres_membnum(:,1),:);
num_HPO_terms(n,21-i)=length(unique(HPO_GO_mapping_terms_unique_thres_membnum(:,1)));
num_GO_terms(n,21-i)=length(unique(HPO_GO_mapping_terms_unique_thres_membnum(:,2)));
end
end
% (considering sig_Sstest result: n>=2 -observed number of co-annotated genes- and
% S>=0.1 -co-occurrence similarity thereshold- was observed to be sufficient to assume significance)
% Saving the finalized HPO2GO mapping file:
n=2;
S=0.1;
load HPO2GO_Files/HPO_GO_mapping_sematic_sim_high_det.mat
load HPO2GO_Files/HPO_GO_mapping_terms.mat
load HPO2GO_Files/HPO_GO_mapping_terms_unique.mat
high_det_thres=HPO_GO_mapping_sematic_sim_high_det(HPO_GO_mapping_sematic_sim_high_det(:,2)>=S,:);
high_det_thres=high_det_thres(high_det_thres(:,3)>=n,:);
HPO2GO_Finalized_Mapping=HPO_GO_mapping_terms_unique(high_det_thres(:,1),:);
HPO2GO_Finalized_Mapping(:,3:4)=num2cell(HPO_GO_mapping_sematic_sim_high_det(high_det_thres(:,1),2:3));
% (deleting the mappings to HPO terms that are not belong to phenotypic abnormality sub-ontology)
[HPO_ID_not_abnor,HPO_Name_not_abnor]=textread('HPO2GO_Files/HPO_terms_not_abnormality.txt', '%s %s', 'delimiter', '\t');
[Lia,Locb]=ismember(HPO2GO_Finalized_Mapping(:,1),HPO_ID_not_abnor);
HPO2GO_Finalized_Mapping(Lia==1,:)=[];
save HPO2GO_Files/HPO2GO_Finalized_Mapping.mat HPO2GO_Finalized_Mapping -v7
length(unique(HPO2GO_Finalized_Mapping(:,1)))
length(unique(HPO2GO_Finalized_Mapping(:,2)))
figure;
hold on;
hist(cell2mat(HPO2GO_Finalized_Mapping(:,3)),0:0.01:1)
axis([0 1 0 max(hist(cell2mat(HPO2GO_Finalized_Mapping(:,3)),0:0.01:1))*1.1])
hold off;
figure;
hold on;
hist(HPO_GO_mapping_sematic_sim_high_det(:,2),0:0.01:1)
axis([0 1 0 max(hist(HPO_GO_mapping_sematic_sim_high_det(:,2),0:0.01:1))*1.1])
hold off;
figure;
hold on;
hist(cell2mat(HPO2GO_Finalized_Mapping(:,4)),0.0005:1:max(cell2mat(HPO2GO_Finalized_Mapping(:,4)))+0.0005)
axis([0 30 0 max(hist(cell2mat(HPO2GO_Finalized_Mapping(:,4)),0.0005:1:max(cell2mat(HPO2GO_Finalized_Mapping(:,4)))+0.0005))*1.1])
hold off;
figure;
hold on;
hist(HPO_GO_mapping_sematic_sim_high_det(:,3),0.0005:1:max(HPO_GO_mapping_sematic_sim_high_det(:,3))+0.0005)
axis([0 30 0 max(hist(HPO_GO_mapping_sematic_sim_high_det(:,3),0.0005:1:max(HPO_GO_mapping_sematic_sim_high_det(:,3))+0.0005))*1.1])
hold off;
% Saving the finalized HPO2GO mapping file as text:
HPO2GO_Finalized_Mapping_txt=HPO2GO_Finalized_Mapping';
fid=fopen('HPO2GO_Finalized_Mapping.txt', 'w');
fprintf(fid, '%s\t%s\t%.4f\t%d\n', HPO2GO_Finalized_Mapping_txt{:});
fclose(fid);
% Comparing HPO2GO mappings with the manually generated HPO to GO associations:
[HPO_manual_GO_HPOID,HPO_manual_GO_GOID]=textread('HPO2GO_Files/HPO_manual_GO_associations_03_2018.txt', '%s %s', 'delimiter', '\t');
HPO_manual_GO=[HPO_manual_GO_HPOID HPO_manual_GO_GOID];
length(HPO_manual_GO)
length(unique(HPO_manual_GO_HPOID))
length(unique(HPO_manual_GO_GOID))
HPO_manual_GO=uniqueRowsCA(HPO_manual_GO);
HPO_manual_GO_txt=HPO_manual_GO';
fid=fopen('HPO2GO_Files/HPO_manual_GO_associations_03_2018.txt', 'w');
fprintf(fid, '%s\t%s\n', HPO_manual_GO_txt{:});
fclose(fid);
save HPO2GO_Files/HPO_manual_GO_associations.mat HPO_manual_GO -v7
[Lia,Locb]=ismember(HPO_manual_GO(:,2),unique(HPO_manual_GO(:,2)));
Locb_hist=hist(Locb,0.5:1:(max(Locb)+0.5));
Locb_hist(Locb_hist>10)
HPO_manual_GO_unique=unique(HPO_manual_GO(:,2));
HPO_manual_GO_unique(find(Locb_hist>10),1)
load HPO2GO_Files/HPO2GO_Finalized_Mapping.mat
[Lia,Locb]=ismember(HPO_manual_GO(:,1),HPO2GO_Finalized_Mapping(:,1));
sum(Lia)
length(unique(HPO_manual_GO(Lia==1,1)))
[Lia,Locb]=ismember(HPO_manual_GO(:,2),HPO2GO_Finalized_Mapping(:,2));
sum(Lia)
length(unique(HPO_manual_GO(Lia==1,2)))
HPO_manual_GO_merged=strcat(HPO_manual_GO(:,1),{' '},HPO_manual_GO(:,2));
HPO2GO_Finalized_Mapping_merged=strcat(HPO2GO_Finalized_Mapping(:,1),{' '},HPO2GO_Finalized_Mapping(:,2));
[Lia,Locb]=ismember(HPO_manual_GO_merged,HPO2GO_Finalized_Mapping_merged);
sum(Lia)
% Predicting HPO terms for CAFA3 human target proteins:
load HPO2GO_Files/HPO_GO_mapping_sematic_sim_high_det.mat
load HPO2GO_Files/HPO_GO_mapping_terms_unique.mat
load HPO2GO_Files/CAFA3_Targets_human_all_mappings.mat
load HPO2GO_Files/CAFA3_HPO_target_variables.mat
load HPO2GO_Files/Humprot_mapping_variables.mat
load HPO2GO_Files/HPO_GO_mapping_terms.mat
load HPO2GO_Files/HPO_test_GO_annotation.mat
load HPO2GO_Files/HPO_test_HPO_gene_annotation.mat
load HPO2GO_Files/HPO_test_GO_annotation_all.mat
load HPO2GO_Files/HPO2GO_Finalized_Mapping.mat
mapGO_unique=unique(HPO2GO_Finalized_Mapping(:,2));
[~,Locb0]=ismember(HPO2GO_Finalized_Mapping(:,2),mapGO_unique);
[Lia,Locb]=ismember(GO_annot_manual_human_all(:,2),mapGO_unique);
to=0;
CAFA3_HPO_predictions=cell(2000000,3);
for i=1:length(mapGO_unique);
disp(['Predicting HPO terms for the mapped GO term #: ', num2str(i), ' / ', num2str(length(mapGO_unique))])
genesymbol_temp=GO_annot_manual_human_all(Locb==i,1);
HPO_temp=HPO2GO_Finalized_Mapping(Locb0==i,1);
score_temp=HPO2GO_Finalized_Mapping(Locb0==i,3);
if sum(Lia)>0
siz=length(genesymbol_temp)*length(HPO_temp);
[A,B]=meshgrid(1:length(genesymbol_temp),1:length(HPO_temp));
c=cat(2,A',B');
d=reshape(c,[],2);
CAFA3_HPO_predictions(to+1:to+siz,1)=genesymbol_temp(d(:,1),1);
CAFA3_HPO_predictions(to+1:to+siz,2)=HPO_temp(d(:,2),1);
CAFA3_HPO_predictions(to+1:to+siz,3)=score_temp(d(:,2),1);
to=to+siz;
end
end
CAFA3_HPO_predictions(cellfun(@isempty,CAFA3_HPO_predictions(:,1))==1,:)=[];
[CAFA3_HPO_predictions_un,I,C]=uniqueRowsCA(CAFA3_HPO_predictions(:,1:2));
% score_unique=zeros(length(CAFA3_HPO_predictions_un),1); % Alternative 1) Extremely slow
% for i=1:length(CAFA3_HPO_predictions_un)
% disp(['Calculating the max score for the prediction #: ', num2str(i), ' / ', num2str(length(CAFA3_HPO_predictions_un))])
% score_unique(i,1)=max(cell2mat(CAFA3_HPO_predictions(C==i,3)));
% end
% score=cell2mat(CAFA3_HPO_predictions(:,3));
% score_unique=arrayfun(@(x) max(score(C==x,1)), 1:max(C)); % Alternative 2) Slow
score=cell2mat(CAFA3_HPO_predictions(:,3));
score_unique=splitapply(@max,score,C); % Alternative 3) Very fast but requires Matlab 2017b
CAFA3_HPO_predictions_un(:,3)=num2cell(score_unique);
CAFA3_HPO_predictions=CAFA3_HPO_predictions_un;
CAFA3_HPO_predictions(ismember(CAFA3_HPO_predictions(:,1),'2xchrna4-3xchrnb2_human')==1,1)=cellstr('CHRNA4');
CAFA3_HPO_predictions(ismember(CAFA3_HPO_predictions(:,1),'3xchrna4-2xchrnb2_human')==1,1)=cellstr('CHRNA4');
mapsymbol_unique=unique(CAFA3_HPO_predictions(:,1));
[Lia0,Locb0]=ismember(CAFA3_HPO_predictions(:,1),mapsymbol_unique);
[Lia,Locb]=ismember(mapsymbol_unique,CAFA3_Targets_human_all_mappings(:,4));
Locb(Locb==0,1)=length(CAFA3_Targets_human_all_mappings)+1;
CAFA3_Targets_human_all_mappings(end+1,:)=cellstr(' ');
mapCAFAid_unique=CAFA3_Targets_human_all_mappings(Locb,1);
CAFA3_HPO_predictions_CAFAid_genesymbol_HPOid_sco=mapCAFAid_unique(Locb0,1);
CAFA3_HPO_predictions_CAFAid_genesymbol_HPOid_sco(:,2:4)=CAFA3_HPO_predictions;
save HPO2GO_Files/CAFA3_HPO_predictions_CAFAid_genesymbol_HPOid_sco.mat CAFA3_HPO_predictions_CAFAid_genesymbol_HPOid_sco -v7
CAFA3_pred_eval_save=CAFA3_HPO_predictions_CAFAid_genesymbol_HPOid_sco;
CAFA3_pred_eval_save(cellfun(@isempty,CAFA3_pred_eval_save(:,1))==1,:)=[];
CAFA3_pred_eval_save=uniqueRowsCA(CAFA3_pred_eval_save);
save HPO2GO_Files/CAFA3_HPO_predictions_semantic.mat CAFA3_pred_eval_save -v7
CAFA3_HPO_target_predictions=CAFA3_pred_eval_save(:,[1 3 4]);
save HPO2GO_Files/CAFA3_HPO_target_predictions.mat CAFA3_HPO_target_predictions -v7
length(CAFA3_HPO_target_predictions)
length(unique(CAFA3_HPO_target_predictions(:,1)))
length(unique(CAFA3_HPO_target_predictions(:,2)))
% Saving CAFA3 HPO target predictions in a text file:
CAFA3_pred_eval_save_txt=CAFA3_pred_eval_save(:,[1 3 4])';
fid=fopen('CAFA3_HPO_target_predictions.txt', 'w');
fprintf(fid, '%s\t%s\t%.2f\n', CAFA3_pred_eval_save_txt{:});
fclose(fid);
% Generating the finalized HPO2protein predictions:
load HPO2GO_Files/HPO_test_GO_annotation_all_uniprotacc.mat
[Lia,Locb]=ismember(CAFA3_HPO_predictions_CAFAid_genesymbol_HPOid_sco(:,2),GO_annot_manual_human_all_uniprotacc(:,2));
HPO2protein_predictions=GO_annot_manual_human_all_uniprotacc(Locb,1);
HPO2protein_predictions(:,2:3)=CAFA3_HPO_predictions_CAFAid_genesymbol_HPOid_sco(:,3:4);
Lia=strncmp('EBI-',HPO2protein_predictions(:,1),4);
HPO2protein_predictions(Lia==1,:)=[];
% (deleting the predictions with terms that are not belong to phenotypic abnormality sub-ontology)
[HPO_ID_not_abnor,~]=textread('HPO2GO_Files/HPO_terms_not_abnormality.txt', '%s %s', 'delimiter', '\t');
[Lia,~]=ismember(HPO2protein_predictions(:,2),HPO_ID_not_abnor);
HPO2protein_predictions(Lia==1,:)=[];
save HPO2GO_Files/HPO2protein_predictions.mat HPO2protein_predictions -v7
length(HPO2protein_predictions)
length(unique(HPO2protein_predictions(:,1)))
length(unique(HPO2protein_predictions(:,2)))
% Saving HPO2protein predictions in a text file:
HPO2protein_predictions_txt=HPO2protein_predictions';
fid=fopen('HPO2protein_predictions.txt', 'w');
fprintf(fid, '%s\t%s\t%.4f\n', HPO2protein_predictions_txt{:});
fclose(fid);
% Calculating how many of the targets already have disease annotation in UniProt:
list=unique(HPO2protein_predictions(:,1));
dlmcell('hpo_list.txt',list)
% (load the list to UniProt ID mapping and obtain the disease annotation file)
[CAFA3_HPO_UniProt_acc,CAFA3_HPO_gene_name,CAFA3_HPO_disease_annot,CAFA3_HPO_orphanet_annot]=textread('HPO2GO_Files/CAFA3_HPO_predicted_target_list_w_disease_annot.tab', '%s %s %s %s', 'delimiter', '\t', 'headerlines', 1, 'bufsize', 10000);
CAFA3_HPO_disease_annot_sort=sort(CAFA3_HPO_disease_annot);
CAFA3_HPO_disease_annot_sort(cellfun(@isempty,CAFA3_HPO_disease_annot_sort(:,1))==1,:)=[];
length(list)-length(CAFA3_HPO_disease_annot_sort);
% (14545 out of 18134 proteins with predictions have no existing disease annotation in UniProt)
% Performance test on CAFA2 targets
% (download CAFA2 files from: https://figshare.com/articles/Supplementary_Data_for_CAFA2/2059944)
[CAFA2_HPO_ground_geneCAFAid,CAFA2_HPO_ground_HPOid]=textread('CCAFA2/CAFA2-master/benchmark/groundtruth/propagated_HPO.txt', '%s %s', 'delimiter', '\t');
CAFA2_HPO_ground_geneCAFAid_unique=unique(CAFA2_HPO_ground_geneCAFAid);
[CAFA2_Targets_human_headers,~]=fastaread('CAFA2/CAFA2_Supplementary_data/data/CAFA2-targets/eukarya/sp_species.9606.tfa');
CAFA2_Targets_human_headers=CAFA2_Targets_human_headers';
CAFA2_Targets_human_idmapping=cellfun(@(x) strsplit(x,' '), CAFA2_Targets_human_headers(:),'uni',0);
CAFA2_Targets_human_idmapping=vertcat(CAFA2_Targets_human_idmapping{:,1});
[Lia,~]=ismember(CAFA2_Targets_human_idmapping(:,1),CAFA2_HPO_ground_geneCAFAid_unique);
save HPO2GO_Files/CAFA2_HPO_target_variables.mat CAFA2_Targets_human_headers CAFA2_Targets_human_idmapping -v7
CAFA2_HPO_ground_proteinname=CAFA2_Targets_human_idmapping(Lia==1,2);
load HPO2GO_Files/Humprot_mapping_variables.mat
[~,Locb]=ismember(CAFA2_Targets_human_idmapping(:,2),Humprot_entry_name);
Locb(Locb==0,1)=length(Humprot_entry_name)+1;
Humprot_entry_name(end+1,1)=cellstr(' ');
Humprot_UniProt_acc(end+1,1)=cellstr(' ');
Humprot_gene_symbol(end+1,1)=cellstr(' ');
CAFA2_Targets_human_all_mappings=CAFA2_Targets_human_idmapping;
CAFA2_Targets_human_all_mappings(:,3)=Humprot_UniProt_acc(Locb,1);
CAFA2_Targets_human_all_mappings(:,4)=Humprot_gene_symbol(Locb,1);
save HPO2GO_Files/CAFA2_Targets_human_all_mappings.mat CAFA2_Targets_human_all_mappings -v7
% (id mapping between CAFA2_HPO_ground_proteinname and associated gene symbols, loaded as: CAFA2_HPO_ground_proteinname_genesymbol)
[CAFA2_HPO_ground_proteinname_genesymbol(:,1),idx]=sort(CAFA2_HPO_ground_proteinname_genesymbol(:,1));
CAFA2_HPO_ground_proteinname_genesymbol(:,2)=CAFA2_HPO_ground_proteinname_genesymbol(idx,2);
isequal(CAFA2_HPO_ground_proteinname_genesymbol(:,1),CAFA2_HPO_ground_proteinname(:,1))
[~,Locb]=ismember(CAFA2_HPO_ground_geneCAFAid,CAFA2_HPO_ground_geneCAFAid_unique);
CAFA2_HPO_ground_genesymbol=CAFA2_HPO_ground_proteinname_genesymbol(Locb,2);
CAFA2_HPO_ground_annot_genesymbol_HPOid=CAFA2_HPO_ground_genesymbol;
CAFA2_HPO_ground_annot_genesymbol_HPOid(:,2)=CAFA2_HPO_ground_HPOid;
CAFA2_HPO_ground_annot_CAFAid_genesymbol_HPOid=CAFA2_HPO_ground_geneCAFAid;
CAFA2_HPO_ground_annot_CAFAid_genesymbol_HPOid(:,2:3)=CAFA2_HPO_ground_annot_genesymbol_HPOid;
save HPO2GO_Files/CAFA2_HPO_ground_variables.mat CAFA2_HPO_ground_annot_CAFAid_genesymbol_HPOid CAFA2_HPO_ground_annot_genesymbol_HPOid CAFA2_HPO_ground_geneCAFAid CAFA2_HPO_ground_geneCAFAid_unique CAFA2_HPO_ground_genesymbol CAFA2_HPO_ground_HPOid CAFA2_HPO_ground_proteinname CAFA2_HPO_ground_proteinname_genesymbol -v7
% (loading CAFA2 trainnig set for HPO)
[CAFA2_HPO_training_UniProtid,CAFA2_HPO_training_HPOid]=textread('CAFA2/CAFA2_Supplementary_data/data/HPO-t0/hpoa.hp', '%s %s', 'delimiter', '\t');
CAFA2_HPO_training_UniProtid_unique=unique(CAFA2_HPO_training_UniProtid);
% (id mapping between CAFA2_HPO_training_UniProtid_unique and associated gene symbols, loaded as: CAFA2_HPO_training_UniProtid_genesymbol)
[CAFA2_HPO_training_UniProtid_genesymbol(:,1),idx]=sort(CAFA2_HPO_training_UniProtid_genesymbol(:,1));
CAFA2_HPO_training_UniProtid_genesymbol(:,2)=CAFA2_HPO_training_UniProtid_genesymbol(idx,2);
[Lia,Locb]=ismember(CAFA2_HPO_training_UniProtid,CAFA2_HPO_training_UniProtid_genesymbol(:,1));
CAFA2_HPO_training_UniProtid_onlywithgenesym=CAFA2_HPO_training_UniProtid_genesymbol(Locb(Locb>0),1);
CAFA2_HPO_training_genesymbol_onlywithgenesym=CAFA2_HPO_training_UniProtid_genesymbol(Locb(Locb>0),2);
CAFA2_HPO_training_HPOid_onlywithgenesym=CAFA2_HPO_training_HPOid(Locb>0,1);
CAFA2_HPO_training_annot_genesymbol_HPOid=CAFA2_HPO_training_genesymbol_onlywithgenesym;
CAFA2_HPO_training_annot_genesymbol_HPOid(:,2)=CAFA2_HPO_training_HPOid_onlywithgenesym;
CAFA2_HPO_training_annot_genesymbol_HPOid_unique=uniqueRowsCA(CAFA2_HPO_training_annot_genesymbol_HPOid);
save HPO2GO_Files/HPO_CAFA2_training_variables.mat CAFA2_HPO_training_UniProtid CAFA2_HPO_training_HPOid CAFA2_HPO_training_UniProtid_unique CAFA2_HPO_training_UniProtid_genesymbol CAFA2_HPO_training_UniProtid_onlywithgenesym CAFA2_HPO_training_genesymbol_onlywithgenesym CAFA2_HPO_training_HPOid_onlywithgenesym CAFA2_HPO_training_annot_genesymbol_HPOid CAFA2_HPO_training_annot_genesymbol_HPOid_unique -v7
CAFA2_HPO_training_annot_genesymbol_unique=unique(CAFA2_HPO_training_annot_genesymbol_HPOid_unique(:,1));
[GO_UniProt_acc_all,GO_gene_symbol_all,GO_term_id_all,GO_term_evid_all]=textread('HPO2GO_Files/GOA_UniProt_human_protein_annotation_2014_01.txt', '%s %s %s %s', 'delimiter', '\t');
ind_IEA=find(strcmp(GO_term_evid_all,'IEA')==1);
GO_annot_manual_human_all=[GO_gene_symbol_all GO_term_id_all];
GO_annot_manual_human_all(ind_IEA,:)=[];
GO_annot_manual_human_all=uniqueRowsCA(GO_annot_manual_human_all);
save HPO2GO_Files/HPO_test_GO_annotation_all.mat GO_annot_manual_human_all -v7
GO_annot_manual_human_all_addcol=[GO_gene_symbol_all GO_term_id_all GO_term_evid_all];
GO_annot_manual_human_all_addcol(ind_IEA,:)=[];
GO_annot_manual_human_all_addcol=uniqueRowsCA(GO_annot_manual_human_all_addcol);
save HPO2GO_Files/HPO_test_GO_annotation_all_addcol.mat GO_annot_manual_human_all_addcol -v7
[Lia,Locb]=ismember(GO_annot_manual_human_all(:,1),CAFA2_HPO_training_annot_genesymbol_unique);
CAFA2_GO_annot_manual_human=GO_annot_manual_human_all(Lia==1,:);
save HPO2GO_Files/CAFA2_HPO_test_GO_annotation.mat CAFA2_GO_annot_manual_human -v7
to=0;
CAFA2_HPO_GO_mapping_ind=zeros(2000000,2);
for i=1:length(CAFA2_HPO_training_annot_genesymbol_unique);
disp(['Mapping HPO terms with GO terms with gene #: ', num2str(i), ' / ', num2str(length(CAFA2_HPO_training_annot_genesymbol_unique))])
[Lia,Locb]=ismember(CAFA2_HPO_training_annot_genesymbol_HPOid_unique(:,1),CAFA2_HPO_training_annot_genesymbol_unique(i,1));
[Lia2,Locb2]=ismember(CAFA2_GO_annot_manual_human(:,1),CAFA2_HPO_training_annot_genesymbol_unique(i,1));
if sum(Lia2)>0
siz=sum(Lia)*sum(Lia2);
[A,B]=meshgrid(find(Lia==1),find(Lia2==1));
c=cat(2,A',B');
d=reshape(c,[],2);
CAFA2_HPO_GO_mapping_ind(to+1:to+siz,:)=d;
to=to+siz;
end
end
CAFA2_HPO_GO_mapping_ind(CAFA2_HPO_GO_mapping_ind(:,1)==0,:)=[];
CAFA2_HPO_GO_mapping_terms=CAFA2_HPO_training_annot_genesymbol_HPOid_unique(CAFA2_HPO_GO_mapping_ind(:,1),2);
CAFA2_HPO_GO_mapping_terms(:,2)=CAFA2_GO_annot_manual_human(CAFA2_HPO_GO_mapping_ind(:,2),2);
save HPO2GO_Files/CAFA2_HPO_GO_mapping_terms.mat CAFA2_HPO_GO_mapping_terms -v7
[CAFA2_HPO_GO_mapping_terms_unique,I,J]=uniqueRowsCA(CAFA2_HPO_GO_mapping_terms);
CAFA2_HPO_GO_mapping_terms_freq=sort(J);
CAFA2_HPO_GO_mapping_terms_pair_hist=hist(CAFA2_HPO_GO_mapping_terms_freq,0.5:1:max(CAFA2_HPO_GO_mapping_terms_freq)+0.5);
CAFA2_HPO_GO_mapping_terms_pair_hist=CAFA2_HPO_GO_mapping_terms_pair_hist(1,1:end-1)';
save HPO2GO_Files/CAFA2_HPO_GO_mapping_terms_unique.mat CAFA2_HPO_GO_mapping_terms_unique -v7
save HPO2GO_Files/CAFA2_HPO_GO_mapping_terms_pair_hist.mat CAFA2_HPO_GO_mapping_terms_pair_hist -v7
[CAFA2_HPO_terms_unique,~,N]=unique(CAFA2_HPO_training_annot_genesymbol_HPOid_unique(:,2));
CAFA2_HPO_terms_annot_hist=hist(N,0.5:1:max(N)+0.5);
CAFA2_HPO_terms_annot_hist=CAFA2_HPO_terms_annot_hist(1,1:end-1)';
save HPO2GO_Files/CAFA2_HPO_terms_unique.mat CAFA2_HPO_terms_unique -v7
save HPO2GO_Files/CAFA2_HPO_terms_annot_hist.mat CAFA2_HPO_terms_annot_hist -v7
[CAFA2_GO_terms_unique,~,N]=unique(CAFA2_GO_annot_manual_human(:,2));
CAFA2_GO_terms_annot_hist=hist(N,0.5:1:max(N)+0.5);
CAFA2_GO_terms_annot_hist=CAFA2_GO_terms_annot_hist(1,1:end-1)';
save HPO2GO_Files/CAFA2_GO_terms_unique.mat CAFA2_GO_terms_unique -v7
save HPO2GO_Files/CAFA2_GO_terms_annot_hist.mat CAFA2_GO_terms_annot_hist -v7
[~,CAFA2_HPO_GO_mapping_unique_array_ind]=ismember(CAFA2_HPO_GO_mapping_terms_unique(:,1),CAFA2_HPO_terms_unique);
[~,CAFA2_HPO_GO_mapping_unique_array_ind(:,2)]=ismember(CAFA2_HPO_GO_mapping_terms_unique(:,2),CAFA2_GO_terms_unique);
CAFA2_HPO_GO_mapping_sematic_sim_high_det=zeros(length(CAFA2_HPO_GO_mapping_terms_unique),5);
for i=1:length(CAFA2_HPO_GO_mapping_terms_unique);
disp(['Calculating the semantic similarity between the HPO ang GO term pair #: ', num2str(i), ' / ', num2str(length(CAFA2_HPO_GO_mapping_terms_unique))])
t1=CAFA2_HPO_GO_mapping_terms_pair_hist(i,1);
t2=CAFA2_HPO_terms_annot_hist(CAFA2_HPO_GO_mapping_unique_array_ind(i,1),1);
t3=CAFA2_GO_terms_annot_hist(CAFA2_HPO_GO_mapping_unique_array_ind(i,2),1);
CAFA2_HPO_GO_mapping_sematic_sim_high_det(i,1:5)=[i (2*t1)/(t2+t3) t1 t2 t3]; % columns: indice of mapping, semantic similarity of the mapped terms, no of co-annotation of the mapped terms on different genes, total no of annotation of the mapped HPO term on different genes, total no of annotation of the mapped GO term on different genes
end
save HPO2GO_Files/CAFA2_HPO_GO_mapping_sematic_sim_high_det.mat CAFA2_HPO_GO_mapping_sematic_sim_high_det -v7
% (using the parameters: n>=2 and S>=0.1 as previously obtained from randomization test)
n=2;
S=0.1;
high_det_thres=CAFA2_HPO_GO_mapping_sematic_sim_high_det(CAFA2_HPO_GO_mapping_sematic_sim_high_det(:,2)>=S,:);
high_det_thres=high_det_thres(high_det_thres(:,3)>=n,:);
CAFA2_HPO_GO_selected_mappings=CAFA2_HPO_GO_mapping_terms_unique(high_det_thres(:,1),:);
CAFA2_HPO_GO_selected_mappings(:,3)=num2cell(CAFA2_HPO_GO_mapping_sematic_sim_high_det(high_det_thres(:,1),2));
save HPO2GO_Files/CAFA2_HPO_GO_selected_mappings.mat CAFA2_HPO_GO_selected_mappings -v7
length(CAFA2_HPO_GO_selected_mappings)
length(unique(CAFA2_HPO_GO_selected_mappings(:,1)))
length(unique(CAFA2_HPO_GO_selected_mappings(:,2)))
% Predicting HPO terms for CAFA2 human target proteins:
% (the variable containing the ground-truth / benchmark set with respective HPO annotations: CAFA2_HPO_ground_annot_CAFAid_genesymbol_HPOid)
load HPO2GO_Files/CAFA2_HPO_test_GO_annotation_all.mat
load HPO2GO_Files/CAFA2_HPO_GO_selected_mappings.mat
load HPO2GO_Files/CAFA2_HPO_GO_mapping_terms_unique.mat
mapGO_unique=unique(CAFA2_HPO_GO_selected_mappings(:,2));
[~,Locb0]=ismember(CAFA2_HPO_GO_selected_mappings(:,2),mapGO_unique);
[Lia,Locb]=ismember(GO_annot_manual_human_all(:,2),mapGO_unique);
to=0;
CAFA2_HPO_predictions=cell(2000000,3);
for i=1:length(mapGO_unique);
disp(['Predicting HPO terms for the mapped GO term #: ', num2str(i), ' / ', num2str(length(mapGO_unique))])
genesymbol_temp=GO_annot_manual_human_all(Locb==i,1);
HPO_temp=CAFA2_HPO_GO_selected_mappings(Locb0==i,1);
score_temp=CAFA2_HPO_GO_selected_mappings(Locb0==i,3);
if sum(Lia)>0
siz=length(genesymbol_temp)*length(HPO_temp);
[A,B]=meshgrid(1:length(genesymbol_temp),1:length(HPO_temp));
c=cat(2,A',B');
d=reshape(c,[],2);
CAFA2_HPO_predictions(to+1:to+siz,1)=genesymbol_temp(d(:,1),1);
CAFA2_HPO_predictions(to+1:to+siz,2)=HPO_temp(d(:,2),1);
CAFA2_HPO_predictions(to+1:to+siz,3)=score_temp(d(:,2),1);
to=to+siz;
end
end
CAFA2_HPO_predictions(cellfun(@isempty,CAFA2_HPO_predictions(:,1))==1,:)=[];
[CAFA2_HPO_predictions_un,I,C]=uniqueRowsCA(CAFA2_HPO_predictions(:,1:2));
% score_unique=zeros(length(CAFA2_HPO_predictions_un),1); % Alternative 1) Extremely slow
% for i=1:length(CAFA2_HPO_predictions_un)
% disp(['Calculating the max score for the prediction #: ', num2str(i), ' / ', num2str(length(CAFA2_HPO_predictions_un))])
% score_unique(i,1)=max(cell2mat(CAFA2_HPO_predictions(C==i,3)));
% end
% score=cell2mat(CAFA2_HPO_predictions(:,3));
% score_unique=arrayfun(@(x) max(score(C==x,1)), 1:max(C)); - Alternative 2) Slow
score=cell2mat(CAFA2_HPO_predictions(:,3));
score_unique=splitapply(@max,score,C); % Alternative 3) Very fast but requires Matlab 2017b
CAFA2_HPO_predictions_un(:,3)=num2cell(score_unique);
CAFA2_HPO_predictions=CAFA2_HPO_predictions_un;
CAFA2_HPO_predictions(ismember(CAFA2_HPO_predictions(:,1),'2xchrna4-3xchrnb2_human')==1,1)=cellstr('CHRNA4');
CAFA2_HPO_predictions(ismember(CAFA2_HPO_predictions(:,1),'3xchrna4-2xchrnb2_human')==1,1)=cellstr('CHRNA4');
load HPO2GO_Files/CAFA2_Targets_human_all_mappings.mat
mapsymbol_unique=unique(CAFA2_HPO_predictions(:,1));
[Lia0,Locb0]=ismember(CAFA2_HPO_predictions(:,1),mapsymbol_unique);
[Lia,Locb]=ismember(mapsymbol_unique,CAFA2_Targets_human_all_mappings(:,4));
Locb(Locb==0,1)=length(CAFA2_Targets_human_all_mappings)+1;
CAFA2_Targets_human_all_mappings(end+1,:)=cellstr(' ');
mapCAFAid_unique=CAFA2_Targets_human_all_mappings(Locb,1);
CAFA2_HPO_predictions_CAFAid_genesymbol_HPOid_sco=mapCAFAid_unique(Locb0,1);
CAFA2_HPO_predictions_CAFAid_genesymbol_HPOid_sco(:,2:4)=CAFA2_HPO_predictions;
save HPO2GO_Files/CAFA2_HPO_predictions_CAFAid_genesymbol_HPOid_sco.mat CAFA2_HPO_predictions_CAFAid_genesymbol_HPOid_sco -v7
CAFA2_pred_eval_save=CAFA2_HPO_predictions_CAFAid_genesymbol_HPOid_sco;
CAFA2_pred_eval_save(cellfun(@isempty,CAFA2_pred_eval_save(:,1))==1,:)=[];
CAFA2_pred_eval_save134=CAFA2_pred_eval_save(:,[1 3 4]);
CAFA2_pred_eval_save_txt=CAFA2_pred_eval_save134';
fid=fopen('HPO2GO_Files/CAFA2_HPO_target_predictions.txt', 'w');
fprintf(fid, '%s\t%s\t%.4f\n', CAFA2_pred_eval_save_txt{:});
fclose(fid);
CAFA2_HPO_target_predictions=CAFA2_pred_eval_save(:,[1 3 4]);
save HPO2GO_Files/CAFA2_HPO_target_predictions.mat CAFA2_HPO_target_predictions -v7
% Performance test on CAFA2 targets using propagated HPO annotations and GO annotation with all evidence codes (HPOprop2GOall)
% Propagating the HPO annotations to the root:
[CAFA2_HPO_training_UniProtid,CAFA2_HPO_training_HPOid]=textread('CAFA2/CAFA2_Supplementary_data/data/HPO-t0/hpoa.hp', '%s %s', 'delimiter', '\t');
CAFA2_HPO_training=[CAFA2_HPO_training_UniProtid CAFA2_HPO_training_HPOid];
CAFA2_HPO_training_unique=uniqueRowsCA(CAFA2_HPO_training);
CAFA2_HPO_training_UniProtid_unique=unique(CAFA2_HPO_training_UniProtid);
CAFA2_HPO_training_HPOid_unique=unique(CAFA2_HPO_training_HPOid);
ont=pfp_ontbuild('CAFA2/CAFA2-master/ontology/hpo_v810-17-SEP-2013.obo');
term_list=cellstr(vertcat(ont.term.id));
[Lia,Locb]=ismember(CAFA2_HPO_training_HPOid,term_list);
[Lia2,Locb2]=ismember(CAFA2_HPO_training_UniProtid,CAFA2_HPO_training_UniProtid_unique);
source_annot_mat=zeros(length(CAFA2_HPO_training_UniProtid_unique),length(term_list));
row_nonz=Locb2(Locb>0);
col_nonz=Locb(Locb>0);
for i=1:length(row_nonz);
disp(['Ind: ', num2str(i), ' / ', num2str(length(row_nonz))])
source_annot_mat(row_nonz(i,1),col_nonz(i,1))=1;
end
source_annot_mat_log=logical(source_annot_mat);
A=pfp_annotprop(ont.DAG, source_annot_mat_log);
[A_ind_row,A_ind_col]=find(A==1);
CAFA2_HPO_training_prop=CAFA2_HPO_training_UniProtid_unique(A_ind_row,1);
CAFA2_HPO_training_prop(:,2)=term_list(A_ind_col,1);
CAFA2_HPO_training_prop(strcmp(CAFA2_HPO_training_prop(:,2),'HP:0000001')==1,:)=[];
CAFA2_HPO_training_propagated=vertcat(CAFA2_HPO_training_prop,CAFA2_HPO_training);
CAFA2_HPO_training_propagated=uniqueRowsCA(CAFA2_HPO_training_propagated);
CAFA2_HPO_training_propagated_unique=unique(CAFA2_HPO_training_propagated(:,1));
% (download the uniprot acc, entry name, gene symbol for the proteins in 'CAFA2_HPO_training_propagated_unique' as gene_list.txt)
[CAFA2_HPO_training_propagated_unique_UniProtID,CAFA2_HPO_training_propagated_unique_entry_name,CAFA2_HPO_training_propagated_unique_genesymbol]=textread('HPO2GO_Files/gene_list.txt', '%s %s %s', 'delimiter', '\t', 'headerlines', 1);
[Lia,Locb]=ismember(CAFA2_HPO_training_propagated(:,1),CAFA2_HPO_training_propagated_unique_UniProtID);
CAFA2_HPO_training_propagated=CAFA2_HPO_training_propagated(Lia==1,:);
CAFA2_HPO_training_propagated(:,3)=CAFA2_HPO_training_propagated_unique_genesymbol(Locb(Lia==1,1),1);
save HPO2GO_Files/CAFA2_HPO_training_propagated.mat CAFA2_HPO_training_propagated -v7
CAFA2_HPO_training_propagated_txt=CAFA2_HPO_training_propagated';
fid=fopen('HPO2GO_Files/CAFA2_HPO_training_propagated.txt', 'w');
fprintf(fid, '%s\t%s\t%s\n', CAFA2_HPO_training_propagated_txt{:});
fclose(fid);
% Generating the GO annotation arrays:
load HPO2GO_Files/CAFA2_HPO_training_propagated.mat
load HPO2GO_Files/CAFA2_Targets_human_all_mappings.mat
[GO_UniProt_acc_all,GO_gene_symbol_all,GO_term_id_all,GO_term_evid_all]=textread('HPO2GO_Files/GOA_UniProt_human_protein_annotation_2014_01.txt', '%s %s %s %s', 'delimiter', '\t');
GO_annot_manual_human_all=[GO_gene_symbol_all GO_term_id_all];
GO_annot_manual_human_all=uniqueRowsCA(GO_annot_manual_human_all);
save HPO2GO_Files/HPOprop2GOall_HPO_test_GO_annotation_all.mat GO_annot_manual_human_all -v7
GO_annot_manual_human_all_addcol=[GO_gene_symbol_all GO_term_id_all GO_term_evid_all];
GO_annot_manual_human_all_addcol=uniqueRowsCA(GO_annot_manual_human_all_addcol);
save HPO2GO_Files/HPOprop2GOall_HPO_test_GO_annotation_all_addcol.mat GO_annot_manual_human_all_addcol -v7
benchmark_hpo=pfp_loaditem('CAFA2/CAFA2-master/benchmark/lists/hpo_HUMAN_type1.txt', 'char');
[Lia,Locb]=ismember(CAFA2_Targets_human_all_mappings(:,1),benchmark_hpo);
CAFA2_Targets_human_all_mappings_CAFA2hpobench=CAFA2_Targets_human_all_mappings(Lia==1,:);
save HPO2GO_Files/HPOprop2GOall_CAFA2_Targets_human_all_mappings_CAFA2hpobench.mat CAFA2_Targets_human_all_mappings_CAFA2hpobench -v7
[Lia,Locb]=ismember(GO_annot_manual_human_all(:,1),CAFA2_Targets_human_all_mappings_CAFA2hpobench(:,4));
GO_annot_manual_human_all_CAFA2hpobench=GO_annot_manual_human_all(Lia==1,:);
save HPO2GO_Files/HPOprop2GOall_HPO_test_GO_annotation_all_CAFA2hpobench.mat GO_annot_manual_human_all_CAFA2hpobench -v7
[HPOprop_UniProt_id,HPOprop_ID,HPOprop_gene_symbol]=textread('HPO2GO_Files/CAFA2_HPO_training_propagated.txt', '%s %s %s', 'delimiter', '\t');
HPOprop_gene_annotation=[HPOprop_UniProt_id HPOprop_gene_symbol HPOprop_ID];
HPOprop_gene_annotation=uniqueRowsCA(HPOprop_gene_annotation);
save HPO2GO_Files/HPOprop2GOall_HPOprop_test_HPOprop_gene_annotation.mat HPOprop_gene_annotation -v7
HPOprop_gene_symbol_unique=unique(HPOprop_gene_annotation(:,2));
% Selecting the GO annotations for the HPOprop annotated protein list:
[Lia,Locb]=ismember(GO_annot_manual_human_all(:,1),HPOprop_gene_symbol_unique);
GO_annot_manual_human=GO_annot_manual_human_all(Lia==1,:);
save HPO2GO_Files/HPOprop2GOall_HPOprop_test_GO_annotation.mat GO_annot_manual_human -v7
% Generating the HPOprop and GO term pairs:
to=0;
HPOprop_GO_mapping_ind=zeros(10000000,2);
for i=1:length(HPOprop_gene_symbol_unique);
disp(['Mapping HPOprop terms with GO terms with gene #: ', num2str(i), ' / ', num2str(length(HPOprop_gene_symbol_unique))])
[Lia,Locb]=ismember(HPOprop_gene_annotation(:,2),HPOprop_gene_symbol_unique(i,1));
[Lia2,Locb2]=ismember(GO_annot_manual_human(:,1),HPOprop_gene_symbol_unique(i,1));
if sum(Lia2)>0
siz=sum(Lia)*sum(Lia2);
[A,B]=meshgrid(find(Lia==1),find(Lia2==1));
c=cat(2,A',B');
d=reshape(c,[],2);
HPOprop_GO_mapping_ind(to+1:to+siz,:)=d;
to=to+siz;
end
end
HPOprop_GO_mapping_ind(HPOprop_GO_mapping_ind(:,1)==0,:)=[];
HPOprop_GO_mapping_terms=HPOprop_gene_annotation(HPOprop_GO_mapping_ind(:,1),3);
HPOprop_GO_mapping_terms(:,2)=GO_annot_manual_human(HPOprop_GO_mapping_ind(:,2),2);
save HPO2GO_Files/HPOprop2GOall_HPOprop_GO_mapping_terms.mat HPOprop_GO_mapping_terms -v7
% Calculating the co-occurrence similarity between ontology terms:
[HPOprop_GO_mapping_terms_unique,I,J]=uniqueRowsCA(HPOprop_GO_mapping_terms);
HPOprop_GO_mapping_terms_freq=sort(J);
HPOprop_GO_mapping_terms_pair_hist=hist(HPOprop_GO_mapping_terms_freq,0.5:1:max(HPOprop_GO_mapping_terms_freq)+0.5);
HPOprop_GO_mapping_terms_pair_hist=HPOprop_GO_mapping_terms_pair_hist(1,1:end-1)';
save HPO2GO_Files/HPOprop2GOall_HPOprop_GO_mapping_terms_unique.mat HPOprop_GO_mapping_terms_unique -v7
save HPO2GO_Files/HPOprop2GOall_HPOprop_GO_mapping_terms_pair_hist.mat HPOprop_GO_mapping_terms_pair_hist -v7
[HPOprop_terms_unique,~,N]=unique(HPOprop_gene_annotation(:,3));
HPOprop_terms_annot_hist=hist(N,0.5:1:max(N)+0.5);
HPOprop_terms_annot_hist=HPOprop_terms_annot_hist(1,1:end-1)';
save HPO2GO_Files/HPOprop2GOall_HPOprop_terms_unique.mat HPOprop_terms_unique -v7
save HPO2GO_Files/HPOprop2GOall_HPOprop_terms_annot_hist.mat HPOprop_terms_annot_hist -v7
[GO_terms_unique,~,N]=unique(GO_annot_manual_human(:,2));
GO_terms_annot_hist=hist(N,0.5:1:max(N)+0.5);
GO_terms_annot_hist=GO_terms_annot_hist(1,1:end-1)';
save HPO2GO_Files/HPOprop2GOall_GO_terms_unique.mat GO_terms_unique -v7
save HPO2GO_Files/HPOprop2GOall_GO_terms_annot_hist.mat GO_terms_annot_hist -v7
[~,HPOprop_GO_mapping_unique_array_ind]=ismember(HPOprop_GO_mapping_terms_unique(:,1),HPOprop_terms_unique);
[~,HPOprop_GO_mapping_unique_array_ind(:,2)]=ismember(HPOprop_GO_mapping_terms_unique(:,2),GO_terms_unique);
HPOprop_GO_mapping_sematic_sim_high_det=zeros(length(HPOprop_GO_mapping_terms_unique),5);
for i=1:length(HPOprop_GO_mapping_terms_unique);
disp(['Calculating the semantic similarity between the HPOprop ang GO term pair #: ', num2str(i), ' / ', num2str(length(HPOprop_GO_mapping_terms_unique))])
t1=HPOprop_GO_mapping_terms_pair_hist(i,1);
t2=HPOprop_terms_annot_hist(HPOprop_GO_mapping_unique_array_ind(i,1),1);
t3=GO_terms_annot_hist(HPOprop_GO_mapping_unique_array_ind(i,2),1);
HPOprop_GO_mapping_sematic_sim_high_det(i,1:5)=[i (2*t1)/(t2+t3) t1 t2 t3]; % columns: indice of mapping, semantic similarity of the mapped terms, # of co-annotated genes, total # of annotation of the mapped HPOprop term on different genes, total # of annotation of the mapped GO term on different genes
end
save HPO2GO_Files/HPOprop2GOall_HPOprop_GO_mapping_sematic_sim_high_det.mat HPOprop_GO_mapping_sematic_sim_high_det -v7
HPOprop_GO_Raw_Mapping_merged=[HPOprop_GO_mapping_terms_unique num2cell(HPOprop_GO_mapping_sematic_sim_high_det(:,2:end))];
save HPO2GO_Files/HPOprop2GOall_HPOprop_GO_Raw_Mapping_merged.mat HPOprop_GO_Raw_Mapping_merged -v7
HPOprop_GO_Raw_Mapping_merged_txt=HPOprop_GO_Raw_Mapping_merged';
fid=fopen('HPO2GO_Files/HPOprop2GOall_HPOprop_GO_Raw_Mapping_merged.txt', 'w');
fprintf(fid, '%s\t%s\t%.4f\t%d\t%d\t%d\n', HPOprop_GO_Raw_Mapping_merged_txt{:});
fclose(fid);
% (large-scale performance test with different parameters)
load HPO2GO_Files/HPOprop2GOall_HPOprop_GO_mapping_sematic_sim_high_det.mat
load HPO2GO_Files/HPOprop2GOall_HPOprop_GO_mapping_terms_unique.mat
load HPO2GO_Files/HPO_test_GO_annotation_all_CAFA2hpobench.mat
load CAFA2/CAFA2-master/ontology/HPO.mat
load CAFA2/CAFA2-master/benchmark/groundtruth/hpoa.mat
n_mat=[2 5 10 20 30 40 50 60 70 80 90 100 110 120 130 140 145 150 155 160 165 170 175 180 185 190 195 200 210 220 230 250 250 300 400 500];
S_mat=0:0.01:1;
for j=1:length(n_mat)
disp(['Analyzing the performance for n: ', num2str(j), ' / ', num2str(length(n_mat))])
load HPO2GO_Files/CAFA2_Targets_human_all_mappings.mat
n=n_mat(1,j);
S=0.05;
high_det_thres=HPOprop_GO_mapping_sematic_sim_high_det(HPOprop_GO_mapping_sematic_sim_high_det(:,2)>=S,:);
high_det_thres=high_det_thres(high_det_thres(:,3)>=n,:);
HPOprop2GOall_Mapping=HPOprop_GO_mapping_terms_unique(high_det_thres(:,1),:);
HPOprop2GOall_Mapping(:,3:4)=num2cell(HPOprop_GO_mapping_sematic_sim_high_det(high_det_thres(:,1),2:3));
mapGO_unique=unique(HPOprop2GOall_Mapping(:,2));
[~,Locb0]=ismember(HPOprop2GOall_Mapping(:,2),mapGO_unique);
[Lia,Locb]=ismember(GO_annot_manual_human_all_CAFA2hpobench(:,2),mapGO_unique);
to=0;
CAFA2_HPOprop_predictions=cell(15000000,3);
for i=1:length(mapGO_unique)
disp(['Predicting HPO terms for the mapped GO term #: ', num2str(i), ' / ', num2str(length(mapGO_unique))])
genesymbol_temp=GO_annot_manual_human_all_CAFA2hpobench(Locb==i,1);
HPOprop_temp=HPOprop2GOall_Mapping(Locb0==i,1);
score_temp=HPOprop2GOall_Mapping(Locb0==i,3);
if sum(Lia)>0
siz=length(genesymbol_temp)*length(HPOprop_temp);
[A,B]=meshgrid(1:length(genesymbol_temp),1:length(HPOprop_temp));
c=cat(2,A',B');
d=reshape(c,[],2);
CAFA2_HPOprop_predictions(to+1:to+siz,1)=genesymbol_temp(d(:,1),1);
CAFA2_HPOprop_predictions(to+1:to+siz,2)=HPOprop_temp(d(:,2),1);
CAFA2_HPOprop_predictions(to+1:to+siz,3)=score_temp(d(:,2),1);
to=to+siz;
end
end
CAFA2_HPOprop_predictions(cellfun(@isempty,CAFA2_HPOprop_predictions(:,1))==1,:)=[];
[CAFA2_HPOprop_predictions_un,I,C]=uniqueRowsCA(CAFA2_HPOprop_predictions(:,1:2));
score=cell2mat(CAFA2_HPOprop_predictions(:,3));
score_unique=splitapply(@max,score,C); % Alternative 3) Very fast but requires Matlab 2017b
CAFA2_HPOprop_predictions_un(:,3)=num2cell(score_unique);