in reply to Re^2: How can one get all possible combinations of a string without changing positions & using window size?
in thread How can one get all possible combinations of a string without changing positions & using window size?

I am not certain about your objectives, but maybe something like the following would do what you want. It doesn't use a window but it does add numbers, as I understand your description.

use strict; use warnings; my $string = "ATATGCGCAT"; my %levels = ( A => 3, T => 2, G => 2, C => 1, ); my @letters = split(//,$string); my $max = $#letters; my @numbers = map { 1 } @letters; while(1) { # Print the current combination of letters and numbers print "~"; for my $n (0..$max) { print $letters[$n] . $numbers[$n]; } print "~\n"; # Calculate the next set of numbers my $n = 0; $numbers[$n]++; while($numbers[$n] > $levels{$letters[$n]}) { $numbers[$n] = 1; $n++; last if($n > $max); $numbers[$n]++; } last if($n > $max); }
  • Comment on Re^3: How can one get all possible combinations of a string without changing positions & using window size?
  • Download Code

Replies are listed 'Best First'.
Re^4: How can one get all possible combinations of a string without changing positions & using window size?
by supriyoch_2008 (Monk) on Apr 23, 2013 at 16:03 UTC

    Hi ig,

    Thank you very much for the code. You have written it very nicely. Moreover, it is intelligible to me. I am grateful to you for your endeavour. I hope this code will solve some basic problems in comutational genomics.

    With regards,