Simple R functions

This is a very simple R function to calculate the fragments per nanogram based on an average size of fragments
frag <- function(x){                             # X = average size of fragments
molmass <- x * 649                            # calculates molar mass for ds fragments
frag.g <- 6.022e+23/molmass          # avogadro number frag in frag/g <- frag.g*1e-9                        # number frag in frag/ng
return(                                    # return result

This is another R function I took somewhere from internet to load a sequence from Genbank into R

getncbiseq <- function(accession) #function to load entire genome in R
require(“seqinr”) # this function requires the SeqinR R package
# first find which ACNUC database the accession is stored in:
dbs <- c(“genbank”,”refseq”,”refseqViruses”,”bacterial”)
numdbs <- length(dbs)
for (i in 1:numdbs)
db <- dbs[i]
# check if the sequence is in ACNUC database ‘db’:
resquery <- try(query(“.tmpquery”, paste(“AC=”, accession)), silent = TRUE)
if (!(inherits(resquery, “try-error”)))
queryname <- “query2”
thequery <- paste(“AC=”,accession,sep=””)
# see if a sequence was retrieved:
seq <- getSequence(query2$req[[1]])
print(paste(“ERROR: accession”,accession,”was not found”))


One thought on “Simple R functions

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s