Skip to content

Instantly share code, notes, and snippets.

@bobthecat
Created June 4, 2012 03:43
Show Gist options
  • Save bobthecat/2866212 to your computer and use it in GitHub Desktop.
Save bobthecat/2866212 to your computer and use it in GitHub Desktop.
get.ppiNCBI
get.ppiNCBI <- function(g.n) {
require(XML)
ppi <- data.frame()
for(i in 1:length(g.n)){
o <- htmlParse(paste("http://www.ncbi.nlm.nih.gov/gene/", g.n[i], sep=''))
# check if interaction table exists
exist <- length(getNodeSet(o, "//table//th[@id='inter-prod']"))>0
if(exist){
p <- getNodeSet(o, "//table")
## need to know which table is the good one
for(j in 1:length(p)){
int <- readHTMLTable(p[[j]])
if(colnames(int)[2]=="Interactant"){break}
}
ppi <- rbind(ppi, data.frame(egID=g.n[i], intSymbol=int$`Other Gene`))
}
# play nice! and avoid being kicked out from NCBI servers
Sys.sleep(1)
}
if(dim(ppi)[1]>0){
ppi <- unique(ppi)
print(paste(dim(ppi)[1], "interactions found"))
return(ppi)
} else{
print("No interaction found")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment