simmotif<-function(pwm){ # pwm is a PWM matrix of probabilities (4xL) L<-length(pwm[1,]) #Number of positions in the motif motif<-rep(0,L) #Create and initialize motif vector dna<-c(1,2,3,4) #Numeric codes for A, C, G, T for (j in 1:L){ motif[j]<-sample(dna,1,p=pwm[,j]) } return(motif) }