I have a list of DNA sequences and I want to mix the contents.
Let's say dna_lst:
[1] AATTAATTCC
[2] ATCGATCG
[3] TTTAACCCCCGG
I want to generate mix dna content like:dna_mix:
[1] TACAATTACT
[2] CATGCTAG
[3] CCTGATCTCGAC
how can I do this in R?
thanks.
Something like that :
dna_mix<-sapply(dna_lst,function(dna){paste(sample(strsplit(dna,"")[[1]]),collapse="")})
can work if what you want is a "random mixing"
> dna_mix
AATTAATTCC ATCGATCG TTTAACCCCCGG
"TTTATCAAAC" "TAACCGGT" "CTACTCACGGTC"
with a list of factor (if each sequence is an element of the list) :
lapply(dna_lst,function(dna){paste(sample(strsplit(as.character(dna),"")[[1]]),collapse="")})
should work.