簡単な警告: エイリアスは複数の Entrez Gene 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 Gene 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 Gene 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