I have a string e.g.
and I want to replace random positions of that string with corresponding position from a random sequence in another set of other strings e.g.
ABCDEFGHIJ KLMNOPQRST UVWXYZABCD ...
If I chose to make 3 replacements, the script should chose 3 random numbers e.g. 3,7,8; and 3 random sequences e.g. 1, 1, 3; make the replacements to generate the expected output:
Is there a way to do this without significant looping? I wrote a simple bash script to generate a random position and a random sequence line then do 1 replacement, then repeat the process on the output, repeat, repeat. This works perfectly, however in my real-life files (much larger than the examples), I want to generate 10,000 or more replacements. Oh, and I will need to do this multiple times to generate multiple 'mutated' variant sequences.
EDIT: At the moment I am using something like this:
#chose random number between 1 and the number of characters in the string randomposition=$(jot -r 1 1 $seqpositions) #chose a random number between 1 and the number of lines in the set of potential replacement strings randomline=$(jot -r 1 1 $alignlines) #find the character at randomline:randomposition newAA=$(sed -n "$randomline,$randomline p" $alignmentfile | cut -c$randomposition) #replace the character at 'string:randomposition' with the character at 'randomline:randomposition' sed "s/./$newAA/$randomposition" $sequencefile
(with some additional bits, obviously) and just looping through this thousands of times