Computational Example 3.5 rsite <- function(inseq, seq){ # inseq: vector containing input DNA sequence, # A=1, C=2, G=3, and T =4 # seq: vector for restriction site, length m, coded as above. # Make/initialize vector to hold site # positions found in inseq xxx <- rep(0, length(inseq)) m <- length(seq) # Length of restriction recognition sequence truth <- rep(0, m) # To record whether pos. of inseq match seq # 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 pos. } } 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) }