假设我有这个DNAStringSet(例如)
-keepparameternames
,而我有一个向量,其中包含一些序列的名称:
dataset1
A DNAStringSet instance of length 38874
width seq names
[1] 2617 GGC yellow
[2] 4306 ACG blue
[3] 1070 CTC red
[4] 1870 CAC white
[5] 3732 CAC brown
... ... ...
[38870] 390 TGC black
[38871] 1970 CAG orange
如何对dataset2 <- c("blue","black","red","brown")
中名称在dataset1
中的那些序列进行子集化?
答案 0 :(得分:1)
{@Activity} = "P/U"
对象可以按名称作为子集,就像使用方括号符号的普通R列表一样:
DNAStringSet
就您而言,您只需要afastafile <- DNAStringSet(c("GCAAATGGG", "CCCGGGTT", "AAAGGGTT", "TTTGGGCC"))
names(afastafile) <- c("ABC1_1", "ABC2_1", "ABC3_1", "ABC4_1")
afastafile
A DNAStringSet instance of length 4
width seq names
[1] 9 GCAAATGGG ABC1_1
[2] 8 CCCGGGTT ABC2_1
[3] 8 AAAGGGTT ABC3_1
[4] 8 TTTGGGCC ABC4_1
nms <- c('ABC1_1', 'ABC3_1')
afastafile[nms]
A DNAStringSet instance of length 2
width seq names
[1] 9 GCAAATGGG ABC1_1
[2] 8 AAAGGGTT ABC3_1