在R中生成所有可能的kmers

问题描述 投票:-2回答:3

我有一个字母或符号的向量,比如base = c('A','T','G','C'),是否有更短更有效的方式(现有函数)来生成所有可能的k-除了使用嵌套for循环或sapply之外,给定k的mers?

r
3个回答
0
投票

qazxsw poi具有qazxsw poi功能,允许重复采样。

要使用大于45的n值,您需要增加R的递归限制。有关如何执行此操作的详细信息,请参阅options命令的expression参数。

gtools

要使用permutation,你需要通过基于k的大小复制library(gtools) bases <- c("A","T","C","G") permutations(n = length(bases), v = bases, r = 3, repeats.allowed = T) # [,1] [,2] [,3] # [1,] "A" "A" "A" # [2,] "A" "A" "C" # [3,] "A" "A" "G" # [4,] "A" "A" "T" # [5,] "A" "C" "A" # [6,] "A" "C" "C" # [7,] "A" "C" "G" # [8,] "A" "C" "T" # [9,] "A" "G" "A" # [10,] "A" "G" "C" # [11,] "A" "G" "G" # [12,] "A" "G" "T" # [13,] "A" "T" "A" # [14,] "A" "T" "C" # [15,] "A" "T" "G" # [16,] "A" "T" "T" # [17,] "C" "A" "A" # [18,] "C" "A" "C" # [19,] "C" "A" "G" # [20,] "C" "A" "T" # [21,] "C" "C" "A" # [22,] "C" "C" "C" # [23,] "C" "C" "G" # [24,] "C" "C" "T" # [25,] "C" "G" "A" # [26,] "C" "G" "C" # [27,] "C" "G" "G" # [28,] "C" "G" "T" # [29,] "C" "T" "A" # [30,] "C" "T" "C" # [31,] "C" "T" "G" # [32,] "C" "T" "T" # [33,] "G" "A" "A" # [34,] "G" "A" "C" # [35,] "G" "A" "G" # [36,] "G" "A" "T" # [37,] "G" "C" "A" # [38,] "G" "C" "C" # [39,] "G" "C" "G" # [40,] "G" "C" "T" # [41,] "G" "G" "A" # [42,] "G" "G" "C" # [43,] "G" "G" "G" # [44,] "G" "G" "T" # [45,] "G" "T" "A" # [46,] "G" "T" "C" # [47,] "G" "T" "G" # [48,] "G" "T" "T" # [49,] "T" "A" "A" # [50,] "T" "A" "C" # [51,] "T" "A" "G" # [52,] "T" "A" "T" # [53,] "T" "C" "A" # [54,] "T" "C" "C" # [55,] "T" "C" "G" # [56,] "T" "C" "T" # [57,] "T" "G" "A" # [58,] "T" "G" "C" # [59,] "T" "G" "G" # [60,] "T" "G" "T" # [61,] "T" "T" "A" # [62,] "T" "T" "C" # [63,] "T" "T" "G" # [64,] "T" "T" "T" 然后以unqique包装来做一些小技巧。

combn

1
投票

您可以使用bases在基础R中执行此操作

k <- 3
unique(t(combn(rep(bases, k), m = k)))
#      [,1] [,2] [,3]
# [1,] "A"  "T"  "C" 
# [2,] "A"  "T"  "G" 
# [3,] "A"  "T"  "A" 
# [4,] "A"  "T"  "T" 
# [5,] "A"  "C"  "G" 
# [6,] "A"  "C"  "A" 
# [7,] "A"  "C"  "T" 
# [8,] "A"  "C"  "C" 
# [9,] "A"  "G"  "A" 
# [10,] "A"  "G"  "T" 
# [11,] "A"  "G"  "C" 
# [12,] "A"  "G"  "G" 
# [13,] "A"  "A"  "T" 
# [14,] "A"  "A"  "C" 
# [15,] "A"  "A"  "G" 
# [16,] "A"  "A"  "A" 
# [17,] "T"  "C"  "G" 
# [18,] "T"  "C"  "A" 
# [19,] "T"  "C"  "T" 
# [20,] "T"  "C"  "C" 
# [21,] "T"  "G"  "A" 
# [22,] "T"  "G"  "T" 
# [23,] "T"  "G"  "C" 
# [24,] "T"  "G"  "G" 
# [25,] "T"  "A"  "T" 
# [26,] "T"  "A"  "C" 
# [27,] "T"  "A"  "G" 
# [28,] "T"  "A"  "A" 
# [29,] "T"  "T"  "C" 
# [30,] "T"  "T"  "G" 
# [31,] "T"  "T"  "A" 
# [32,] "T"  "T"  "T" 
# [33,] "C"  "G"  "A" 
# [34,] "C"  "G"  "T" 
# [35,] "C"  "G"  "C" 
# [36,] "C"  "G"  "G" 
# [37,] "C"  "A"  "T" 
# [38,] "C"  "A"  "C" 
# [39,] "C"  "A"  "G" 
# [40,] "C"  "A"  "A" 
# [41,] "C"  "T"  "C" 
# [42,] "C"  "T"  "G" 
# [43,] "C"  "T"  "A" 
# [44,] "C"  "T"  "T" 
# [45,] "C"  "C"  "G" 
# [46,] "C"  "C"  "A" 
# [47,] "C"  "C"  "T" 
# [48,] "C"  "C"  "C" 
# [49,] "G"  "A"  "T" 
# [50,] "G"  "A"  "C" 
# [51,] "G"  "A"  "G" 
# [52,] "G"  "A"  "A" 
# [53,] "G"  "T"  "C" 
# [54,] "G"  "T"  "G" 
# [55,] "G"  "T"  "A" 
# [56,] "G"  "T"  "T" 
# [57,] "G"  "C"  "G" 
# [58,] "G"  "C"  "A" 
# [59,] "G"  "C"  "T" 
# [60,] "G"  "C"  "C" 
# [61,] "G"  "G"  "A" 
# [62,] "G"  "G"  "T" 
# [63,] "G"  "G"  "C" 
# [64,] "G"  "G"  "G" 

0
投票

使用expand.grid包中的> bases=c('A','T','G','C') > expand.grid(bases, bases, bases) Var1 Var2 Var3 1 A A A 2 T A A 3 G A A 4 C A A 5 A T A 6 T T A 7 G T A 8 C T A 9 A G A 10 T G A 11 G G A 12 C G A 13 A C A 14 T C A 15 G C A 16 C C A 17 A A T 18 T A T 19 G A T 20 C A T 21 A T T 22 T T T 23 G T T 24 C T T 25 A G T 26 T G T 27 G G T 28 C G T 29 A C T 30 T C T 31 G C T 32 C C T 33 A A G 34 T A G 35 G A G 36 C A G 37 A T G 38 T T G 39 G T G 40 C T G 41 A G G 42 T G G 43 G G G 44 C G G 45 A C G 46 T C G 47 G C G 48 C C G 49 A A C 50 T A C 51 G A C 52 C A C 53 A T C 54 T T C 55 G T C 56 C T C 57 A G C 58 T G C 59 G G C 60 C G C 61 A C C 62 T C C 63 G C C 64 C C C 函数

一个例子:

permutations
© www.soinside.com 2019 - 2024. All rights reserved.