Bioinformatics/Subsequence: Difference between revisions

Added 11l
(Added 11l)
Line 5:
Write a routine to find all the positions of a randomly generated subsequence   (four letters).
<br><br>
 
=={{header|11l}}==
{{trans|Python}}
 
<lang 11l>UInt32 seed = 34
F nonrandom_choice(lst)
:seed = (1664525 * :seed + 1013904223) [&] FFFF'FFFF
R lst[Int(:seed >> 16) % lst.len]
 
F generate_sequence(Int n)
R ((0 .< n).map(_ -> nonrandom_choice([‘A’, ‘C’, ‘G’, ‘T’]))).join(‘’)
 
F positions(dnaSeq, subSeq)
[Int] r
V start = 0
L
V? pos = dnaSeq.find(subSeq, start)
I pos == N
L.break
r.append(pos)
start = pos + 1
R r
 
F dna_findall(String needle, String haystack) -> N
V pp = positions(haystack, needle)
I pp.empty
print(‘No matches found’)
E
print(‘Found ’needle‘ at the following indices:’)
L(p) pp
print(String(p)‘:’String(p + needle.len))
 
V dna_seq = generate_sequence(200)
V sample_seq = generate_sequence(4)
 
V c = 1
L(i) dna_seq
I c % 20 != 0 {print(i, end' ‘’)} E print(i)
c++
print("\nSearch Sample: "sample_seq)
 
dna_findall(sample_seq, dna_seq)</lang>
 
{{out}}
<pre>
GAAGTGCTCAAACCCTTTTT
CCTTGCCGTAGGTTGTGCTG
CCGCCGCACACCCGCAACAG
CTTTTAGGCATAAGTATACG
GACCGCGGACGGGGCGTAAC
GGTGAACATTTTGCTAAATT
GGCTCTAGGGATGAGCCCTA
TAGCGCTGGGGACTACGCCC
CGGTAAAGATCGAGGCGACT
CACCGATTGCGCTAGGGACA
 
Search Sample: CGTA
Found CGTA at the following indices:
26:30
94:98
</pre>
 
=={{header|Ada}}==
1,481

edits