How to resolve the algorithm Bioinformatics/Sequence mutation step by step in the Raku programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Bioinformatics/Sequence mutation step by step in the Raku programming language
Table of Contents
Problem Statement
Given a string of characters A, C, G, and T representing a DNA sequence write a routine to mutate the sequence, (string) by:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Bioinformatics/Sequence mutation step by step in the Raku programming language
Source code in the raku programming language
my @bases = ;
# The DNA strand
my $dna = @bases.roll(200).join;
# The Task
put "ORIGINAL DNA STRAND:";
put pretty $dna;
put "\nTotal bases: ", +my $bases = $dna.comb.Bag;
put $bases.sort( ~*.key ).join: "\n";
put "\nMUTATED DNA STRAND:";
my $mutate = $dna.&mutate(10);
put pretty diff $dna, $mutate;
put "\nTotal bases: ", +my $mutated = $mutate.comb.Bag;
put $mutated.sort( ~*.key ).join: "\n";
# Helper subs
sub pretty ($string, $wrap = 50) {
$string.comb($wrap).map( { sprintf "%8d: %s", $++ * $wrap, $_ } ).join: "\n"
}
sub mutate ($dna is copy, $count = 1) {
$dna.substr-rw((^$dna.chars).roll, 1) = @bases.roll for ^$count;
$dna
}
sub diff ($orig, $repl) {
($orig.comb Z $repl.comb).map( -> ($o, $r) { $o eq $r ?? $o !! $r.lc }).join
}
You may also check:How to resolve the algorithm Password generator step by step in the Python programming language
You may also check:How to resolve the algorithm Trabb Pardo–Knuth algorithm step by step in the Haskell programming language
You may also check:How to resolve the algorithm Integer comparison step by step in the Rockstar programming language
You may also check:How to resolve the algorithm Metallic ratios step by step in the REXX programming language
You may also check:How to resolve the algorithm Knuth shuffle step by step in the XPL0 programming language