Bioinformatics/Sequence mutation: Difference between revisions

m
syntax highlighting fixup automation
m (syntax highlighting fixup automation)
Line 19:
{{trans|Python}}
 
<langsyntaxhighlight lang=11l>UInt32 seed = 0
F nonrandom(n)
:seed = 1664525 * :seed + 1013904223
Line 69:
print(‘ #10 @#.’.format(kind, index))
print()
seq_pp(mseq)</langsyntaxhighlight>
 
{{out}}
Line 115:
 
=={{header|Ada}}==
<langsyntaxhighlight lang=Ada>with Ada.Containers.Vectors;
with Ada.Numerics.Discrete_Random;
with Ada.Text_Io;
Line 231:
Pretty_Print (Sequence);
 
end Mutations;</langsyntaxhighlight>
{{out}}
<pre>Initial sequence:
Line 267:
=={{header|Arturo}}==
 
<langsyntaxhighlight lang=rebol>bases: ["A" "T" "G" "C"]
dna: map 1..200 => [sample bases]
 
Line 334:
print "------------------------------"
prettyPrint dna
print ""</langsyntaxhighlight>
 
{{out}}
Line 373:
=={{header|C}}==
Adenine ( A ) is always swapped for Thymine ( T ) and vice versa. Similarly with Cytosine ( C ) and Guanine ( G ).
<syntaxhighlight lang=C>
<lang C>
#include<stdlib.h>
#include<stdio.h>
Line 585:
return 0;
}
</syntaxhighlight>
</lang>
Sample run :
<pre>
Line 674:
 
=={{header|C++}}==
<langsyntaxhighlight lang=cpp>#include <array>
#include <iomanip>
#include <iostream>
Line 797:
sequence_generator::print_sequence(std::cout, sequence);
return 0;
}</langsyntaxhighlight>
 
{{out}}
Line 836:
:: :genome <i><Genome Sequence></i>)
<b>All keys are optional. <i><Genome length></i> is discarded when :genome is set.</b>
<langsyntaxhighlight lang=lisp>
(defun random_base ()
(random 4))
Line 910:
(t (delete_base genome)))))
(output_genome_info genome "MUTATED"))
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 981:
 
=={{header|Factor}}==
<langsyntaxhighlight lang=factor>USING: assocs combinators.random formatting grouping io kernel
macros math math.statistics namespaces prettyprint quotations
random sequences sorting ;
Line 1,054:
[ mutate ] curry times nl "MUTATED " write show-dna ;
 
MAIN: main</langsyntaxhighlight>
{{out}}
<pre>
Line 1,103:
 
=={{header|Go}}==
<langsyntaxhighlight lang=go>package main
 
import (
Line 1,201:
fmt.Println()
prettyPrint(dna, 50)
}</langsyntaxhighlight>
 
{{out}}
Line 1,257:
</pre>
=={{header|Haskell}}==
<langsyntaxhighlight lang=haskell>import Data.List (group, sort)
import Data.List.Split (chunksOf)
import System.Random (Random, randomR, random, newStdGen, randoms, getStdRandom)
Line 1,336:
showSequence = mapM_ (uncurry (printf "%3d: %s\n")) . chunkedDNASequence
showBaseCounts = mapM_ (uncurry (printf "%s: %3d\n")) . baseCounts
showSumBaseCounts xs = putStrLn (replicate 6 '-') >> printf "Σ: %d\n\n" (length xs)</langsyntaxhighlight>
{{out}}
<pre>Initial Sequence:
Line 1,379:
 
=={{header|J}}==
<langsyntaxhighlight lang=J>ACGT=: 'ACGT'
MUTS=: ;: 'del ins mut'
 
Line 1,414:
)
 
