Bioinformatics/Sequence mutation: Difference between revisions
Content deleted Content added
No edit summary |
→{{header|Lua}}: added Lua solution |
||
Line 1,991: | Line 1,991: | ||
Total 502 |
Total 502 |
||
</pre> |
</pre> |
||
=={{header|Lua}}== |
|||
Using the <code>prettyprint()</code> function from [[Bioinformatics/base_count#Lua]] (not replicated here) |
|||
<lang lua>math.randomseed(os.time()) |
|||
bases = {"A","C","T","G"} |
|||
function randbase() return bases[math.random(#bases)] end |
|||
function mutate(seq) |
|||
local i,h = math.random(#seq), "%-6s %3s at %3d" |
|||
local old,new = seq:sub(i,i), randbase() |
|||
local ops = { |
|||
function(s) h=h:format("Swap", old..">"..new, i) return s:sub(1,i-1)..new..s:sub(i+1) end, |
|||
function(s) h=h:format("Delete", " -"..old, i) return s:sub(1,i-1)..s:sub(i+1) end, |
|||
function(s) h=h:format("Insert", " +"..new, i) return s:sub(1,i-1)..new..s:sub(i) end, |
|||
} |
|||
local weighted = { 1,1,2,3 } |
|||
local n = weighted[math.random(#weighted)] |
|||
return ops[n](seq), h |
|||
end |
|||
local seq,hist="",{} for i = 1, 200 do seq=seq..randbase() end |
|||
print("ORIGINAL:") |
|||
prettyprint(seq) |
|||
print() |
|||
for i = 1, 10 do seq,h=mutate(seq) hist[#hist+1]=h end |
|||
print("MUTATIONS:") |
|||
for i,h in ipairs(hist) do print(" "..h) end |
|||
print() |
|||
print("MUTATED:") |
|||
prettyprint(seq)</lang> |
|||
{{out}} |
|||
<pre>ORIGINAL: |
|||
LOCUS AB000000 200 bp mRNA linear HUM 01-JAN-2001 |
|||
BASE COUNT 50 a 47 c 51 g 52 t |
|||
ORIGIN |
|||
1 atggatccga cgtgattata ttcactatgg ggcaatcgca cattagtttt atctccatca |
|||
61 gcgacacgat ggggatcaat gggctgctac tggagacgtc cgatgcgatg attggtaatt |
|||
121 gcatagagtg gatctccttt aacctagtag aaacgccctt ccggttcagc atggcgagtg |
|||
181 cgtacaacgt cacccagact |
|||
MUTATIONS: |
|||
Insert +A at 190 |
|||
Delete -C at 134 |
|||
Swap A>G at 57 |
|||
Delete -G at 83 |
|||
Insert +T at 81 |
|||
Swap T>T at 164 |
|||
Delete -C at 199 |
|||
Swap T>G at 147 |
|||
Swap C>G at 33 |
|||
Swap C>G at 191 |
|||
MUTATED: |
|||
LOCUS AB000000 199 bp mRNA linear HUM 01-JAN-2001 |
|||
BASE COUNT 50 a 43 c 54 g 52 t |
|||
ORIGIN |
|||
1 atggatccga cgtgattata ttcactatgg gggaatcgca cattagtttt atctccgtca |
|||
61 gcgacacgat ggggatcaat tggctgctac tggagacgtc cgatgcgatg attggtaatt |
|||
121 gcatagagtg gattccttta acctaggaga aacgcccttc cggttcagca tggcgagtgc |
|||
181 gtacaacgat gacccagat</pre> |
|||
=={{header|Mathematica}} / {{header|Wolfram Language}}== |
=={{header|Mathematica}} / {{header|Wolfram Language}}== |