-
Notifications
You must be signed in to change notification settings - Fork 2
/
helpers.R
40 lines (28 loc) · 1.06 KB
/
helpers.R
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
map_entrez_ids <- function(entrez.ids, tech = "h19"){
genes = entrez.ids
mapping = AnnotationDbi::select(org.Hs.eg.db,
key=genes,
columns=c("SYMBOL"),
keytype="ENTREZID")
mapping = as.data.table(mapping)
colnames(mapping) = c("entrez.id", "hgnc.symbol")
not.found = mapping[which(is.na(mapping$hgnc.symbol)), ]$entrez.id
mapping = mapping[which(!(is.na(mapping$hgnc.symbol))), ]
if(length(not.found) > 0){
if(tech == "h19"){
x = grch37
} else {
x = grch38
}
x = as.data.table(x)
x = x[,c(2,3)]
colnames(x) = c("entrez.id", "hgnc.symbol")
merge = x[which(x$entrez.id %in% not.found), ]
mapping = rbind(mapping, merge)
not.found = not.found[which(!(not.found %in% merge$entrez.id))]
}
mapping = rbind(mapping, data.table("entrez.id" = not.found, "hgnc.symbol" = NA))
mapping = mapping[order(mapping$hgnc.symbol), ]
mapping = unique(mapping)
return(mapping)
}