struggling with an R command
1
0
Entering edit mode
9.6 years ago

I have established ensembl as my database but I can not get this code to work....

Any help?

results <- getBM(attributes = c("ensembl_gene_id", "hgnc_symbol"), filters = "hgnc_symbol", values = genes$hgnc, mart = mart)
Error in getBM(attributes = c("ensembl_gene_id", "hgnc_symbol"), filters = "hgnc_symbol",  : 
  Values argument contains no data.
R • 4.8k views
ADD COMMENT
1
Entering edit mode

What is the output of head(genes$hgnc)?

ADD REPLY
0
Entering edit mode

this returns.... NULL. what do i have to do to give it a value

ADD REPLY
1
Entering edit mode

Your vector genes$hgnc seems to contain no rows.. try length(genes$hgnc) ; class(genes$hgnc) ..

ADD REPLY
0
Entering edit mode

oh yes i have created a list of genes in a csv file and i have it in the right directory and i changed the "my file" to my csv title.

changing the values to tp53 and sry worked but my list is 200 genes long.... i'm hoping to get the requested info (specified in the code) on the whole list... is that possible that it will search ensembl for this info for all of the genes in my list with the right code?

ADD REPLY
0
Entering edit mode

Please comment under answers rather than posting new questions as answers.

If what you say regarding the CSV file is true then the value of genes$hgnc cannot be NULL. Check again.

BioMart should have no issues with 200 genes; I routinely use query vectors with thousands of entries.

ADD REPLY
0
Entering edit mode

Is this where u want me to post? yes the csv file is real and genes$hgnc just returns NULL.

The full code is as follows:

library(biomaRt)
> mart <- useMart(biomart="ensembl", dataset="hsapiens_gene_ensembl")
> # read in the file
> genes <- read.csv("chromatin.csv")
> results <- getBM(attributes = c("ensembl_gene_id", "hgnc_symbol"), filters = "hgnc_symbol", values = c("TP53", "SRY"), mart = mart)

And results returns:

> results
  ensembl_gene_id hgnc_symbol
1 ENSG00000184895         SRY
2 ENSG00000141510        TP53
3         LRG_321        TP53
ADD REPLY
0
Entering edit mode

What do the first few lines of chromatin.csv look like? (including the header row)

ADD REPLY
0
Entering edit mode
TDRKH
CTCFL
PIWIL4
GATAD2A
ASZ1
DNMT1
DNMT1
DNMT1
DNMT1
ADD REPLY
0
Entering edit mode

OK. First, that is not a CSV file - although read.csv() will still read it in just fine.

Second, the first row does not contain the value "hgnc". That is where genes$hgnc comes from. read.csv() assumes by default that the first row contains the column header, so what you have is genes$TDRKH.

There are lots of ways to fix this. One of them is to use read.csv() with the header = FALSE argument. Your column header will then be V1, so you would use genes$V1. But you should read the help pages or some online tutorials for read.csv() and read.table(), so you understand how to read data into R.

ADD REPLY
0
Entering edit mode

So does that mean that everywhere in the code that I have hgnc e.g. hgnc_symbol I should replace the hgnc with TDHRK?

ADD REPLY
0
Entering edit mode

No. That means that the first line of your file should be "hgnc", not "TDHRK". As I said, read.csv() assumes that the first line contains a header by default. If your first line is "TDHRK" and you don't specify header = FALSE, then R assumes that the column header is "TDHRK".

ADD REPLY
1
Entering edit mode
9.6 years ago
Neilfws 49k

It seems that you have copied this code from my blog post.

In that post, you will note that the HGNC symbols are one column of a CSV file, which was read into R. You cannot expect copy/paste of the code to work unless you also have a CSV file, with a column headed "hgnc", containing HGNC symbols.

You can try values = c("TP53", "SRY") if you just want to see how the code works and what is returned by getBM(). Basically, you need to supply a vector of HGNC symbols as the value for values.

ADD COMMENT
0
Entering edit mode

Good answer (maybe question should be closed?).

ADD REPLY

Login before adding your answer.

Traffic: 2417 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

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

Powered by the version 2.3.6