[4fba4e]: / network / CommGeneticsLoader.java

Download this file

785 lines (673 with data), 25.4 kB

  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
package network;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import GraphAlgorithm.ComSearch;
import util.CollectionsEx;
import util.DCNOMIMUMLSIDmap;
/**
* Provides methods for creating a bipartite network and write it to a network file
* @author zhengc
*
*/
public class CommGeneticsLoader {
public static HashSet<String> entry_set = new HashSet<String>();
public static HashSet<String> disease_set = new HashSet<String>();
public static HashSet<String> gene_set = new HashSet<String>();
public static HashSet<String> DMN_set = new HashSet<String>();
public static HashSet<String> DCN_set = new HashSet<String>();
public static List<String> entry_list = new ArrayList<String>();
public static List<String> disease_list = new ArrayList<String>();
public static List<String> gene_list = new ArrayList<String>();
public static List<String> DMN_list = new ArrayList<String>();
public static List<String> DCN_list = new ArrayList<String>();
public static int num_gene = 0;
public static int num_dmn;
public static int num_dcn;
public static int num_disease;
public static Map<Integer, Integer> dis_gene = new HashMap<Integer, Integer>();
public static Map<String, Integer> entry_index = new HashMap<String, Integer>();
public static Map<Integer, String> index_entry = new HashMap<Integer, String>();
public static Map<String, String> idnamemap = new HashMap<String, String>();
public static Map<String, String> nameidmap = new HashMap<String, String>();
public static Map<String, String> OMIMidnamemap = new HashMap<String, String>();
public static Map<String, String> OMIMnameidmap = new HashMap<String, String>();
public static HashSet<String> soc_set = new HashSet<String>();
public static Map<String, String> umlssocmap = new HashMap<String, String>();
public static Map<String, Integer> soc_idx = new HashMap<String, Integer>();
public static Map<Integer, String> idx_soc = new HashMap<Integer,String>();
public static final double P = 0.85;
/**
* Read DCN net and get DCN disease list
* @param filename DCN net file
* @throws IOException
*/
public static void readCommNet(String filename) throws IOException{
// get all unique disease set
BufferedReader br = new BufferedReader(new FileReader(new File(filename)));
String line = br.readLine();
while ((line = br.readLine()) != null) {
String disease = line.split("\\|")[0];
DCN_set.add(disease);
}
br.close();
DCN_list = util.CollectionsEx.setToList(DCN_set);
num_dcn = DCN_set.size();
System.out.println("number of DCN: " + num_dcn);
}
/**
* Write a map from DCN disease UMLS to disease name
* @param imput map file from disease UMLS to name
* @param output a file to be written
* @throws IOException
*/
public static void writeDCNIdName(String imput, String output) throws IOException {
Map<String, String> idnamemap = new HashMap<String, String>();
BufferedReader br = new BufferedReader(new FileReader(new File(imput)));
String line = br.readLine();
while ((line = br.readLine()) != null) {
String disease_id = line.split("\\|")[0];
String disease_name = line.split("\\|")[1];
if(!idnamemap.keySet().contains(disease_id)) {
idnamemap.put(disease_id, disease_name);
}
}
br.close();
BufferedWriter bw = new BufferedWriter(new FileWriter(new File(output)));
Set<String> ids = idnamemap.keySet();
List<String> id_list = util.CollectionsEx.setToList(ids);
Collections.sort(id_list);
for(String id : id_list) {
String name = idnamemap.get(id).replace("-- ", "");
bw.write(id + "|" + name + "\n");
}
bw.close();
}
/**
* Reads DMN to get DMN disease list
* @param filename DMN net file
* @throws IOException
*/
public static void readDMN(String filename) throws IOException{
// get all unique disease set
BufferedReader br = new BufferedReader(new FileReader(new File(filename)));
String line = br.readLine();
while ((line = br.readLine()) != null) {
String disease1 = line.split("\\|")[0];
DMN_set.add(disease1);
String disease2 = line.split("\\|")[1];
DMN_set.add(disease2);
}
br.close();
DMN_list = util.CollectionsEx.setToList(DMN_set);
num_dmn = DMN_set.size();
System.out.println("number of DMN: " + num_dmn);
}
/**
* Reads PPI to get gene list
* @param filename
* @throws IOException
*/
public static void readPPI(String filename) throws IOException{
BufferedReader br = new BufferedReader(new FileReader(new File(filename)));
String line = null;
while ((line=br.readLine()) != null) {
String gene = line.split("\\|")[0];
// System.out.println(2);
gene_set.add(gene);
}
br.close();
gene_list = util.CollectionsEx.setToList(gene_set);
num_gene = gene_set.size();
System.out.println("number of gene: " + num_gene);
}
/**
* Reads UMLS-SOC map file to get UMLS-SOC map
* @param filename
* @throws IOException
*/
public static void readUMLSSOC(String filename) throws IOException{
BufferedReader br = new BufferedReader(new FileReader(new File(filename)));
String line = null;
while ((line=br.readLine()) != null) {
String[] parts = line.split("\\$");
String umls = parts[0];
String soc = parts[8];
soc_set.add(soc);
umlssocmap.put(umls, soc);
}
br.close();
int m = 0;
for (String soc : soc_set) {
soc_idx.put(soc, m);
idx_soc.put(m, soc);
m++;
}
}
/**
* Creates entry index for all nodes
* @param entry_list
*/
public static void createIndex(List<String> entry_list) {
int m = 0;
for (String e : entry_list) {
if (!entry_index.containsKey(e)) {
entry_index.put(e, m);
index_entry.put(m, e);
m++;
}
}
System.out.println("Total nodes: " + entry_index.size());
System.out.println("--------");
}
/**
* Build a bipartite graph including DCN and PPI, additional DCN-OMIM disease mapping also included
* @param commnetfile DCN file
* @param ppifile PPI file
* @param disgenefile disease genetics file from OMIM
* @param dcn_omim mapping from DCN disease to OMIM disease
* @return a bipartite graph
* @throws IOException
*/
public static DisGraph createCommGeneticsGraph(String commnetfile,
String ppifile, String disgenefile, Map<String, List<String>> dcn_omim) throws IOException {
readCommNet(commnetfile);
readPPI(ppifile);
disease_set.addAll(DCN_set);
disease_list = util.CollectionsEx.setToList(disease_set);
entry_list.addAll(disease_list);
entry_list.addAll(gene_list);
createIndex(entry_list);
num_disease = disease_list.size();
int n = entry_index.size();
DisGraph cgg = new DisGraph(n);
// construct DCN net from network file
// Note: there are two type of network files, attention should be paid that one file contains
// additional abbreviation of SOC. Consequently, the second entry should be in column 6 instead 5
BufferedReader br1 = new BufferedReader(new FileReader(new File(commnetfile)));
String line1 = null;
while ((line1 = br1.readLine()) != null) {
String [] s = line1.split("\\|");
// System.out.println(s[0]);
// System.out.println(s[0]);
if (entry_index.containsKey(s[0]) && entry_index.containsKey(s[5])) {
int entry1 = entry_index.get(s[0]);
int entry2 = entry_index.get(s[5]);
// double score = Integer.parseInt(s[2]);
cgg.addEdge(entry1, entry2);
}
}
br1.close();
// Check if diagonal entry is 1
// for (int j=0; j<disease_list.size(); j++) {
// System.out.println(cgg.getNet().get(j, j));
// }
BufferedReader br2 = new BufferedReader(new FileReader(new File(ppifile)));
String line2 = null;
while ((line2 = br2.readLine()) != null) {
String [] s = line2.split("\\|");
// System.out.println(s[0]);
if (entry_index.containsKey(s[0]) && entry_index.containsKey(s[1])) {
int entry1 = entry_index.get(s[0]);
int entry2 = entry_index.get(s[1]);
// System.out.println(s[0] +" " + entry1);
// System.out.println(s[1] +" " + entry2);
// double score = Integer.parseInt(s[2]);
cgg.addEdge(entry1, entry2);
}
}
br2.close();
// Check if diagonal entry is 1
// for (int j=disease_list.size(); j<entry_list.size(); j++) {
// System.out.println(cgg.getNet().get(j, j));
// }
BufferedReader br3 = new BufferedReader(new FileReader(new File(disgenefile)));
String line3 = null;
Set<String> mappedset = new HashSet<>();
while ((line3 = br3.readLine()) != null) {
String [] s = line3.split("\\|");
// System.out.println(s[0]);
String disid = s[0];
String gene = s[1];
if (entry_index.containsKey(disid) && entry_index.containsKey(gene)) {
mappedset.add(disid);
int entry1 = entry_index.get(disid);
int entry2 = entry_index.get(gene);
// System.out.println(s[0] +" " + entry1);
// System.out.println(s[1] +" " + entry2);
// double score = Integer.parseInt(s[2]);
cgg.addEdge(entry1, entry2);
}
// add additional dcn_omim map
for (String id : dcn_omim.keySet()) {
List<String> omim_ids = dcn_omim.get(id);
if (!entry_index.containsKey(disid) && omim_ids.contains(disid)) {
disid = id; // update id
if (entry_index.containsKey(disid) && entry_index.containsKey(gene)) {
int entry1 = entry_index.get(disid);
int entry2 = entry_index.get(gene);
cgg.addEdge(entry1, entry2);
}
}
}
}
br3.close();
// Check if diagonal entry is 1
// for (int j=disease_list.size(); j<entry_list.size(); j++) {
// System.out.println(cgg.getNet().get(j, j));
// }
System.out.println("Total mapped disease: " + mappedset.size());
// for (int i=0; i<n; i++) {
// cgg.addEdge(i, i);
// }
return cgg;
}
/**
* Build a bipartite graph including DCN, DMN and PPI
* @param commnetfile DCN file
* @param dmnfile DMN file
* @param ppifile PPI file
* @param disgenefile disease genetics file from OMIM
* @return a bipartite graph
* @throws IOException
*/
public static DisGraph createCommGeneticsGraph(String commnetfile, String dmnfile,
String ppifile, String disgenefile) throws IOException {
readCommNet(commnetfile);
readDMN(dmnfile);
readPPI(ppifile);
disease_set.addAll(DCN_set);
disease_set.addAll(DMN_set);
disease_list = util.CollectionsEx.setToList(disease_set);
entry_list.addAll(disease_list);
entry_list.addAll(gene_list);
createIndex(entry_list);
num_disease = disease_list.size();
int n = entry_index.size();
DisGraph cgg = new DisGraph(n);
// System.out.println(n);
BufferedReader br1 = new BufferedReader(new FileReader(new File(commnetfile)));
String line1 = null;
while ((line1 = br1.readLine()) != null) {
String [] s = line1.split("\\|");
// System.out.println(s[0]);
// System.out.println(s[0]);
if (entry_index.containsKey(s[0]) && entry_index.containsKey(s[4])) {
int entry1 = entry_index.get(s[0]);
int entry2 = entry_index.get(s[4]);
// double score = Integer.parseInt(s[2]);
cgg.addEdge(entry2, entry1);
}
}
br1.close();
BufferedReader br2 = new BufferedReader(new FileReader(new File(dmnfile)));
String line2 = null;
while ((line2 = br2.readLine()) != null) {
String [] s = line2.split("\\|");
// System.out.println(s[0]);
// System.out.println(s[0]);
if (entry_index.containsKey(s[0]) && entry_index.containsKey(s[1])) {
int entry1 = entry_index.get(s[0]);
int entry2 = entry_index.get(s[1]);
// double score = Integer.parseInt(s[2]);
cgg.addEdge(entry1, entry2);
}
}
br2.close();
BufferedReader br3 = new BufferedReader(new FileReader(new File(ppifile)));
String line3 = null;
while ((line3 = br3.readLine()) != null) {
String [] s = line3.split("\\|");
// System.out.println(s[0]);
if (entry_index.containsKey(s[0]) && entry_index.containsKey(s[1])) {
int entry1 = entry_index.get(s[0]);
int entry2 = entry_index.get(s[1]);
// System.out.println(s[0] +" " + entry1);
// System.out.println(s[1] +" " + entry2);
// double score = Integer.parseInt(s[2]);
cgg.addEdge(entry1, entry2);
}
}
br3.close();
BufferedReader br4 = new BufferedReader(new FileReader(new File(disgenefile)));
String line4 = null;
Set<String> mappedset = new HashSet<>();
while ((line4 = br4.readLine()) != null) {
String [] s = line4.split("\\|");
// System.out.println(s[0]);
String disid = s[0];
String gene = s[1];
if (entry_index.containsKey(disid) && entry_index.containsKey(gene)) {
mappedset.add(disid);
int entry1 = entry_index.get(disid);
int entry2 = entry_index.get(s[1]);
// System.out.println(s[0] +" " + entry1);
// System.out.println(s[1] +" " + entry2);
// double score = Integer.parseInt(s[2]);
cgg.addEdge(entry1, entry2);
}
}
br4.close();
System.out.println("Total mapped disease: " + mappedset.size());
for (int i=0; i<n; i++) {
cgg.addEdge(i, i);
}
return cgg;
}
/**
* Build a bipartite graph including DCN and PPI, extra mapping and DMN are optional
*
* @param commnetfile DCN file
* @param dmnfile DMN file
* @param ppifile PPI file
* @param disgenefile disease genetics file from OMIM
* @param dcn_omim mapping from DCN disease to OMIM disease
* @param dmn a flag to indicate if DMN will be included
* @param extra a flag to indicate if extra mapping will be included
* @return a bipartite graph
* @throws IOException
*/
public static DisGraph createCommGeneticsGraph(String commnetfile, String dmnfile,
String ppifile, String disgenefile, Map<String, List<String>> dcn_omim, Boolean dmn, Boolean extra) throws IOException {
readCommNet(commnetfile);
disease_set.addAll(DCN_set);
if(dmn) {
readDMN(dmnfile);
disease_set.addAll(DMN_set);
}
disease_list = util.CollectionsEx.setToList(disease_set);
readPPI(ppifile);
entry_list.addAll(disease_list);
entry_list.addAll(gene_list);
createIndex(entry_list);
num_disease = disease_list.size();
int n = entry_index.size();
DisGraph cgg = new DisGraph(n);
// System.out.println(n);
BufferedReader br1 = new BufferedReader(new FileReader(new File(commnetfile)));
String line1 = null;
while ((line1 = br1.readLine()) != null) {
String [] s = line1.split("\\|");
// System.out.println(s[0]);
// System.out.println(s[0]);
if (entry_index.containsKey(s[0]) && entry_index.containsKey(s[4])) {
int entry1 = entry_index.get(s[0]);
int entry2 = entry_index.get(s[4]);
// double score = Integer.parseInt(s[2]);
cgg.addEdge(entry2, entry1);
}
}
br1.close();
if(dmn) {
BufferedReader br2 = new BufferedReader(new FileReader(new File(dmnfile)));
String line2 = null;
while ((line2 = br2.readLine()) != null) {
String [] s = line2.split("\\|");
// System.out.println(s[0]);
// System.out.println(s[0]);
if (entry_index.containsKey(s[0]) && entry_index.containsKey(s[1])) {
int entry1 = entry_index.get(s[0]);
int entry2 = entry_index.get(s[1]);
// double score = Integer.parseInt(s[2]);
cgg.addEdge(entry1, entry2);
}
}
br2.close();
}
BufferedReader br3 = new BufferedReader(new FileReader(new File(ppifile)));
String line3 = null;
while ((line3 = br3.readLine()) != null) {
String [] s = line3.split("\\|");
// System.out.println(s[0]);
if (entry_index.containsKey(s[0]) && entry_index.containsKey(s[1])) {
int entry1 = entry_index.get(s[0]);
int entry2 = entry_index.get(s[1]);
// System.out.println(s[0] +" " + entry1);
// System.out.println(s[1] +" " + entry2);
// double score = Integer.parseInt(s[2]);
cgg.addEdge(entry1, entry2);
}
}
br3.close();
BufferedReader br4 = new BufferedReader(new FileReader(new File(disgenefile)));
String line4 = null;
Set<String> mappedset = new HashSet<>();
while ((line4 = br4.readLine()) != null) {
String [] s = line4.split("\\|");
// System.out.println(s[0]);
String disid = s[0];
String gene = s[1];
if (entry_index.containsKey(disid) && entry_index.containsKey(gene)) {
mappedset.add(disid);
int entry1 = entry_index.get(disid);
int entry2 = entry_index.get(gene);
// System.out.println(s[0] +" " + entry1);
// System.out.println(s[1] +" " + entry2);
// double score = Integer.parseInt(s[2]);
cgg.addEdge(entry1, entry2);
}
// Additional mapping according to biological meaning
// if (!entry_index.containsKey(disid) && extra) {
// for (String id : dcn_omim.keySet()) {
// List<String> omim_ids = dcn_omim.get(id);
// if (omim_ids.contains(disid)) {
// disid = id; // update id
// if (entry_index.containsKey(disid) && entry_index.containsKey(gene)) {
// int entry1 = entry_index.get(disid);
// int entry2 = entry_index.get(gene);
// cgg.addEdge(entry1, entry2);
// }
// }
// }
if(extra) {
for (String id : dcn_omim.keySet()) {
List<String> omim_ids = dcn_omim.get(id);
if (!entry_index.containsKey(disid) && omim_ids.contains(disid)) {
disid = id; // update id
if (entry_index.containsKey(disid) && entry_index.containsKey(gene)) {
int entry1 = entry_index.get(disid);
int entry2 = entry_index.get(gene);
cgg.addEdge(entry1, entry2);
}
}
}
}
}
br4.close();
System.out.println("Total mapped disease: " + mappedset.size());
for (int i=0; i<n; i++) {
cgg.addEdge(i, i);
}
return cgg;
}
public static DisGraph createCommGeneticsGraph(DisGraph dg, DisGraph pp,
Map<Integer, List<Integer>> dis_genelist) {
int N1 = dg.getNodes();
int N2 = pp.getNodes();
DisGraph cgg = new DisGraph(N1 + N2);
//add disease comorbidity network
for (int i=0; i<N1; i++) {
Set<Integer> neibors = dg.getNeibor(i).getKeys();
for (int neibor : neibors) {
cgg.addEdge(i, neibor);
}
}
//add protein-protein interaction network
for (int i=0; i<N2; i++) {
Set<Integer> neibors = pp.getNeibor(i).getKeys();
for (int neibor : neibors) {
int idx1 = i + N1;
int idx2 = neibor + N1;
cgg.addEdge(idx1, idx2);
}
}
//add disease-gene connection
for (int dis_idx: dis_genelist.keySet()) {
for (int gene_idx: dis_genelist.get(dis_idx)) {
cgg.addEdge(dis_idx, gene_idx + N1);
}
}
return cgg;
}
/**
* Creates a UMLS-name mapping
* @param mapfiles mapping file
* @throws IOException
*/
public static void createIdNameMap(List<String> mapfiles) throws IOException {
for (String mapfile : mapfiles) {
BufferedReader br = new BufferedReader(new FileReader(mapfile));
String line = null;
while((line = br.readLine()) != null){
String[] parts = line.split("\\|");
idnamemap.put(parts[0], parts[1].toLowerCase());
nameidmap.put(parts[1].toLowerCase(), parts[0]);
}
br.close();
}
}
/**
* Create UMLS-name mapping for OMIM
* @param mapfiles
* @throws IOException
*/
public static void createOMIMIdNameMap(List<String> mapfiles) throws IOException {
for (String mapfile : mapfiles) {
BufferedReader br = new BufferedReader(new FileReader(mapfile));
String line = null;
while((line = br.readLine()) != null){
String[] parts = line.split("\\|");
OMIMidnamemap.put(parts[1], parts[0].toLowerCase());
OMIMnameidmap.put(parts[0].toLowerCase(), parts[1]);
}
br.close();
}
}
/**
* Write the bipartite graph to a file, format is "node1|node2|score"
* @param cgg the bipartite file
* @param filename a file to be written
* @throws IOException
*/
private static void writeCommGeneticsNet(DisGraph cgg, String filename) throws IOException {
BufferedWriter bw = new BufferedWriter(new FileWriter(new File(filename)));
for (int i = 0; i < cgg.getNet().size(); i++) {
Set<Integer> sv = cgg.getNet().getKey(i);
for (int k : sv) {
String d1 = index_entry.get(i);
String d2 = index_entry.get(k);
double score = cgg.getNet().get(i, k);
bw.write(d1 + "|" + d2 + "|" + score + "|" + "\n");
}
}
bw.close();
}
public static void main(String[] args) throws IOException {
// #########################################################################
// ----------------------- Method 1: Build network from files --------------------
// #########################################################################
/*
* Create additional DCN_OMIM map for give disease
*/
// String DCN_dis = "dementia";
// String OMIM_pat = "alzheimer";
//
// DCNOMIMUMLSIDmap domim = new DCNOMIMUMLSIDmap(DCN_dis, OMIM_pat);
// Map<String, List<String>> dcn_omim = domim.getDCNOMIMUMLSIDmap();
//
// /*
// * Build the bipartite network
// */
//// String commnetfile = "/Users/zhengc/Projects/AD_comorbidity/data/fares_comm_net_conf_ISMB_final_public.txt";
//// String dmnfile = "/Users/zhengc/Projects/AD_comorbidity/data/dmn_dm.txt";
//// String ppifile = "/Users/zhengc/Projects/AD_comorbidity/data/gene_gene_string_cut.txt";
//// String disgenefile = "/Users/zhengc/workspace/FARES_final/data/OMIM/mapped_OMIM/OMIM_disease_gene_umls_id_diso";
//
// String commnetfile = "/Users/zhengc/workspace/FARES_final/analysis/network/DCN/fares_comm_net_lift_final_abbr.txt";;
//// String dmnfile = "/Users/zhengc/workspace/FARES_final/analysis/AD_comorbidity/data/dmn_dm.txt";
// String ppifile = "/Users/zhengc/workspace/FARES_final/analysis/AD_comorbidity/data/gene_gene_string_cut.txt";
// String disgenefile = "/Users/zhengc/workspace/FARES_final/data/OMIM/mapped_OMIM/OMIM_disease_gene_umls_id_diso";
//
//
// DisGraph cgg = null;
// try {
//// cgg = CommGeneticsLoader.createCommGeneticsGraph(commnetfile, dmnfile, ppifile, disgenefile, dcn_omim);
// cgg = CommGeneticsLoader.createCommGeneticsGraph(commnetfile, ppifile, disgenefile, dcn_omim);
// System.out.println("Total edges: " + cgg.getEdges());
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
//
//
//
// /* Write commgenetics file */
// String netfile = "/Users/zhengc/workspace/FARES_final/analysis/network/DCN_PPI/DCN_PPI_net_lift.txt";
// writeCommGeneticsNet(cgg, netfile);
//
// String disUMLS_name_file = "/Users/zhengc/workspace/FARES_final/analysis/network/DCN_PPI/disUMLS_name_lift.txt";
// writeDCNIdName(commnetfile, disUMLS_name_file);
//
// String dcnmapfile = "/Users/zhengc/workspace/FARES_final/data/FARES/map/term_umls_id_diso";
// util.DCNOMIMUMLSIDmap.createDCNIdNameMap(dcnmapfile);
// String diseaseid = util.DCNOMIMUMLSIDmap.dcnnameidmap.get(DCN_dis);
// System.out.println(diseaseid);
// int disease_idx = entry_index.get(diseaseid);
// System.out.println(disease_idx);
// System.out.println(cgg.getNeibor(disease_idx));
//
// Map<String, Double> commDisMap = ComSearch.searchFaers2(diseaseid, cgg);
// System.out.println("\nNeibor node method......");
// System.out.println("Number of comorbidities found: " + commDisMap.size() + "\n");
// for (String dis : commDisMap.keySet()) {
// System.out.println(dis);
// }
// #########################################################################
// --------------------- Method 2: Build network from network -------------
// #########################################################################
String dcnmapfile = "/Users/zhengc/workspace/FARES_final/data/FARES/map/term_umls_id_diso";
String omimmapfile = "/Users/zhengc/workspace/FARES_final/data/OMIM/map/OMIM_umls_id_diso";
util.DCNOMIMUMLSIDmap.createDCNIdNameMap(dcnmapfile);
util.DCNOMIMUMLSIDmap.createOMIMIdNameMap(omimmapfile);
String DCN_dis = "dementia";
String OMIM_pat = "alzheimer";
DCNOMIMUMLSIDmap domim = new DCNOMIMUMLSIDmap(DCN_dis, OMIM_pat);
Map<String, List<String>> dcn_omim = domim.getDCNOMIMUMLSIDmap();
for (String dis: dcn_omim.keySet()) {
System.out.println(dcn_omim.get(dis));
}
/*
* Build heterogenous network
*/
String rulefile = "./data/ID_indications_all_clean_width_umls_id_diso_filtered_sp_lift_1_0.000002_3_processed.txt";
String commnetfile = "./results/fares_comm_net_lift_final_abbr.txt";;
String ppifile = "./data/gene_gene_string_cut.txt";
String disgenefile = "./data/OMIM_disease_gene_umls_id_diso";
CommLoader.readAssocRules(rulefile);
DisGraph commnet = CommLoader.createCommNet(rulefile);
CommLoader.readPPI(ppifile);
DisGraph ppinet = CommLoader.createPPINet(ppifile);
Map<Integer, List<Integer>> dis_gene = CommLoader.readDisGene(disgenefile, dcn_omim);
DisGraph cgg2 = createCommGeneticsGraph(commnet, ppinet, dis_gene);
System.out.println(cgg2.getEdges());
System.out.println(cgg2.getNodes());
String netfile = "./results/DCN_PPI/DCN_PPI_net_lift.txt";
writeCommGeneticsNet(cgg, netfile);
String disUMLS_name_file = "./results/disUMLS_name_lift.txt";
writeDCNIdName(commnetfile, disUMLS_name_file);
}
}