Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^5: How can one get all possible combinations of elements of different arrays using File::Glob(bsd_glob)?

by hdb (Parson)
on Apr 24, 2013 at 21:15 UTC ( #1030533=note: print w/ replies, xml ) Need Help??


in reply to Re^4: How can one get all possible combinations of elements of different arrays using File::Glob(bsd_glob)?
in thread How can one get all possible combinations of elements of different arrays using File::Glob(bsd_glob)?

The key is in the glob function. If you feed it a string like "{1,2}{a,b,c}" it creates all combinations of elements within the braces. Here is a complete solution for your problem. I hope you can adapt it to your needs. There is nothing really new in there.

use strict; use warnings; use File::Glob qw{bsd_glob}; my $string; my $entry; do { print"\n\n Press 1 to Enter New File or 2 to Combine: "; $entry=<STDIN>; chomp $entry; if ($entry==1) { print"\n\n Enter New File Name (.txt): "; my $filename = <STDIN>; chomp $filename; open my $fh, "<", $filename or die "Cannot open $filename.\n"; my $DNA; { local $/=undef; $DNA = <$fh>; } close $fh; chomp $DNA; $DNA=~s/\n/,/g; $string .= "{$DNA}"; } # Curly brace for entry1 ends: } until ($entry==2); for (bsd_glob $string) { print "~$_~\n"; }

So for every file you input, it creates this substring "{...,...,...}" with all elements from the file and adds it to the previous substrings of the same kind. When you are done, the overall string is fed into glob to create all combinations. I hope this makes it clear.


Comment on Re^5: How can one get all possible combinations of elements of different arrays using File::Glob(bsd_glob)?
Download Code
Re^6: How can one get all possible combinations of elements of different arrays using File::Glob(bsd_glob)?
by supriyoch_2008 (Scribe) on Apr 25, 2013 at 07:17 UTC

    Hi hdb,

    Thank you for the code. It works but the problem is that it produces all the combinations alongwith the desired 6-letter combinations i.e.

    ~A1T1C1G1A1C1~ ~A1T1C1G2A1C1~ ~A1T1C2G1A1C1~ ~A2T3C1G1A1C1~ ~A2T3C1G2A1C1~ ~A2T3C2G1A1C1~

    Here is the text output of your code:

    ~A1T1C1G1A1C1~ ~A1T1C1G1~ ~A1T1C1G1~ ~A1T1C1G1~ ~A1T1C1G1~ ~A1T1C1G1~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~~ ~A1C1~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~A1C1~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~A1C1~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~A1C1~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~A1C1~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~C1G1A1C1~ ~C1G1~ ~C1G1~ ~C1G1~ ~C1G1~ ~C1G1~ ~C1G1~ ~C1G1~ ~C1G2A1C1~ ~C1G2~ ~C1G2~ ~C1G2~ ~C1G2~ ~C1G2~ ~C1G2~ ~C1G2~ ~C2G1A1C1~ ~C2G1~ ~C2G1~ ~C2G1~ ~C2G1~ ~C2G1~ ~C2G1~ ~C2G1~ ~A1C1~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~A1C1~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~A1C1~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~A1C1~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~A1C1~ ~~ ~~ ~~ ~~ ~~ ~~ ~~ ~A1C1~ ~~ ~~ ~~ ~~ ~~ ~~ ~~

    Here the input files i.e. k1.txt, k2.txt, k3.txt are small. When the input files are large, then I shall face problem in selecting the desired longest combinations from a very large cmd or text file output. It will be much easier if the output text file shows only the longest combinations as given above. I think it is not very easy task in perl. I think so because poj has also suggested a script which produces many unwanted combinations along with the desired 6-letter longest combinations. From the output text file, the unwanted combinations are to be deleted manually to retain only the longest correct, desired combinations. It will be a very time-taking task for more input files with large size. I wish perl could solve this problem.

      Not what I get. I only get the six desired lines. Probabaly your k?.txt files have a lot of empty lines??? In which case, you need to modify the code by adding two more lines:

      chomp $DNA; $DNA=~s/\n/,/g; $DNA=~s/,+$//g; # new $DNA=~s/,,+/,/g; # new $string .= "{$DNA}";

      This removes multiple commata or trailing commata created by empty lines. Let me know whether this solves the problem.

        Hi hdb,

        Thanks a lot. I have put the two new lines given by you in the script. Now the script has worked nicely and I have got the results the way I wanted. My heartfelt thanks to you. I wish I could develop the skills like you in perl. It appears to me that possibly no problem in perl is insurmountable to you. My heart knew no bounds when I had found the correct results using the code given by you.

        With deep REGARDS to you for your kind help and guidance.

        I SALUTE your intellectual achievement. This is the message from my heart to you. My English is not very good and so I don't know which words or sentences I should use here appropriately to thank you.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (8)
As of 2014-07-12 07:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (238 votes), past polls