Iteration of the Biomart search command on the entire list of rsIDs in a file
2
0
Entering edit mode
4.9 years ago

Hello,

I have a text file containing a list of rsIDs for many snp. I want to make the same request to search for gene names and transcripts on each line of this file. So, I would like to read my file line by line and indicate the current line (loop?) in my request. How to read my file line by line and put in "value" (of the getBM function) each line of my file (here instead of Data_with it is to have each line of the file).

Here is the code I tried:

Data <- readLines ("/Users/amandinelecerfdefer/Desktop/rsID.txt")
require(biomaRt)
sink("sortie_rsID.txt")
retrieve<-list()
for (i in 1:nrow(Data)){
  values <- Data_vec[[i]]
  ensembl <- useMart("ENSEMBL_MART_SNP", dataset = "hsapiens_snp")
  retrieve[[i]] <-getBM(attributes=c(
  "refsnp_id", "ensembl_gene_stable_id", "ensembl_transcript_stable_id"),
  filters="snp_filter", values=values,
  mart=ensembl, uniqueRows=TRUE)
}

but I still have this message:

Error in 1:nrow(Data) : argument of length 0

How can I link the file line by line and indicate to value each line line after line? and so how can I iterate this search command on all my snps in my file?

itération R SNP rsID • 2.3k views
ADD COMMENT
0
Entering edit mode

I guess your Data is in character class. If whatever you want to stick to your codes, you can try:

for (i in 1:length(Data)) {
  values <- Data[i]
  ......
}
ADD REPLY
0
Entering edit mode

Thank you for your answer but the search command via mart does not start. How to solve this problem?

ADD REPLY
0
Entering edit mode

Thank you for your answer but the search command via mart does not start. How to solve this problem?

ADD REPLY
0
Entering edit mode

Did you have a look at the final dataframe: result if using the codes from fracarb8?

ADD REPLY
0
Entering edit mode

Thank you for your help SMK , your solution works perfectly! Thank you! Thank you!

ADD REPLY
0
Entering edit mode

Hello, I turn to you because since Friday, I can no longer retrieve my various information because I find myself with a recurrent error:

> res <- getBM(
+   attributes = c(
+     "refsnp_id",
+     "ensembl_gene_stable_id",
+     "ensembl_transcript_stable_id"
+   ),
+   filters = "snp_filter",
+   values = Data$rsID,
+   mart = snpmart,
+   uniqueRows = TRUE
+ )
Batch submitting query [=======>-----------------------------------------------------]  13% eta:  2hError in getBM(attributes = c("refsnp_id", "ensembl_gene_stable_id", "ensembl_transcript_stable_id"),  : 
  The query to the BioMart webservice returned an invalid result: biomaRt expected a character string of length 1. 
Please report this on the support site at http://support.bioconductor.org

Despite my internet research, I can't fix this mistake. How can I get this tool to work again?

Thank you in advance

ADD REPLY
0
Entering edit mode
ADD REPLY
0
Entering edit mode

Yes, it's also my post ^^. The problem is the length of the list to send to the server. A maximum of 500 queries can be sent. What seems strange to me is that last week I managed to send 100,000 rsIDs.

ADD REPLY
0
Entering edit mode

I added a comment there, regarding the batch issue.

ADD REPLY
3
Entering edit mode
4.9 years ago
AK ★ 2.2k

Hi amandinelecerfdefer,

Try the following codes (assuming your file rsID.txt is with rsID as the header):

rsID
rs1450830176
rs868546642
rs1207902742
rs1431088173
rs1266518345
rs1387005982
library(biomaRt)
Data <- read.delim("rsID.txt")

snpmart <-
  useMart(biomart = "ENSEMBL_MART_SNP", dataset = "hsapiens_snp")
res <- getBM(
  attributes = c(
    "refsnp_id",
    "ensembl_gene_stable_id",
    "ensembl_transcript_stable_id"
  ),
  filters = "snp_filter",
  values = Data$rsID,
  mart = snpmart,
  uniqueRows = TRUE
)

Your results will be saved in a data.frame named res, you can save that out using write.csv(res, file = "rsID_out.txt").

ADD COMMENT
0
Entering edit mode
4.9 years ago
fracarb8 ★ 1.6k

Why don't you simply read.delim() your file, save the column containing your IDs into values and pass it to useMart?

data <- read.delim("/Users/amandinelecerfdefer/Desktop/rsID.txt") values <- data[,1] # or use $ if the column is not the first ensembl <- useMart("ENSEMBL_MART_SNP", dataset = "hsapiens_snp") result <- getBM(attributes=c("refsnp_id", "ensembl_gene_stable_id", "ensembl_transcript_stable_id"), filters="snp_filter", values=values, mart=ensembl, uniqueRows=TRUE)

ADD COMMENT

Login before adding your answer.

Traffic: 2132 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