simulate=: (sim@(1 1 1&; &. |. ))`sim@.(3=#)</langsyntaxhighlight>
 
{{out}}
Line 1,508:
 
=={{header|Java}}==
<langsyntaxhighlight lang=java>import java.util.Arrays;
import java.util.Random;
 
Line 1,620:
private static final int OP_COUNT = 3;
private static final char[] BASES = {'A', 'C', 'G', 'T'};
}</langsyntaxhighlight>
 
{{out}}
Line 1,654:
 
=={{header|JavaScript}}==
<langsyntaxhighlight lang=javascript>// Basic set-up
const numBases = 250
const numMutations = 30
Line 1,811:
console.log('\nMUTATED BASE COUNTS:')
printBases(mut);
</syntaxhighlight>
</lang>
 
{{out}}
Line 1,878:
 
=={{header|Julia}}==
<langsyntaxhighlight lang=julia>dnabases = ['A', 'C', 'G', 'T']
randpos(seq) = rand(1:length(seq)) # 1
mutateat(pos, seq) = (s = seq[:]; s[pos] = rand(dnabases); s) # 2-1
Line 1,931:
 
testbioseq()
</langsyntaxhighlight>{{out}}
<pre>
500nt DNA sequence:
Line 1,994:
=={{header|Lua}}==
Using the <code>prettyprint()</code> function from [[Bioinformatics/base_count#Lua]] (not replicated here)
<langsyntaxhighlight lang=lua>math.randomseed(os.time())
bases = {"A","C","T","G"}
function randbase() return bases[math.random(#bases)] end
Line 2,022:
 
print("MUTATED:")
prettyprint(seq)</langsyntaxhighlight>
{{out}}
<pre>ORIGINAL:
Line 2,056:
=={{header|Mathematica}} / {{header|Wolfram Language}}==
BioSequence is a fundamental data type in Mathematica:
<langsyntaxhighlight lang=Mathematica>SeedRandom[13122345];
seq = BioSequence["DNA", "ATAAACGTACGTTTTTAGGCT"];
randompos = RandomInteger[seq["SequenceLength"]];
Line 2,090:
ends = Rest[Accumulate[Prepend[StringLength /@ parts, 0]]];
StringRiffle[MapThread[ToString[#1] <> "-" <> ToString[#2] <> ": " <> #3 &, {begins, ends, parts}], "\n"]
Tally[Characters[seq["SequenceString"]]]</langsyntaxhighlight>
{{out}}
<pre>1-50: TAGCAGGGGAATTGTCGACTCCCGGGTTTCAATTGCCAACCAAGCATATT
Line 2,106:
 
=={{header|Nim}}==
<langsyntaxhighlight lang=Nim>import random
import strformat
import strutils
Line 2,222:
echo "\nMutated sequence"
echo "————————————————\n"
dnaSeq.display()</langsyntaxhighlight>
 
{{out}}
Line 2,261:
=={{header|Perl}}==
{{trans|Raku}}
<langsyntaxhighlight lang=perl>use strict;
use warnings;
use feature 'say';
Line 2,305:
say "Total bases: ". length $mutate;
say "$_: $cnt{$_}" for @bases;
</syntaxhighlight>
</lang>
{{out}}
<pre>Original DNA strand:
Line 2,332:
 
=={{header|Phix}}==
<!--<langsyntaxhighlight lang=Phix>(phixonline)-->
<span style="color: #004080;">string</span> <span style="color: #000000;">dna</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #008000;">' '</span><span style="color: #0000FF;">,</span><span style="color: #000000;">200</span><span style="color: #0000FF;">+</span><span style="color: #7060A8;">rand</span><span style="color: #0000FF;">(</span><span style="color: #000000;">300</span><span style="color: #0000FF;">))</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dna</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span> <span style="color: #000000;">dna</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]</span> <span style="color: #0000FF;">=</span> <span style="color: #008000;">"ACGT"</span><span style="color: #0000FF;">[</span><span style="color: #7060A8;">rand</span><span style="color: #0000FF;">(</span><span style="color: #000000;">4</span><span style="color: #0000FF;">)]</span> <span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
Line 2,368:
<span style="color: #000000;">mutate</span><span style="color: #0000FF;">()</span>
<span style="color: #000000;">show</span><span style="color: #0000FF;">()</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 2,410:
 
=={{header|PureBasic}}==
<langsyntaxhighlight lang=PureBasic>#BASE$="ACGT"
#SEQLEN=200
#PROTOCOL=#True
Line 2,467:
PrintN("After 10 mutations:")
pprint()
Input()</langsyntaxhighlight>
{{out}}
<pre>Initial sequence:
Line 2,499:
Similarly parameter choice is chosen from to give the base for substitution or insertion - the more any base appears, the more likely it is to be chosen in any insertion/substitution.
<langsyntaxhighlight lang=python>import random
from collections import Counter
 
Line 2,544:
print(f" {kind:>10} @{index}")
print()
seq_pp(mseq)</langsyntaxhighlight>
 
{{out}}
Line 2,592:
<code>prettyprint</code> and <code>tallybases</code> are defined at [[Bioinformatics/base count#Quackery]].
 
<langsyntaxhighlight lang=Quackery> [ $ "ACGT" 4 random peek ] is randomgene ( --> c )
 
[ $ "" swap times
Line 2,609:
cr cr say "Mutating..." cr
10 times mutate
dup prettyprint cr cr tallybases</langsyntaxhighlight>
 
{{out}}
Line 2,643:
=={{header|Racket}}==
 
<langsyntaxhighlight lang=racket>#lang racket
 
(define current-S-weight (make-parameter 1))
Line 2,720:
(define s+d (parameterize ((current-D-weight 5)) (for/fold ((s initial-sequence)) ((_ 10)) (mutate s))))
(newline)
(report-sequence s+d))</langsyntaxhighlight>
 
{{out}}
Line 2,791:
 
 
<syntaxhighlight lang=raku perl6line>my @bases = <A C G T>;
 
# The DNA strand
Line 2,822:
sub diff ($orig, $repl) {
($orig.comb Z $repl.comb).map( -> ($o, $r) { $o eq $r ?? $o !! $r.lc }).join
}</langsyntaxhighlight>
{{out}}
<pre>ORIGINAL DNA STRAND:
Line 2,849:
 
=={{header|Ring}}==
<langsyntaxhighlight lang=ring>
row = 0
dnaList = []
Line 2,962:
total = dnaBase["A"] + dnaBase["T"] + dnaBase["C"] + dnaBase["G"]
see "Total: " + total+ nl + nl
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 3,010:
 
=={{header|Ruby}}==
<langsyntaxhighlight lang=ruby>class DNA_Seq
attr_accessor :seq
Line 3,044:
test.delete
puts test
</syntaxhighlight>
</lang>
{{out}}
<pre> 0 TAAGGTGAGGAGTGTGATGGAGTTCGGTGGCTAGCCACAAATACAACACA
Line 3,067:
=={{header|Swift}}==
 
<langsyntaxhighlight lang=swift>let bases: [Character] = ["A", "C", "G", "T"]
 
enum Action: CaseIterable {
Line 3,123:
}
 
printSeq(d)</langsyntaxhighlight>
 
{{out}}
Line 3,154:
=={{header|Vlang}}==
{{trans|Go}}
<langsyntaxhighlight lang=vlang>import rand
import rand.seed
 
Line 3,246:
println('')
pretty_print(dna, 50)
}</langsyntaxhighlight>
 
{{out}}
Line 3,306:
{{libheader|Wren-sort}}
{{libheader|Wren-fmt}}
<langsyntaxhighlight lang=ecmascript>import "random" for Random
import "/fmt" for Fmt
import "/sort" for Sort
Line 3,383:
for (i in 0...muts) dna = mutate.call(dna, w)
System.print()
prettyPrint.call(dna, 50)</langsyntaxhighlight>
 
{{out}}
Line 3,441:
=={{header|Yabasic}}==
{{trans|Phix}}
<langsyntaxhighlight lang=Yabasic>// Rosetta Code problem: http://rosettacode.org/wiki/Sequence_mutation
// by Galileo, 07/2022
 
Line 3,493:
show()
mutate()
show()</langsyntaxhighlight>
{{out}}
<pre>1: TCCATCGTGG GATCGCTCTA GCGGTATGCT ATCATTCCTA TAGCAATTCT
Line 3,528:
 
=={{header|zkl}}==
<langsyntaxhighlight lang=zkl>var [const] bases="ACGT", lbases=bases.toLower();
dna:=(190).pump(Data().howza(3),(0).random.fp(0,4),bases.get); // bucket of bytes
 
Line 3,560:
[0..*,50].zipWith(fcn(n,bases){ println("%6d: %s".fmt(n,bases.concat())) },
dna.walker().walk.fp(50)).pump(Void); // .pump forces the iterator
}</langsyntaxhighlight>
{{out}}
<pre>
Line 3,590:
 
=={{header|Rust}}==
<langsyntaxhighlight lang=Rust>
use rand::prelude::*;
use std::collections::HashMap;
Line 3,687:
println!("\nMutated sequence:\n{}", seq);
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
10,327

edits