沿着我的老问题Subsetting defined group out of DNAStringSet,我无法为列表做同样的事情。导致错误的所有尝试:
Error in .Call2("new_XStringSet_from_CHARACTER", ans_class, ans_elementType, : key 56 (char '8') not in lookup table
工作示例:
library("DECIPHER")
library("Biostrings")
名为Biglist
的DNAStringsets列表和一个名为patterns
的选择我想打电话来获取一个新列表:
aDNAStringSet <- DNAStringSet(c("GCATCCATTAC", "AATCGCCATCC", "GCATACCTTAC", "GCATACCTTAC", "GCATACCTTAC"))
names(aDNAStringSet) <- c("seq1", "seq2", "seq3", "seq4", "seq5")
bDNAStringSet <- DNAStringSet(c("GCATCCATTAC", "AATCGCCATCC", "GCATACCTTAC", "GCATACCTTAC", "GCATACCTTAC"))
names(bDNAStringSet) <- c("seq1", "seq2", "seq3", "seq4", "seq5")
cDNAStringSet <- DNAStringSet(c("GCATCCATTAC", "AATCGCCATCC", "GCATACCTTAC", "GCATACCTTAC", "GCATACCTTAC"))
names(cDNAStringSet) <- c("seq1", "seq2", "seq3", "seq4", "seq5")
dDNAStringSet <- DNAStringSet(c("GCATCCATTAC", "AATCGCCATCC", "GCATACCTTAC", "GCATACCTTAC", "GCATACCTTAC"))
names(dDNAStringSet) <- c("seq1", "seq2", "seq3", "seq4", "seq5")
Biglist<-list(A=aDNAStringSet, B=bDNAStringSet, C=cDNAStringSet, D=dDNAStringSet)
patterns <- c("seq2", "seq4", "seq5")
使用grep
我能够隔离elements
,但这不是我想要的:
newlist<-Biglist[grep("A", names(Biglist))]
使用lapply
应该是正确的方法,但是这一行会导致错误:
newlist<-lapply(Biglist, function(y) y[y %in% patterns])
Error in .Call2("new_XStringSet_from_CHARACTER", ans_class, ans_elementType, : key 101 (char 'e') not in lookup table
我也不理解错误按摩。有任何想法吗?
因为你正在使用S4类,所以你需要一个不同的子集方法,在这种情况下,它是@
#To use `DNAStringSet` function install Biostrings using the following
#source("http://www.bioconductor.org/biocLite.R")
#biocLite(c("Biostrings"))
#library(Biostrings)
lapply(Biglist, function(x) x[x@ranges@NAMES %in% patterns])