Hi Perl Monks,
I am a beginner in perl programming. I am
interested in generating all possible combinations of 2-letter & 3-letter words
from a set of four letters (A,T,G,C), choosing one letter at a time for each position.
I searched for perl scripts in CPAN and other online sources but I didn't get the codes.
But a few scripts are indeed available for permutations and combinations. If the size of
the word is small, it's easy to do it manually but when the size of the word is 10 or
more it is time-consuming to generate all the combinations. If any perl code is available,
it will be very useful to the biologists. If 'n' is the size of the word, then 4**n (i.e. 4 to the power word size) combinations
are possible unlike possible permutations and combinations. For 2-letter words, there will be 16 combinations as given below (unlike 12
permutations and 6 combinations) and for 3-letter words 64 combinations are possible in the same
way (unlike fewer permutations and combinations). May I request perl monks to suggest me
some reference reading material or codes for this purpose?
#!/usr/bin/perl
use warnings;
use strict;
## Perl script to create all possible combinations of A,T,G & C
# of varying lengths:
print"\n This program will generate all possible combinations of A,T,G
+ & C:";
print"\n Enter the length of words you want (say 2 or 3 etc.): ";
my $num=<STDIN>;my $four=4;
chomp $num;
my $no_combi=$four**$num;
print"\n Total Number of Combinations= $no_combi\n";
my $combi_2l=". . .????";
my $combi_3l=". . .????";
print"\n All possible combinations of 2-letter words: ???$combi_2l\n";
print"\n All possible combinations of 3-letter words: ???$combi_3l\n";
exit;
The expected results will look like:
All possible combinations of 2-letter words (16):
AA
AT
AG
AC
TA
TT
TG
TC
GA
GT
GG
GC
CA
CT
CG
CC
For 3-letter words, there will be 64 combinations like:
All possible combinations of 3-letter words:
AAA
...
...
...
CCC