-
Notifications
You must be signed in to change notification settings - Fork 1
/
getseqs.R
49 lines (48 loc) · 856 Bytes
/
getseqs.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#Converts a nonnegative decimal integer to base b
#
#Args
#num A nonnegative decimal integer
#b THe desired base
#
#Output
#A vector of the integers 0, 1, ..., b-1 representing the digits of the base b number
#
#Note; no error checking of inputs
#
dec_to_baseb<-function(num,b)
{
res<-(num %% b)
num<-(num-res)/b
while (num!=0)
{
h<-(num %% b)
res<-c(h,res)
num<-(num-h)/b
}
return(res)
}
#Given a length, finds all sequences of A, T, G, C of that length
#
#Args
#len A single number
#
#Output
#A vector of all of 'em
#
#Note: no error checking
#
getseqs<-function(len)
{
bases<-c("A","C","G","T")
res<-c()
for (counter in 0:(4^len-1))
{
h<-dec_to_baseb(counter,4)
if (length(h)<len)
{
h<-c(rep(0,len-length(h)),h)
}
res<-c(res,paste0(bases[h+1],collapse=""))
}
return(res)
}