Bioinformatics/Subsequence: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
Thundergnat (talk | contribs) m (Automated syntax highlighting fixup (second round - minor fixes)) |
||
Line 5: | Line 5: | ||
Write a routine to find all the positions of a randomly generated subsequence (four letters). |
Write a routine to find all the positions of a randomly generated subsequence (four letters). |
||
<br><br> |
<br><br> |
||
=={{header|11l}}== |
=={{header|11l}}== |
||
{{trans|Python}} |
{{trans|Python}} |
||
<syntaxhighlight lang=11l>UInt32 seed = 34 |
<syntaxhighlight lang="11l">UInt32 seed = 34 |
||
F nonrandom_choice(lst) |
F nonrandom_choice(lst) |
||
:seed = (1664525 * :seed + 1013904223) [&] FFFF'FFFF |
:seed = (1664525 * :seed + 1013904223) [&] FFFF'FFFF |
||
Line 66: | Line 65: | ||
94:98 |
94:98 |
||
</pre> |
</pre> |
||
=={{header|Action!}}== |
=={{header|Action!}}== |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="action!">DEFINE SEQLEN="200" |
||
DEFINE SUBLEN="4" |
DEFINE SUBLEN="4" |
||
Line 159: | Line 157: | ||
83-86 |
83-86 |
||
</pre> |
</pre> |
||
=={{header|Ada}}== |
=={{header|Ada}}== |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="ada">with Ada.Text_Io; |
||
with Ada.Strings.Fixed; |
with Ada.Strings.Fixed; |
||
with Ada.Numerics.Discrete_Random; |
with Ada.Numerics.Discrete_Random; |
||
Line 243: | Line 240: | ||
Found at position: 371..374 |
Found at position: 371..374 |
||
Found at position: 380..383</pre> |
Found at position: 380..383</pre> |
||
=={{header|Arturo}}== |
=={{header|Arturo}}== |
||
<syntaxhighlight lang=rebol>bases: [`A` `G` `C` `T`] |
<syntaxhighlight lang="rebol">bases: [`A` `G` `C` `T`] |
||
randSeq: join map 1..200 => [sample bases] |
randSeq: join map 1..200 => [sample bases] |
||
randSub: join map 1..4 => [sample bases] |
randSub: join map 1..4 => [sample bases] |
||
Line 285: | Line 281: | ||
Found subsequence at position: 71 |
Found subsequence at position: 71 |
||
Found subsequence at position: 169</pre> |
Found subsequence at position: 169</pre> |
||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
{{works with|Factor|0.99 2021-02-05}} |
{{works with|Factor|0.99 2021-02-05}} |
||
<syntaxhighlight lang=factor>USING: accessors formatting grouping io kernel math |
<syntaxhighlight lang="factor">USING: accessors formatting grouping io kernel math |
||
math.functions.integer-logs math.parser random regexp sequences ; |
math.functions.integer-logs math.parser random regexp sequences ; |
||
Line 352: | Line 347: | ||
312..316 |
312..316 |
||
</pre> |
</pre> |
||
=={{header|Go}}== |
=={{header|Go}}== |
||
{{trans|Wren}} |
{{trans|Wren}} |
||
<syntaxhighlight lang=go>package main |
<syntaxhighlight lang="go">package main |
||
import ( |
import ( |
||
Line 444: | Line 438: | ||
388..391 |
388..391 |
||
</pre> |
</pre> |
||
=={{header|jq}}== |
=={{header|jq}}== |
||
{{works with|jq}} |
{{works with|jq}} |
||
Line 457: | Line 450: | ||
`jot -r N MIN MAX` but a fourth argument can also be |
`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: |
used to specify a seed. An alternative would be to use `gshuf` along the lines of: |
||
<syntaxhighlight lang=sh> |
<syntaxhighlight lang="sh"> |
||
# For 200 pseudo-random integers in the range 0 to 3 inclusive: |
# For 200 pseudo-random integers in the range 0 to 3 inclusive: |
||
gshuf -i 0-3 -r -n 200 --random-source=/dev/random |
gshuf -i 0-3 -r -n 200 --random-source=/dev/random |
||
Line 463: | Line 456: | ||
Note that the indices shown below are offsets (i.e., the index origin is taken to be 0). |
Note that the indices shown below are offsets (i.e., the index origin is taken to be 0). |
||
<syntaxhighlight lang=sh> |
<syntaxhighlight lang="sh"> |
||
#!/bin/bash |
#!/bin/bash |
||
Line 494: | Line 487: | ||
55 141 169 |
55 141 169 |
||
</pre> |
</pre> |
||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
<syntaxhighlight lang=julia>DNArand(n, bases=['A', 'T', 'C', 'G']) = String(rand(bases, n)) |
<syntaxhighlight lang="julia">DNArand(n, bases=['A', 'T', 'C', 'G']) = String(rand(bases, n)) |
||
DNAsearch(needle, haystack, lap=true) = findall(needle, haystack, overlap=lap) |
DNAsearch(needle, haystack, lap=true) = findall(needle, haystack, overlap=lap) |
||
Line 512: | Line 504: | ||
21:24 74:77 99:102 |
21:24 74:77 99:102 |
||
</pre> |
</pre> |
||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
<syntaxhighlight lang= |
<syntaxhighlight lang="nim">import random, sequtils, strutils |
||
proc dnaSequence(n: Positive): string = |
proc dnaSequence(n: Positive): string = |
||
Line 571: | Line 562: | ||
Subsequence found at positions: 61, 122, 170</pre> |
Subsequence found at positions: 61, 122, 170</pre> |
||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
<syntaxhighlight lang=perl>use strict; |
<syntaxhighlight lang="perl">use strict; |
||
use warnings; |
use warnings; |
||
use feature 'say'; |
use feature 'say'; |
||
Line 596: | Line 586: | ||
TGCGAG >CCTG< TAGAGCCGGGCCTCAAATTAAACGAAAAAT |
TGCGAG >CCTG< TAGAGCCGGGCCTCAAATTAAACGAAAAAT |
||
ATAAGTTTGCTTGGCACGCTGTACTACTTATCC >CCTG< ACT</pre> |
ATAAGTTTGCTTGGCACGCTGTACTACTTATCC >CCTG< ACT</pre> |
||
=={{header|Phix}}== |
=={{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 "<=<==>". |
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 "<=<==>". |
||
<!--<syntaxhighlight lang= |
<!--<syntaxhighlight lang="phix">(phixonline)--> |
||
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span> |
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span> |
||
Line 675: | Line 664: | ||
GCTA does not occur |
GCTA does not occur |
||
</pre> |
</pre> |
||
=={{header|Python}}== |
=={{header|Python}}== |
||
Line 681: | Line 669: | ||
{{libheader|regex}} |
{{libheader|regex}} |
||
<syntaxhighlight lang=python> |
<syntaxhighlight lang="python"> |
||
from random import choice |
from random import choice |
||
import regex as re |
import regex as re |
||
Line 729: | Line 717: | ||
167:171 |
167:171 |
||
</pre> |
</pre> |
||
=={{header|Racket}}== |
=={{header|Racket}}== |
||
<syntaxhighlight lang=racket>#lang racket |
<syntaxhighlight lang="racket">#lang racket |
||
(define (rand-seq n) |
(define (rand-seq n) |
||
Line 796: | Line 783: | ||
350 : GGCCTCGACCCAATTTAACCTCCCACTCCGTGGGTACAGCTTGAACCCCC |
350 : GGCCTCGACCCAATTTAACCTCCCACTCCGTGGGTACAGCTTGAACCCCC |
||
((245 . 248) (250 . 253) (329 . 332) (386 . 389))</pre> |
((245 . 248) (250 . 253) (329 . 332) (386 . 389))</pre> |
||
=={{header|Raku}}== |
=={{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. |
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 line>use String::Splice:ver<0.0.3>; |
<syntaxhighlight lang="raku" line>use String::Splice:ver<0.0.3>; |
||
my $line = 80; |
my $line = 80; |
||
Line 839: | Line 825: | ||
AGTACTCGACTGTTATGGTAAAAGGGCATCGTGATCGTTTATATTAATCATTGGGACAGGTGGTTAATGTCA<span style="color: #CC0000;">TAGC</span>TTAG<br> |
AGTACTCGACTGTTATGGTAAAAGGGCATCGTGATCGTTTATATTAATCATTGGGACAGGTGGTTAATGTCA<span style="color: #CC0000;">TAGC</span>TTAG<br> |
||
</div> |
</div> |
||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
This REXX version allows the user to specify: |
This REXX version allows the user to specify: |
||
Line 849: | Line 834: | ||
:* DNA proteins to be searched in the data (the default is four unique random proteins). |
:* DNA proteins to be searched in the data (the default is four unique random proteins). |
||
:* the seed for the RANDOM function so runs can be repeated with the same data (no default). |
:* the seed for the RANDOM function so runs can be repeated with the same data (no default). |
||
<syntaxhighlight lang=rexx>/*REXX pgm gens random DNA (ACGT) sequence & finds positions of a random 4─protein seq. */ |
<syntaxhighlight 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 . |
parse arg totLen rndLen basePr oWidth Bevery rndDNA seed . |
||
if totLen=='' | totLen=="," then totLen= 200 /*Not specified? Then use the default.*/ |
if totLen=='' | totLen=="," then totLen= 200 /*Not specified? Then use the default.*/ |
||
Line 931: | Line 916: | ||
the random DNA proteins were found in positions: 5 6 16 69 157 158 159 340 796 797 962 963 |
the random DNA proteins were found in positions: 5 6 16 69 157 158 159 340 796 797 962 963 |
||
</pre> |
</pre> |
||
=={{header|Ring}}== |
=={{header|Ring}}== |
||
<syntaxhighlight lang=ring> |
<syntaxhighlight lang="ring"> |
||
/*----------------------------------- |
/*----------------------------------- |
||
# Project : DNA subsequences |
# Project : DNA subsequences |
||
Line 1,186: | Line 1,170: | ||
[https://i.imgur.com/5hhbRBK.mp4 Bioinformatics/Subsequence - video] |
[https://i.imgur.com/5hhbRBK.mp4 Bioinformatics/Subsequence - video] |
||
=={{header|Wren}}== |
=={{header|Wren}}== |
||
{{libheader|Wren-pattern}} |
{{libheader|Wren-pattern}} |
||
{{libheader|Wren-str}} |
{{libheader|Wren-str}} |
||
{{libheader|Wren-fmt}} |
{{libheader|Wren-fmt}} |
||
<syntaxhighlight lang=ecmascript>import "random" for Random |
<syntaxhighlight lang="ecmascript">import "random" for Random |
||
import "/pattern" for Pattern |
import "/pattern" for Pattern |
||
import "/str" for Str |
import "/str" for Str |