[e26484]: / OmicsFold / R / identifier_mapping.R

Download this file

78 lines (73 with data), 2.6 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
#' Map gene symbols to Entrez IDs
#'
#' @description
#' Map a list of symbols to their corresponding Entrez IDs. This wraps the
#' method from the anRichmentMethods library to convert a list of symbols to
#' entrez IDs.
#'
#' @param symbols List of gene symbols.
#' @param organism The organism the symbols relate to. This can be any of the
#' supported common names, scientific names or shorthand shown when calling
#' \code{anRichmentMethods::organismLabels()}.
#'
#' @return Data frame containing pairs of symbols and Entrez IDs.
#' @export
#'
#' @examples
#' \dontrun{
#' gene.symbols.and.ids <- map.symbols.entrez.ids(gene.symbols, "mouse")
#' }
map.symbols.entrez.ids <- function(symbols, organism) {
gene.symbols <- as.data.frame(symbols)
colnames(gene.symbols) <- c("symbol")
gene.symbols$entrez.id <- anRichmentMethods::convert2entrez(organism, symbols)
return(gene.symbols)
}
#' Retrieve genes annotated with a GO term
#'
#' @description
#' Utility method to retrieve all genes annotated with a particular GO term, or
#' any of its children.
#'
#' @param go.id GO term.
#'
#' @return Symbol of gene annotated with this term.
#' @export
#'
getGOGenes <- function(go.id) {
go.ids <- GOBPOFFSPRING[[go.id]]
go.ids <- append(go.ids, go.id)
allegs <- sapply(go.ids,
function (x) try(get(x, org.Mm.egGO2ALLEGS), silent = TRUE) )
allegs <- unlist(allegs, recursive = TRUE)
allegs <- allegs[!str_detect(allegs, "Error", negate = FALSE)]
genes = unlist(mget(allegs, org.Mm.egSYMBOL))
return(genes)
}
#' Convert mouse genes to human orthologues
#'
#' @description
#' Convert a list of mouse genes to their human orthologues.
#'
#' @param mouse.genes List of mouse gene symbols.
#'
#' @return Human orthologue gene symbols (not necessarily ordered).
#' @export
#'
convertMouseGeneList <- function(mouse.genes) {
human = biomaRt::useEnsembl("ensembl",
dataset = "hsapiens_gene_ensembl",
mirror = "useast")
mouse = biomaRt::useEnsembl("ensembl",
dataset = "mmusculus_gene_ensembl",
mirror = "useast")
genesV2 = biomaRt::getLDS(attributes = c("mgi_symbol"),
filters = "mgi_symbol",
values = mouse.genes,
mart = mouse,
attributesL = c("hgnc_symbol"),
martL = human,
uniqueRows=T)
humanx <- unique(genesV2[, 2])
return(humanx)
}