Bioinformatics/Subsequence: Difference between revisions

m
syntax highlighting fixup automation
(Added solution for Action!)
m (syntax highlighting fixup automation)
Line 9:
{{trans|Python}}
 
<langsyntaxhighlight lang=11l>UInt32 seed = 34
F nonrandom_choice(lst)
:seed = (1664525 * :seed + 1013904223) [&] FFFF'FFFF
Line 46:
print("\nSearch Sample: "sample_seq)
 
dna_findall(sample_seq, dna_seq)</langsyntaxhighlight>
 
{{out}}
Line 68:
 
=={{header|Action!}}==
<langsyntaxhighlight lang=Action!>DEFINE SEQLEN="200"
DEFINE SUBLEN="4"
 
Line 138:
PrintE("Not found")
FI
RETURN</langsyntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Bioinformatics_subsequence.png Screenshot from Atari 8-bit computer]
Line 161:
 
=={{header|Ada}}==
<langsyntaxhighlight lang=Ada>with Ada.Text_Io;
with Ada.Strings.Fixed;
with Ada.Numerics.Discrete_Random;
Line 225:
New_Line;
end loop;
end Sub_Sequence;</langsyntaxhighlight>
{{out}}
<pre>Search sequence:
Line 246:
=={{header|Arturo}}==
 
<langsyntaxhighlight lang=rebol>bases: [`A` `G` `C` `T`]
randSeq: join map 1..200 => [sample bases]
randSub: join map 1..4 => [sample bases]
Line 264:
print ["Found subsequence at position:" idx]
idx: idx + 1
]</langsyntaxhighlight>
 
{{out}}
Line 288:
=={{header|Factor}}==
{{works with|Factor|0.99 2021-02-05}}
<langsyntaxhighlight lang=factor>USING: accessors formatting grouping io kernel math
math.functions.integer-logs math.parser random regexp sequences ;
 
Line 314:
 
80 10 .biosub nl
600 39 .biosub nl</langsyntaxhighlight>
{{out}}
<pre>
Line 355:
=={{header|Go}}==
{{trans|Wren}}
<langsyntaxhighlight lang=go>package main
 
import (
Line 400:
fmt.Println()
findDnaSubsequence(600, 40)
}</langsyntaxhighlight>
 
{{out}}
Line 457:
`jot -r N MIN MAX` but a fourth argument can also be
used to specify a seed. An alternative would be to use `gshuf` along the lines of:
<syntaxhighlight lang=sh>
<lang sh>
# For 200 pseudo-random integers in the range 0 to 3 inclusive:
gshuf -i 0-3 -r -n 200 --random-source=/dev/random
</syntaxhighlight>
</lang>
 
Note that the indices shown below are offsets (i.e., the index origin is taken to be 0).
<syntaxhighlight lang=sh>
<lang sh>
#!/bin/bash
 
Line 479:
"Zero-based indices of \($four):",
($strand | indices($four) | join(" "))
'</langsyntaxhighlight>
{{out}}
<pre>
Line 496:
 
=={{header|Julia}}==
<langsyntaxhighlight lang=julia>DNArand(n, bases=['A', 'T', 'C', 'G']) = String(rand(bases, n))
 
DNAsearch(needle, haystack, lap=true) = findall(needle, haystack, overlap=lap)
Line 505:
println("Search sequence:\n$rand_string\nfor substring $subseq. Found at positions: ")
foreach(p -> print(rpad(p[2], 8), p[1] % 10 == 0 ? "\n" : ""), enumerate(DNAsearch(subseq, rand_string)))
</langsyntaxhighlight>{{out}}
<pre>
Search sequence:
Line 514:
 
=={{header|Nim}}==
<langsyntaxhighlight lang=Nim>import random, sequtils, strutils
 
proc dnaSequence(n: Positive): string =
Line 553:
else:
let tail = if pos.len == 1: ": " else: "s: "
echo "Subsequence found at position", tail, pos.join(", ")</langsyntaxhighlight>
 
{{out}}
Line 573:
 
=={{header|Perl}}==
<langsyntaxhighlight lang=perl>use strict;
use warnings;
use feature 'say';
Line 585:
say "Target: $target";
say 'Matches at these positions:';
say (($string =~ s/.{1,40}\K/\n/gr) =~ s/($target)/ >$1< /gr);</langsyntaxhighlight>
{{out}}
<pre>Target: CCTG
Line 599:
=={{header|Phix}}==
Currently only searches for non-overlapped sequences, but it should be pretty obvious how to change that, in which case the next underline will simply partially overwrite the previous, so you'll get eg "<=<==>".
<!--<langsyntaxhighlight lang=Phix>(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
Line 654:
<span style="color: #004080;">sequence</span> <span style="color: #000000;">idx</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">match_all</span><span style="color: #0000FF;">(</span><span style="color: #000000;">test</span><span style="color: #0000FF;">,</span><span style="color: #000000;">dna</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">show</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dna</span><span style="color: #0000FF;">,</span><span style="color: #000000;">test</span><span style="color: #0000FF;">,</span><span style="color: #000000;">idx</span><span style="color: #0000FF;">)</span>
<!--</langsyntaxhighlight>-->
{{out}}
with cheat enabled
Line 681:
{{libheader|regex}}
 
<langsyntaxhighlight lang=python>
from random import choice
import regex as re
Line 708:
 
dna_findall(sample_seq, dna_seq)
</syntaxhighlight>
</lang>
{{out}}
 
Line 732:
=={{header|Racket}}==
 
<langsyntaxhighlight lang=racket>#lang racket
 
(define (rand-seq n)
Line 753:
sub (report-sequence full) (subsequence-indices full sub)))
 
(module+ main (for ((i 4)) (Bioinformatics/Subsequence)))</langsyntaxhighlight>
 
{{out}}
Line 799:
=={{header|Raku}}==
Chances are actually pretty small that a random 4 codon string will show up at all in a random 200 codon sequence. Bump up the sequence size to get a reasonable chance of multiple matches.
<syntaxhighlight lang=raku perl6line>use String::Splice:ver<0.0.3>;
 
my $line = 80;
Line 820:
}
 
say $disp;</langsyntaxhighlight>
{{out}}
Show in custom div to better display highlighting.
Line 849:
:* &nbsp; DNA proteins to be searched in the data &nbsp; &nbsp; &nbsp; &nbsp; (the default is four unique random proteins).
:* &nbsp; the seed for the RANDOM function so runs can be repeated with the same data &nbsp; &nbsp; (no default).
<langsyntaxhighlight lang=rexx>/*REXX pgm gens random DNA (ACGT) sequence & finds positions of a random 4─protein seq. */
parse arg totLen rndLen basePr oWidth Bevery rndDNA seed .
if totLen=='' | totLen=="," then totLen= 200 /*Not specified? Then use the default.*/
Line 895:
if $\=='' then say right(idx, 7)"│" strip($, 'T') /*show residual protein data*/
say "───────┴"center('' , oWidth+10, '─')
say; return</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
Line 933:
 
=={{header|Ring}}==
<langsyntaxhighlight lang=ring>
/*-----------------------------------
# Project : DNA subsequences
Line 1,181:
 
//-----------------------------------------
</syntaxhighlight>
</lang>
 
'''Output:'''
Line 1,191:
{{libheader|Wren-str}}
{{libheader|Wren-fmt}}
<langsyntaxhighlight lang=ecmascript>import "random" for Random
import "/pattern" for Pattern
import "/str" for Str
Line 1,227:
findDnaSubsequence.call(200, 20)
System.print()
findDnaSubsequence.call(600, 40)</langsyntaxhighlight>
 
{{out}}
10,327

edits