Bioinformatics/Global alignment: Difference between revisions
Content added Content deleted
(→{{header|Perl}}: added Pascal by prepending to perl) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 58: | Line 58: | ||
{{trans|Nim}} |
{{trans|Nim}} |
||
< |
<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)</ |
printCounts(scs)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 185: | Line 185: | ||
=={{header|Go}}== |
=={{header|Go}}== |
||
{{trans|Julia}} |
{{trans|Julia}} |
||
< |
<syntaxhighlight lang=go>package main |
||
import ( |
import ( |
||
Line 355: | Line 355: | ||
printCounts(scs) |
printCounts(scs) |
||
} |
} |
||
}</ |
}</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 ;</ |
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</ |
tasks</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 558: | Line 558: | ||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
< |
<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 |
||
</ |
</syntaxhighlight>{{out}} |
||
<pre> |
<pre> |
||
Nucleotide counts for TAAGAA: |
Nucleotide counts for TAAGAA: |
||
Line 684: | Line 684: | ||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
{{trans|Wren}} |
{{trans|Wren}} |
||
< |
<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()</ |
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. |
||
< |
<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}}== |
||
< |
<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; |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,227: | Line 1,227: | ||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
<!--< |
<!--<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> |
||
<!--</ |
<!--</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}} |
||
< |
<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 |
<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}} |
||
< |
<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) |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |