Task

Given a string of characters A, C, G, and T representing a DNA sequence write a routine to mutate the sequence, (string) by:

 Choosing a random base position in the sequence.
 Mutate the sequence by doing one of either:
 Swap the base at that position by changing it to one of A, C, G, or T. (which has a chance of swapping the base for the same base)
 Delete the chosen base at the position.
 Insert another base randomly chosen from A,C, G, or T into the sequence at that position.
 Randomly generate a test DNA sequence of at least 200 bases
 "Pretty print" the sequence and a count of its size, and the count of each base in the sequence
 Mutate the sequence ten times.
 "Pretty print" the sequence after all mutations, and a count of its size, and the count of each base in the sequence.
Extra credit

 Give more information on the individual mutations applied.
 Allow mutations to be weighted and/or chosen.
ACGT=: 'ACGT'
MUTS=: ;: 'del ins mut'
 
NB. generate sequence of size y of uniformly selected nucleotides.
NB. represent sequences as ints in range i.4 pretty printed. nuc
NB. defined separately to avoid fixing value inside mutation
NB. functions.
nuc=: monad : '?4'
dna=: nuc"0 @ i.
 
NB. randomly mutate nucleotide at a random index by deletion insertion
NB. or mutation of a nucleotide.
del=: {.,[:}.}.
ins=: {.,nuc@],}.
mut=: {.,nuc@],[:}.}.
 
NB. pretty print nucleotides in rows of 50 with numbering
seq=: [: (;~ [: (4&":"0) 50*i.@#) _50]\{&ACGT
 
sim=: monad define
'n k ws'=. y        NB. initial size, mutations, and weights for mutations
ws=. (% +/) ws      NB. normalize weights
A=.0$]D0=.D=. dna n NB. initial dna and history of actions
 
NB. k times do a random action according to weights and record it
for. i.k do.
  D=.". action=. (":?#D),' ',(":MUTS{::~(+/\ws)I.?0),' D'
  A=. action ; A
end.
 
echo 'actions';,. A-.a:
echo ('mutation';'probability') , MUTS ,. <"0 ws
('start';'end'),.(seq D0) ,: seq D
)
 
simulate=: (sim@(1 1 1&; &. |. ))`sim@.(3=#)