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?
2 answers
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").
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)
Log in to answer this question.
I guess your
Datais incharacterclass. If whatever you want to stick to your codes, you can try:Thank you for your answer but the search command via mart does not start. How to solve this problem?
Thank you for your answer but the search command via mart does not start. How to solve this problem?
Did you have a look at the final dataframe:
resultif using the codes from fracarb8?Thank you for your help SMK , your solution works perfectly! Thank you! Thank you!
Hello, I turn to you because since Friday, I can no longer retrieve my various information because I find myself with a recurrent error:
Despite my internet research, I can't fix this mistake. How can I get this tool to work again?
Thank you in advance
Did you find answers in BioMart : the BioMart webservice returned an invalid result?
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.
I added a comment there, regarding the batch issue.