-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapper.js
More file actions
60 lines (51 loc) · 1.88 KB
/
Copy pathmapper.js
File metadata and controls
60 lines (51 loc) · 1.88 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
/***
OMIM CONVERTER: a JavaScript conversion tool for Open Data Science URIs
Created on January 13th 2025
@author: Niccolò Bianchi [https://github.com/NCMBianchi]
'mapper.js' is a streamline ID conversion tool to convert Monarch Initiative's
custom IDs to OMIM IDs, fetching corresponding IDs and names from mapping file
'monarch-omim.json' that can be generated/updated with 'updateMapping.py'.
***/
class MonarchOmimMapper {
constructor() {
this.monarchMappings = {};
this.omimMappings = {};
this.loadMappings();
}
async loadMappings() {
try {
// Load both mapping files
const [monarchResponse, omimResponse] = await Promise.all([
fetch('./data/monarch-omim.json'),
fetch('./data/omim-monarch.json')
]);
this.monarchMappings = await monarchResponse.json();
this.omimMappings = await omimResponse.json();
} catch (error) {
console.error('Error loading mapping files:', error);
this.monarchMappings = {};
this.omimMappings = {};
}
}
getMonarchToOmim(monarchId) {
if (!monarchId) return null;
const cleanMonarchId = monarchId.trim().toUpperCase();
return this.monarchMappings[cleanMonarchId] || null;
}
getOmimToMonarch(omimId) {
if (!omimId) return null;
const cleanOmimId = omimId.replace('OMIM:', '').trim();
return this.omimMappings[cleanOmimId] || null;
}
// Get just the name for a Monarch Initiative ID
getDiseaseName(monarchId) {
const data = this.getMonarchToOmim(monarchId);
return data ? data.name : null;
}
// Get just the name for an OMIM ID
getOmimName(omimId) {
const data = this.getOmimToMonarch(omimId);
return data ? data.name : null;
}
}
module.exports = MonarchOmimMapper;