// Rosetta Code problem: http://rosettacode.org/wiki/Sequence_mutation // by Galileo, 07/2022 r = int(ran(300)) for i = 1 to 200 + r : dna$ = dna$ + mid$("ACGT", int(ran(4))+1, 1) : next sub show() local acgt(4), i, j, x, total for i = 1 to len(dna$) x = instr("ACGT", mid$(dna$, i, 1)) acgt(x) = acgt(x) + 1 next for i = 1 to 4 : total = total + acgt(i) : next for i = 1 to len(dna$) step 50 print i, ":\t"; for j = 0 to 49 step 10 print mid$(dna$, i+j, 10), " "; next print next print "\nBase counts: A: ", acgt(1), ", C: ", acgt(2), ", G: ", acgt(3), ", T: ", acgt(4), ", total: ", total end sub sub mutate() local i, p, sdi$, rep$, was$ print for i = 1 to 10 p = int(ran(len(dna$))) + 1 sdi$ = mid$("SDI", int(ran(3)) + 1, 1) rep$ = mid$("ACGT", int(ran(4)) + 1, 1) was$ = mid$(dna$, p, 1) switch sdi$ case "S": mid$(dna$, p, 1) = rep$ print "swapped ", was$, " at ", p, " for ", rep$ : break case "D": dna$ = left$(dna$, p - 1) + right$(dna$, len(dna$) - p) print "deleted ", was$, " at ", p : break case "I": dna$ = left$(dna$, p - 1) + rep$ + right$(dna$, (len(dna$) - p + 1)) print "inserted ", rep$, " at ", p, ", before ", was$ : break end switch next print end sub show() mutate() show()