Anonymous user
Bioinformatics/Subsequence: Difference between revisions
m
→{{header|REXX}}: moved some code to subroutines.
m (→{{header|REXX}}: added commas to the numbers in the output, enhanced title with the length that was used for data field width.) |
m (→{{header|REXX}}: moved some code to subroutines.) |
||
Line 65:
if rndDNA=='' | rndDNA=="," then rndDNA= copies(., rndLen) /*what we're looking for*/
if datatype(seed, 'W') then call random ,,seed /*used to generate repeatable random #s*/
call genRnd /*gen data field of random proteins.
say " index │"center(' DNA sequence of ' commas(totLen) " proteins", oWidth + 10)▼
say "───────┼"center('' , oWidth + 10, '─')▼
idx= 1 /*assign the index number of 1st line. */▼
$=; $$= /*gen data field of random proteins. */▼
do j=1 for totLen; c= substr( basePr, random(1, lenB), 1)▼
$$= $$ || c /*append a random protein.*/▼
if Bevery\==0 then if j//Bevery==0 then $= $' ' /*maybe add a blank. */▼
if length( space($ || c, 0) )<oWidth then do; $= $ || c; iterate /*width OK*/▼
▲ end
say strip( right(idx, 7)'│' $, 'T'); $= /*display line──► terminal*/▼
end /*j*/▼
if $\=='' then say right(idx, 7)"│" strip($, 'T') /*display residual protein data.*/▼
say ' base DNA proteins used: ' basePr
say 'random DNA proteins used: ' dna?
call findRnd
@=; p=0 /*@: list of all found random proteins*/▼
do until p==0; p= pos(dna?, $$, p+1) /*find all overlapped positions in data*/▼
if p>0 then @= @ commas(p) /*Found one? Append it to the "Found"s*/▼
end /*p*/▼
if @=='' then do; say "the random DNA proteins weren't found."; exit 4; end
say 'the random DNA proteins were found in positions:' strip(@)
Line 92 ⟶ 75:
/*──────────────────────────────────────────────────────────────────────────────────────*/
commas: parse arg ?; do jc=length(?)-3 to 1 by -3; ?=insert(',', ?, jc); end; return ?
/*──────────────────────────────────────────────────────────────────────────────────────*/
▲ do until p==0; p= pos(dna?, $$, p+1);
▲ end /*p*/; return
/*──────────────────────────────────────────────────────────────────────────────────────*/
genRnd: dna?=; use= basePr; upper use basePr rndDNA; lenB= length(basePr)
Line 100 ⟶ 88:
dna?= dna? || x /*build a random protein seq.*/
end /*k*/
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
▲ do j=1 for totLen; c= substr( basePr, random(1, lenB), 1)
▲ end /*j*/
say; return</lang>
{{out|output|text= when using the default inputs:}}
<pre>
|