只是一个快速警告:一个别名可以映射到多个 Entrez 基因 ID。
因此,您当前的解决方案假定第一个列出的 ID 是正确的(这可能不是真的)。
# e.g. The alias "A1B" is assumed to map to "1" and not "6641"
mget("A1B", org.Hs.egALIAS2EG)
# $A1B
# [1] "1" "6641"
如果您查看 的帮助?org.Hs.egALIAS2EG
,您会发现从不建议使用别名或符号作为主要基因标识符。
## From the 'Details' section of the help:
# Since gene symbols are sometimes redundantly assigned in the literature,
# users are cautioned that this map may produce multiple matching results
# for a single gene symbol. Users should map back from the entrez gene IDs
# produced to determine which result is the one they want when this happens.
# Because of this problem with redundant assigment of gene symbols,
# is it never advisable to use gene symbols as primary identifiers.
如果没有人工管理,就不可能知道哪个 ID 是“正确的”。因此,最安全的选择是获取表中每个别名的所有可能 ID 和符号,同时保留有关哪些是受体和哪些是配体的信息:
# your example subset with "A1B" and "trash" added for complexity
myTable <- data.frame(
ReceptorGene = c("A1B", "ACVR2B", "ACVR2B", "ACVR2B", "ACVR2B", "AMHR2", "BLR1", "BMPR1A", "BMPR1A", "BMPR1A", "BMPR1A", "BMPR1A"),
LigandGene = c("trash", "INHA", "INHBA", "INHBB", "INHBC", "AMH", "SCYB13", "BMP10", "BMP15", "BMP2", "BMP3", "BMP4"),
stringsAsFactors = FALSE
)
# unlist and rename
my.aliases <- unlist(myTable)
names(my.aliases) <- paste(names(my.aliases), my.aliases, sep = ".")
# determine which aliases have a corresponding Entrez Gene ID
has.key <- my.aliases %in% keys(org.Hs.egALIAS2EG)
# replace Aliases with character vectors of all possible entrez gene IDs
my.aliases[has.key] <- sapply(my.aliases[has.key], function(x) {
eg.ids <- unlist(mget(x, org.Hs.egALIAS2EG))
symbols <- unlist(mget(eg.ids, org.Hs.egSYMBOL))
})
# my.aliases retains all pertinent information regarding the original alias
my.aliases[1:3]
# $ReceptorGene1.A1B
# 1 6641
# "A1BG" "SNTB1"
#
# $ReceptorGene2.ACVR2B
# 93
# "ACVR2B"
#
# $ReceptorGene3.ACVR2B
# 93
# "ACVR2B"
一旦您知道哪些 Entrez 基因 ID 是合适的,您就可以将它们作为附加列存储在您的表格中。
myTable$receptor.id <- c("1", "93", "93", "93", "93", "269", "643", "657", "657", "657", "657", "657")
myTable$ligand.id <- c(NA, "3623", "3624", "3625", "3626", "268", "10563", "27302", "9210", "650", "651", "652")
然后,当您需要更新到最新的符号时,您可以只使用 Entrez 基因 ID(永远不需要更新)。
has.key <- myTable$receptor.id %in% keys(org.Hs.egSYMBOL)
myTable$ReceptorGene[has.key] <- unlist(mget(myTable$receptor.id[has.key], org.Hs.egSYMBOL))
has.key <- myTable$ligand.id %in% keys(org.Hs.egSYMBOL)
myTable$LigandGene[has.key] <- unlist(mget(myTable$ligand.id[has.key], org.Hs.egSYMBOL))
head(myTable)
# ReceptorGene LigandGene receptor.id ligand.id
# 1 A1BG trash 1 <NA>
# 2 ACVR2B INHA 93 3623
# 3 ACVR2B INHBA 93 3624
# 4 ACVR2B INHBB 93 3625
# 5 ACVR2B INHBC 93 3626
# 6 AMHR2 AMH 269 268