Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hi! I am trying to compare columns in all possible combination, I have two files one with all possible combination and other with data
file2
1 2 3 4 1 2 3 5 1 2 4 5 1 3 4 5 2 3 4 5
file1
A B C D E 0 0 0 + 0 + 0 + + + 0 + + + + 0 0 + + 0 + + + + + 0 + + + + + 0 + + 0
so far I have tried this, but it seems only first line of file2 is getting parsed to while loop
open (BC,"file2.txt")||die("cannot open"); open (AB,"file1.txt")||die("cannot open"); @file=<BC>; chomp(@file); foreach $fl(@file) { if($fl=~/(.*?)\s+(.*?)\s+(.*?)\s+(.*)/) { $w=$1-1; $x=$2-1; $y=$3-1; $z=$4-1; } while(<AB>) { @data=split("\t",$_); chomp(@data); push(@col1,$data[$w]); push(@col2,$data[$x]); push(@col3,$data[$y]); push(@col4,$data[$z]); } } for($i=1;$i<@col1;$i++) { if(($col1[$i] eq '+') && ($col2[$i] eq '+') && ($col3[$i] eq +'+')) { $j++; } if(($col1[$i] eq '+') && ($col2[$i] eq '+') && ($col4[$i] e +q '+')) { $k++; } if(($col3[$i] eq '+') && ($col2[$i] eq '+') && ($col4[$i] eq ' ++')) { $l++; } if(($col3[$i] eq '+') && ($col2[$i] eq '+') && ($col4[$i] eq + '+')&&($col1[$i] eq '+') ) { $m++; } print $col1[0],"\t",$col2[0],"\t",$col3[0],"\t\t",$j,"\n"; print $col1[0],"\t",$col2[0],"\t",$col4[0],"\t\t",$k,"\n"; print $col4[0],"\t",$col2[0],"\t",$col3[0],"\t\t",$l,"\n"; print $col1[0],"\t",$col2[0],"\t",$col3[0],"\t",$col4[0],"\t",$m," +\n"; }
desired output
thank youA B C 1 A B D 1 D B C 3 A B C D 1 A B C 1 A B E 1 E B C 3 A B C E 1 A B D 1 A B E 1 E B D 3 A B D E 1 A C D 3 A C E 2 E C D 4 A C D E 2 B C D 3 B C E 3 E C D 4 B C D E 3
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: compare columns in all possible combination
by roboticus (Chancellor) on Sep 20, 2014 at 13:29 UTC | |
|
Re: compare columns in all possible combination
by LanX (Saint) on Sep 20, 2014 at 13:35 UTC | |
|
Re: compare columns in all possible combination
by Lennotoecom (Pilgrim) on Sep 20, 2014 at 19:08 UTC | |
by greeknlatin (Initiate) on Sep 21, 2014 at 10:01 UTC | |
by Lennotoecom (Pilgrim) on Sep 21, 2014 at 15:09 UTC | |
by greeknlatin (Initiate) on Sep 21, 2014 at 15:19 UTC | |
by Lennotoecom (Pilgrim) on Sep 21, 2014 at 16:33 UTC | |
|
Re: compare columns in all possible combination
by Cristoforo (Curate) on Sep 22, 2014 at 04:02 UTC | |
by Anonymous Monk on Sep 22, 2014 at 06:54 UTC |