Switch to unified view

a b/util/DCNOMIMUMLSIDmap.java
1
package util;
2
3
import java.io.BufferedReader;
4
import java.io.BufferedWriter;
5
import java.io.File;
6
import java.io.FileReader;
7
import java.io.FileWriter;
8
import java.io.IOException;
9
import java.util.ArrayList;
10
import java.util.Collections;
11
import java.util.HashMap;
12
import java.util.List;
13
import java.util.Map;
14
import java.util.Set;
15
16
/**
17
 * This class provides disease mapping between DCN and OMIM disease
18
 * @author zhengc
19
 *
20
 */
21
public class DCNOMIMUMLSIDmap {
22
23
    public static Map<String, List<String>> dcnidnamemap = new HashMap<>();
24
    public static Map<String, String> dcnnameidmap = new HashMap<>();
25
    public static Map<String, List<String>> omimidnamemap = new HashMap<>();
26
    public static Map<String, String> omimnameidmap = new HashMap<>();
27
    
28
    private static Map<String, List<String>> DCN_OMIM = new HashMap<>();
29
    
30
    /**
31
     * Initiates and creates a DCNOMIMUMLSIDmap object
32
     * @param DCN_disease DCN disease name
33
     * @param OMIM_dispattern OMIM disease name pattern that equals DCN disease name
34
     */
35
    public DCNOMIMUMLSIDmap(String DCN_disease, String OMIM_dispattern) {
36
        
37
        String DCN_id = dcnnameidmap.get(DCN_disease);
38
        
39
        List<String> OMIM_ids = new ArrayList<>();
40
        for (String dis : omimnameidmap.keySet()) {
41
            if (dis.contains(OMIM_dispattern)) {
42
                OMIM_ids.add(omimnameidmap.get(dis));
43
            }   
44
        }
45
        Collections.sort(OMIM_ids);
46
        DCN_OMIM.put(DCN_id, OMIM_ids);
47
        
48
    }
49
    
50
    /**
51
     * Creates a DCN name_UMLS mapping
52
     * @param mapfile a name_UMLS mapping file
53
     * @throws IOException
54
     */
55
    public static void createDCNIdNameMap(String mapfile) throws IOException {
56
        
57
        BufferedReader br = new BufferedReader(new FileReader(mapfile));
58
        String line = null;
59
        while((line = br.readLine()) != null){
60
            String[] parts = line.split("\\|");
61
            String name = parts[0].toLowerCase();
62
            String id = parts[1];
63
            if (!dcnnameidmap.containsKey(name)) {
64
                dcnnameidmap.put(name, id);
65
            }
66
            
67
            if (!dcnidnamemap.containsKey(id)) {
68
                List<String> names = new ArrayList<>();
69
                names.add(name);
70
                dcnidnamemap.put(id, names);
71
            } else {
72
                dcnidnamemap.get(id).add(name);
73
            }
74
        }
75
        br.close();
76
    } 
77
    
78
79
    /**
80
     * Creates a OMIM name_UMLS mapping
81
     * @param mapfile a name_UMLS mapping file
82
     * @throws IOException
83
     */
84
    public static void createOMIMIdNameMap(String mapfile) throws IOException {
85
        
86
        BufferedReader br = new BufferedReader(new FileReader(mapfile));
87
        String line = null;
88
        while((line = br.readLine()) != null){
89
            String[] parts = line.split("\\|");
90
            String name = parts[0].toLowerCase();
91
            String id = parts[1];
92
            if (!omimnameidmap.containsKey(name)) {
93
                omimnameidmap.put(name, id);
94
            }
95
            
96
            if (!omimidnamemap.containsKey(id)) {
97
                List<String> names = new ArrayList<>();
98
                names.add(name);
99
                omimidnamemap.put(id, names);
100
            } else {
101
                omimidnamemap.get(id).add(name);
102
            }
103
        }
104
        br.close();
105
    } 
106
    
107
    /**
108
     * Get DCN_OMIM mapping
109
     * @return DCN_OMIM mapping
110
     */
111
    public Map<String, List<String>> getDCNOMIMUMLSIDmap() {
112
        return DCN_OMIM;
113
    }
114
    
115
    public static void main(String[] args) throws IOException {
116
117
        String dcnmapfile = "/Users/zhengc/workspace/FARES_final/data/FARES/map/term_umls_id_diso";
118
        String omimmapfile = "/Users/zhengc/workspace/FARES_final/data/OMIM/map/OMIM_umls_id_diso";
119
        createDCNIdNameMap(dcnmapfile);
120
        createOMIMIdNameMap(omimmapfile);
121
        
122
        String DCN_dis = "dementia";
123
        String OMIM_pat = "alzheimer";
124
        
125
        DCNOMIMUMLSIDmap domim = new DCNOMIMUMLSIDmap(DCN_dis, OMIM_pat);
126
        Map<String, List<String>> dcn_omim = domim.getDCNOMIMUMLSIDmap();
127
                
128
        System.out.println(DCN_dis + ": " + dcnnameidmap.get(DCN_dis));
129
        
130
        String DCN_dis_id = dcnnameidmap.get(DCN_dis);
131
        List<String> OMIM_ids = dcn_omim.get(DCN_dis_id);
132
        
133
        for (String id : OMIM_ids) {
134
            List<String> names = omimidnamemap.get(id);
135
            for (String name : names) {
136
                System.out.println(name + ": " + id);
137
            }
138
        }
139
140
    }
141
142
}