Quickest Way To Convert/Update Gene Ids In A Table
1
1
Entering edit mode
11.4 years ago
enricoferrero ▴ 910

Hi,

I have a number of tab delimited files containing various types of information about specific genes. One or more of the columns can be Aliases to Gene Symbols that I need to upgrade to the latest Gene Symbol annotation.

I'm using Bioconductor's org.Hs.eg.db library to do so (the org.Hs.egALIAS2EG and org.Hs.egSYMBOL objects in particular).

The code reported does the job but is very slow, I guess because of the nested for loops that query the org.Hs.eg.db database at each iteration. Is there a quicker/simpler/smarter way to achieve the same result?

library(org.Hs.eg.db)

myTable <- read.table("tab_delimited_file.txt", header=TRUE, sep="\t", as.is=TRUE)

for (i in 1:nrow(myTable)) {
    for (j in 1:ncol(myTable)) {
        repl <- org.Hs.egALIAS2EG[[myTable[i,j]]][1]
        if (!is.null(repl)) {
            repl <- org.Hs.egSYMBOL[[repl]][1]
            if (!is.null(repl)) {
                myTable[i,j] <- repl
            }
        }
    }
}

write.table(myTable, file="new_tab_delimited_file", quote=FALSE, sep="\t", row.names=FALSE, col.names=TRUE)

I'm thinking to use one of the apply function, but bear in mind that org.Hs.egALIAS2EG and org.Hs.egSYMBOL are objects, and not functions.

Thank you!

r bioconductor • 3.1k views
ADD COMMENT
0
Entering edit mode

For these thing awk is very convenient and extremely fast. But you need files for that which have info about each gene against which you have to parse your file. Otherwsie try DAVID (there are many other online gene id conversion tools)

ADD REPLY
0
Entering edit mode

Thanks, but I was looking into a faster way to do the same in R. One of the advantages of using Bioconductr is that I don't have to worry about keeping mappings between IDs up to date locally.

ADD REPLY
0
Entering edit mode
11.4 years ago
SimonD • 0

I think this might work.

    repl <- org.Hs.egALIAS2EG[[ myTable[1:nrow(myTable),1:ncol(myTable)] ]][1]
    myNewTable <- matrix(nrow=nrow(myTable), repl, byrow=T)
ADD COMMENT
0
Entering edit mode

Thanks, that's a very cool yet simple approach. Unfortunately it fails (possibly because of gene symbols mapped to more than one Entrez Gene ID?):

> repl <- org.Hs.egALIAS2EG[[ myTable[1:nrow(myTable),1:ncol(myTable)] ]][1]
Error in .doubleBracketSub(x, i, j, ...) : 
attempt to select more than one element

Any idea on how to fix it?

ADD REPLY

Login before adding your answer.

Traffic: 1821 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6