Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^3: How can one get all possible combinations of a string without changing positions & using window size?

by ig (Vicar)
on Apr 21, 2013 at 06:34 UTC ( [id://1029719]=note: print w/replies, xml ) Need Help??


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,

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1029719]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-04-24 02:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found