R: How to save Mart object (BiomaRt package)
Entering edit mode
4.8 years ago
m98 ▴ 420

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:

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.

R BiomaRt RNA-Seq • 2.2k views
Entering edit mode

Did you try googling save r object to file? Please invest some effort to solve your problem.

Entering edit mode

I didn't think "Mart" objects stored the database tables. Aren't they database handles? Presumably you'd have to getBM the information you want to store and save that to your "ensembl-data.txt" file

Entering edit mode
4.8 years ago
Mike Smith ★ 2.0k

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.


Login before adding your answer.

Traffic: 1771 users visited in the last hour
Help About
Access RSS

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

Powered by the version 2.3.6