Bioinformatics/Subsequence: Difference between revisions

Line 289:
216..219
388..391
</pre>
 
=={{header|jq}}==
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
 
Neither jq nor gojq currently has any PRNG built-ins so one
possibility is to use a jq-coded PRNG function such
as can be found at https://rosettacode.org/wiki/Random_numbers#jq
 
In practice, it's usually more convenient to use a utility such
gshuf or jot to provide the source of randomness. Here we use
`jot -r N MIN MAX` but a fourth argument can also be
used to specify a seed.
 
Note that the indices shown are offsets (i.e., the index origin is taken to be 0).
<lang sh>
#!/bin/bash
 
jot -r 200 0 3 | jq -nr --slurpfile four <(jot -r 4 0 3) '
 
# input: an array of integers
def toDNA:
def base: . as $in | "ACGT" | .[$in : $in+1];
map(base) | join("");
 
([inputs] | toDNA) as $strand
| ($four | toDNA) as $four
| "Indices of \($four) in the strand of length \($strand|length):",
($strand | indices($four) | join(" "))
'</lang>
{{out}}
<pre>
./bioinformatics-subsequence.sh
Indices of ATTA in the strand of length 200:
6
 
./bioinformatics-subsequence.sh
Indices of GACT in the strand of length 200:
29 135
</pre>
 
2,442

edits