Bioinformatics/Global alignment: Difference between revisions

Content added Content deleted
(→‎{{header|Perl}}: added Pascal by prepending to perl)
m (syntax highlighting fixup automation)
Line 58: Line 58:
{{trans|Nim}}
{{trans|Nim}}


<lang 11l>-V ACGT = [‘A’, ‘C’, ‘G’, ‘T’]
<syntaxhighlight lang=11l>-V ACGT = [‘A’, ‘C’, ‘G’, ‘T’]


F permutations(slist)
F permutations(slist)
Line 137: Line 137:
L(test) TestSequences
L(test) TestSequences
V scs = shortestCommonSuperstring(test)
V scs = shortestCommonSuperstring(test)
printCounts(scs)</lang>
printCounts(scs)</syntaxhighlight>


{{out}}
{{out}}
Line 185: Line 185:
=={{header|Go}}==
=={{header|Go}}==
{{trans|Julia}}
{{trans|Julia}}
<lang go>package main
<syntaxhighlight lang=go>package main


import (
import (
Line 355: Line 355:
printCounts(scs)
printCounts(scs)
}
}
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}
Line 403: Line 403:
{{works with|jq}}
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
'''Works with gojq, the Go implementation of jq'''
<syntaxhighlight lang=jq>
<lang jq>
### Generic helper functions
### Generic helper functions


Line 415: Line 415:
range(0;length) as $i
range(0;length) as $i
| [.[$i]] + (del(.[$i])|permutations)
| [.[$i]] + (del(.[$i])|permutations)
end ;</lang><lang jq>
end ;</syntaxhighlight><syntaxhighlight lang=jq>
# Give a synoptic view of the input string,
# Give a synoptic view of the input string,
# highlighting the occurrence of ACGTU letters
# highlighting the occurrence of ACGTU letters
Line 475: Line 475:
else . end)
else . end)
| .shortestsuper;
| .shortestsuper;
</syntaxhighlight>
</lang>
'''The specific tasks'''
'''The specific tasks'''
<syntaxhighlight lang=jq>
<lang jq>
def examples:
def examples:
[
[
Line 509: Line 509:
| "Task \($i+1):", ($examples[$i]|t), "";
| "Task \($i+1):", ($examples[$i]|t), "";


tasks</lang>
tasks</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 558: Line 558:


=={{header|Julia}}==
=={{header|Julia}}==
<lang julia>using Combinatorics
<syntaxhighlight lang=julia>using Combinatorics


""" Given a DNA sequence, report the sequence, length and base counts"""
""" Given a DNA sequence, report the sequence, length and base counts"""
Line 639: Line 639:
printcounts(scs)
printcounts(scs)
end
end
</lang>{{out}}
</syntaxhighlight>{{out}}
<pre>
<pre>
Nucleotide counts for TAAGAA:
Nucleotide counts for TAAGAA:
Line 684: Line 684:
=={{header|Nim}}==
=={{header|Nim}}==
{{trans|Wren}}
{{trans|Wren}}
<lang Nim>import algorithm, sequtils, strformat, strutils, tables
<syntaxhighlight lang=Nim>import algorithm, sequtils, strformat, strutils, tables


const ACGT = ['A', 'C', 'G', 'T'] # Four DNA bases.
const ACGT = ['A', 'C', 'G', 'T'] # Four DNA bases.
Line 765: Line 765:
for test in TestSequences:
for test in TestSequences:
let scs = test.shortestCommonSuperstring
let scs = test.shortestCommonSuperstring
scs.printCounts()</lang>
scs.printCounts()</syntaxhighlight>


{{out}}
{{out}}
Line 812: Line 812:
Here nearly no runtime.But see [[N-queens_problem]] that using permutation is not the way for > 17<BR>
Here nearly no runtime.But see [[N-queens_problem]] that using permutation is not the way for > 17<BR>
Of course this is more a traveling salesman problem.
Of course this is more a traveling salesman problem.
<lang pascal>
<syntaxhighlight lang=pascal>
program BaseInDNA;
program BaseInDNA;
{$IFDEF FPC}
{$IFDEF FPC}
Line 1,103: Line 1,103:
find;
find;
END.
END.
</syntaxhighlight>
</lang>
{{out}}
{{out}}
<pre>
<pre>
Line 1,127: Line 1,127:


=={{header|Perl}}==
=={{header|Perl}}==
<lang perl>#!/usr/bin/perl
<syntaxhighlight lang=perl>#!/usr/bin/perl


use strict; # https://rosettacode.org/wiki/Bioinformatics/global_alignment
use strict; # https://rosettacode.org/wiki/Bioinformatics/global_alignment
Line 1,210: Line 1,210:
use Data::Dump 'dd'; dd \%ch;
use Data::Dump 'dd'; dd \%ch;
}
}
}</lang>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
Line 1,227: Line 1,227:


=={{header|Phix}}==
=={{header|Phix}}==
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang=Phix>(phixonline)-->
<span style="color: #008080;">procedure</span> <span style="color: #000000;">printcounts</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">ss</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">procedure</span> <span style="color: #000000;">printcounts</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">ss</span><span style="color: #0000FF;">)</span>
<span style="color: #000080;font-style:italic;">-- Given DNA sequence(s), report the sequence, length and base counts</span>
<span style="color: #000080;font-style:italic;">-- Given DNA sequence(s), report the sequence, length and base counts</span>
Line 1,312: Line 1,312:
<span style="color: #0000FF;">}</span>
<span style="color: #0000FF;">}</span>
<span style="color: #7060A8;">papply</span><span style="color: #0000FF;">(</span><span style="color: #000000;">tests</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">shortest_common_superstring</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">papply</span><span style="color: #0000FF;">(</span><span style="color: #000000;">tests</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">shortest_common_superstring</span><span style="color: #0000FF;">)</span>
<!--</lang>-->
<!--</syntaxhighlight>-->
{{out}}
{{out}}
(Shows three length-6 results for the first test)
(Shows three length-6 results for the first test)
Line 1,343: Line 1,343:
{{trans|Go}}
{{trans|Go}}


<lang python>import os
<syntaxhighlight lang=python>import os


from collections import Counter
from collections import Counter
Line 1,459: Line 1,459:
#
#
# .. if you don't want all possible shortest superstrings.
# .. if you don't want all possible shortest superstrings.
</syntaxhighlight>
</lang>


{{out}}
{{out}}
Line 1,527: Line 1,527:
{{trans|Go}}
{{trans|Go}}
{{trans|Julia}}
{{trans|Julia}}
<lang perl6># 20210209 Raku programming solution
<syntaxhighlight lang=raku line># 20210209 Raku programming solution


sub printCounts(\seq) {
sub printCounts(\seq) {
Line 1,583: Line 1,583:
>,
>,
)
)
</syntaxhighlight>
</lang>


{{out}}
{{out}}
Line 1,607: Line 1,607:
{{libheader|Wren-str}}
{{libheader|Wren-str}}
{{libheader|Wren-math}}
{{libheader|Wren-math}}
<lang ecmascript>import "/fmt" for Fmt
<syntaxhighlight lang=ecmascript>import "/fmt" for Fmt
import "/seq" for Lst
import "/seq" for Lst
import "/str" for Str
import "/str" for Str
Line 1,725: Line 1,725:
var scs = shortestCommonSuperstring.call(test)
var scs = shortestCommonSuperstring.call(test)
printCounts.call(scs)
printCounts.call(scs)
}</lang>
}</syntaxhighlight>


{{out}}
{{out}}