I am using the biomaRt package to obtain some annotation data in the context of an RNAseq pipeline.
In my script I have the following commands:
library(biomaRt)
ensembl <- useMart("ENSEMBL_MART_ENSEMBL", dataset = "hsapiens_gene_ensembl", host = "www.ensembl.org")
# Later on in the script I use this ensembl object to annotate my genes
Originally, I used the commands above directly in my pipeline script - in other words, every time I ran the script, I would re-download the data. However, for various reasons, this download is now taking far too long and in fact it crashes before it ends (the download takes over 20min and then crashes).
My question is, is there a way of saving the ensembl object to a file and uploading it in my pipeline? I cannot seem to save the entire file with:
write.table(ensembl, "ensembl-data.txt")
Error in as.data.frame.default(x[[i]], optional = TRUE) :
cannot coerce class ‘structure("Mart", package = "biomaRt")’ to a data.frame
It feels like there is a simple solution this but I cannot find it. Thanks.
1 answer
I think there's a few issues here, but the fundamental problem in your example is that ensembl is an object of class Mart not a table of results. It stores various information about the 'Mart' (which you can think of a resource) such as the URL and properties of dataset you want to access such as the available attributes and filters. What it doesn't hold is the result of any query, since you could can ask many questions of a mart.
What you want to save will be the results of running the getBM() command with that particular Mart object plus the filter, values, and attributes. You should then be able to save that via write.table() or save().
Since you don't give an example of the getBM() command you're trying to run, it's hard to advise on why it might be crashing.
Log in to answer this question.
Did you try googling
save r object to file? Please invest some effort to solve your problem.I didn't think "Mart" objects stored the database tables. Aren't they database handles? Presumably you'd have to
getBMthe information you want to store and save that to your "ensembl-data.txt" file