所以我尝试使用rentrez包从GenBank检索DNA序列数据,给出一个物种列表作为输入。我所做的是为我想要查询的物种创建一个向量,然后创建一个term,我在其中指定要检索的序列数据的类型,然后创建一个search,它检索与我的查询匹配的所有匹配项,最后我创建data,在fasta文件中检索实际的序列数据。
library(rentrez)
species<-c("Ablennes hians","Centrophryne spinulosa","Doratonotus megalepis","Entomacrodus cadenati","Katsuwonus pelamis","Lutjanus fulgens","Pagellus erythrinus")
for (x in species){
term<-paste(x,"[Organism] AND (((COI[Gene] OR CO1[Gene] OR COXI[Gene] OR COX1[Gene]) AND (500[SLEN]:3000[SLEN])) OR complete genome[All Fields] OR mitochondrial genome[All Fields])",sep='',collapse = NULL)
search<-entrez_search(db="nuccore",term=term,retmax=99999)
data<-entrez_fetch(db="nuccore",id=search$ids,rettype="fasta")
}基本上,我要做的是将每个物种的查询结果连接到一个变量中。我开始使用for循环,但我发现它在这个表单中没有任何意义,因为正在查询的每个新物种的数据只是替换了data中的前一个数据。
对于species的某些元素,将没有要检索的数据,R显示此错误:
Error: Vector of IDs to send to NCBI is empty, perhaps entrez_search or entrez_link found no hits?在显示此错误的情况下,因此没有该特定物种的数据,我希望代码继续运行并忽略它。
我的输出将是一个变量data,它将包括从species中的所有名称检索到的序列数据。
发布于 2021-03-06 00:42:44
library(rentrez)
species<-c("Ablennes hians","Centrophryne spinulosa","Doratonotus megalepis","Entomacrodus cadenati","Katsuwonus pelamis","Lutjanus fulgens","Pagellus erythrinus")
data <- list()
for (x in species){
term<-paste(x,"[Organism] AND (((COI[Gene] OR CO1[Gene] OR COXI[Gene] OR COX1[Gene]) AND (500[SLEN]:3000[SLEN])) OR complete genome[All Fields] OR mitochondrial genome[All Fields])",sep='',collapse = NULL)
search<-entrez_search(db="nuccore",term=term,retmax=99999)
data[x] <- tryCatch({entrez_fetch(db="nuccore",id=search$ids,rettype="fasta")},
error = function(e){NA})
}https://stackoverflow.com/questions/66495221
复制相似问题