Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Hexamer combination from 3mers.

by oxydeepu (Novice)
on Oct 10, 2012 at 15:38 UTC ( #998240=perlquestion: print w/ replies, xml ) Need Help??
oxydeepu has asked for the wisdom of the Perl Monks concerning the following question:

Hi all monks,
I need a help with a script. I have a list of 3mers like

ABC
EFG
KLM
XYZ

So what I want is make all possible hexamers from the above list

e.g.,
ABCABC
ABCEFG
ABCKLM
ABCXYZ
EFGABC
EFGEFG
EFGKLM
EFGXYZ
......
......
XYZABC
XYZEFG
XYZKLM
XYZXYZ

I think I have explained my problem. So can anyone help with this.
Thank you in advance.
Best,
Deepak

Comment on Hexamer combination from 3mers.
Re: Hexamer combination from 3mers.
by marto (Chancellor) on Oct 10, 2012 at 15:44 UTC

    Which part are you having problems with? How would you solve the problem using a pen and paper? I suspect you've been given this as a learning exercise, asking others to solve the problem word defeat the purpose of such an exercise

      Hi,
      Thank you for your time.
      Actually this not an excercise. I just wanted to explain the problem as simple as possible thats why. The list Bigger than this. I just wanted the logic.

      Best,
      Deepak

Re: Hexamer combination from 3mers.
by choroba (Abbot) on Oct 10, 2012 at 15:47 UTC
    #!/usr/bin/perl use strict; use warnings; use feature 'say'; my @trimers = <>; chomp @trimers; say for glob +('{' . join(',', @trimers) . '}' ) x 2;
    Update: Using glob is safe only if the data do not contain any special characters like ? * [] {} , or whitespace.
    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      Hi,
      Thanks alot. That works.
      Best,
      Deepak

Re: Hexamer combination from 3mers.
by daxim (Chaplain) on Oct 10, 2012 at 15:53 UTC
    use 5.010; use Algorithm::Combinatorics qw(variations_with_repetition); say join q(), @{ $_ } for variations_with_repetition [qw(ABC EFG KLM XYZ)], 2; __END__ ABCABC ABCEFG ABCKLM ABCXYZ EFGABC EFGEFG EFGKLM EFGXYZ KLMABC KLMEFG KLMKLM KLMXYZ XYZABC XYZEFG XYZKLM XYZXYZ
Re: Hexamer combination from 3mers.
by 2teez (Priest) on Oct 10, 2012 at 16:34 UTC

    Or you could simply use a foreach loop like so:

    use warnings; use strict; my @three_mers = qw( ABC EFG KLM XYZ); foreach my $mers_first (@three_mers) { foreach my $mers_sec (@three_mers) { print $mers_first, $mers_sec, $/; } }
    OUTPUT
    ABCABC ABCEFG ABCKLM ABCXYZ EFGABC EFGEFG EFGKLM EFGXYZ KLMABC KLMEFG KLMKLM KLMXYZ XYZABC XYZEFG XYZKLM XYZXYZ

    If you tell me, I'll forget.
    If you show me, I'll remember.
    if you involve me, I'll understand.
    --- Author unknown to me

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://998240]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2014-07-23 09:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (138 votes), past polls