rsite <- function(inseq, seq){ # inseq: vector containing input DNA sequence, # A=1, C=2, G=3, and T=4 # seq: vector for the restriction site, length m # Make/initialize vector to hold site # positions found in inseq xxx <- rep(0, length(inseq)) m <- length(seq) #To record whether position of inseq matches seq truth<-rep(0, m) # Check each position to see if a site starts there. for(i in 1:(length(inseq) - (length(seq) - 1))) { for(j in 1:m) { if(inseq[i + j - 1] == seq[j]) { truth[j] <- 1 # Record match to jth position. } } if(sum(truth[]) == m){# Check whether all positions match xxx[i] <- i # Record site if all positions match } truth <- rep(0, m) # Reinitialize for next loop cycle } # Write vector of restriction site positions stored in xxx L <- xxx[xxx > 0] return(L) }