Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Setting general options to store the location of temporary speclist file
- options("tempspecfile"=tempfile("specfile."))
- # specfileloc
- specfileloc <- function(){
- specfile <- system.file("extdata/speclist.txt")
- # Check if speclist.txt is available online, if yes, download, if not, fall back to local copy
- localfile <- getOption("tempspecfile")
- if(require(RCurl)){
- if(!file.exists(localfile)){
- specurl <- 'http://www.uniprot.org/docs/speclist.txt'
- test <- getBinaryURL(specurl)
- if(length(test)>1){
- writeBin(test,localfile)
- specfile <- localfile
- }
- }else{
- specfile <- localfile
- }
- }
- # Check if specfile exists or throw error
- if(!file.exists(specfile)){
- stop("speclist.txt cannot be downloaded from UniProt.org, and it is not found locally")
- }
- return(specfile)
- }
- # digest specfile
- digestspecfile <- function(specfile = specfileloc()){
- my.text <- readLines(specfile)
- codetable <- my.text[grep("^[A-Z0-9]+ +[ABEVO]", my.text, perl=TRUE, value=FALSE)]
- codes <- data.frame(domain = substr(codetable,7,7),
- taxId = as.numeric(substr(codetable,8,15)),
- taxname = sapply(strsplit(codetable, ": N="), '[', 2),
- row.names = sapply(strsplit(codetable, " +[ABEVO] +",perl=TRUE), '[', 1))
- codes$species <- gsub("^([^ ]* [^ ]*) .*$","\\1",codes$taxname, perl=TRUE)
- return(codes)
- }
- # taxname2species
- taxname2species <- function(taxname){
- codetable <- digestspecfile()
- specnames <- codetable[taxname,"species"]
- return(specnames)
- }
- # taxname2taxid
- taxname2taxid <- function(taxname){
- codetable <- digestspecfile()
- taxids <- codetable[taxname,"taxId"]
- return(taxids)
- }
- #taxname2domain
- taxname2domain <- function(taxname){
- codetable <- digestspecfile()
- domains <- codetable[taxname,"domain"]
- return(domains)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement