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

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 03:03 UTC ( #1030562=note: print w/ replies, xml ) Need Help??


in reply to Re^5: 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)?

Hi poj,

Thanks for your suggestions and for showing 11 changes in my script. The script now works but in the result part, many unwanted combinations are found along with the desired 6-letter combinations. The 6-letter combinations are correct and this is only what I need in the result. How can I get only the desired 6-letter combinations in the result?

Here goes the script again:

#!/usr/bin/perl #1 add use strict use strict; use warnings; #2 add '' use File::Glob('bsd_glob'); ############################################ ## Output to a TEXT File using file handle: ############################################ my $output="Joint.txt"; open (my $fh,">",$output) or die"Cannot open file '$output'.\n"; #3 declare variables my (@array,@DNA,@list); my ($filename,$combi,$entry,$number,$DNA); 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): "; $filename = <STDIN>; chomp $filename; unless ( open(FILE, $filename) ) { print "Cannot open file \"$filename\"\n\n"; exit; } @DNA= <FILE>; close FILE; #5 add chomp chomp(@DNA); #6 add join by comma $DNA = join(',',@DNA); push @array, $DNA; #7 not needed array1=array; } elsif ($entry==2) { # Curly brace for entry2 starts $number=@array; print"\n\n No. of Elements in Joined Array: $number\n"; print $fh "\n\n No. of Elements in Joined Array: $number\n"; + # To produce all possible combinations of different elements: #10 use simple $_ on @array $combi = join('',map {'{'.$_.'}'} @array); @list = bsd_glob($combi); print"\n Results:\n"; print $fh "\n Results:\n"; #11 print each element on new line print join "\n",@list; print $fh join "\n",@list; } # Curly brace for Entry 2 ends: } until ($entry==2); # Square bracket for do-until: close $output; exit;

Here goes the result of cmd and of output file Joint.txt:

No. of Elements in Joined Array: 3 Results: A1T1C1G1A1C1 # This is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C1G2 C1G2 C2G1A1C1 C2G1 C2G1 C2G1 C2G1 C2G1 C2G1 C2G1 A1C1 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


Comment on Re^6: How can one get all possible combinations of elements of different arrays using File::Glob(bsd_glob)?
Select or Download Code
Re^7: How can one get all possible combinations of elements of different arrays using File::Glob(bsd_glob)?
by poj (Priest) on Apr 25, 2013 at 07:55 UTC
    That looks like you have some blank lines in the data files probably at the end. If you print $DNA you should see commas with no values between them. Either edit the files or add a filter like this ;
    $DNA = join(',',grep(/[ACGT]\d[ACGT]\d/,@DNA)); print "$DNA\n";
    poj

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (7)
As of 2014-12-26 12:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (171 votes), past polls