multidimensional array - How to group the repeated columns in the text file - perl (groups, subgroups) -
input description
it tab delimited file. first 5 columns id's , relations has in final print anyway. want group columns 6, if repeated. different groups exist hierarchy. column 3 criteria grouping. in example, 4 , 5 criterias. please check output.
input
ag1_4099 13 4 2 2 uv1040 uv0000 uv3770 uv3890 ag1_9001 20 4 2 1 uv1040 uv0000 uv3770 uv3890 ag1_9011 63 4 2 4 uv1040 uv0000 uv3770 uv3890 ag1_7013 11 4 1 1 uv1040 uv0000 uv3770 uv3890 ag1_9010 37 4 1 1 uv1040 uv0000 uv3770 uv3890 ag1_1011 33 4 2 7 uv1040 uv2080 uv3770 uv3890 ag1_1013 101 4 1 1 uv1040 uv2080 uv3770 uv3890 ag1_0001 7 4 2 1 uv1040 uv2100 uv3770 uv3890 ag1_1010 23 4 1 1 uv1040 uv8000 uv3770 uv3890 ag1_2099 13 4 2 2 uv1040 uv1000 uv3770 uv3890 ag1_3133 24 5 2 2 uv1040 uv300 uv2100 uv3770 uv3890 ag1_3433 343 5 7 3 uv1040 uv2118 uv2100 uv3890 uv3770 ag1_1100 254 5 1 4 uv2100 uv3770 uv3890 uv2105 mk7 ag1_8111 3 5 3 2 uv1040 uv3770 uv3890 uv2100 mk1 ag1_3430 84 5 2 2 uv1040 uv3770 uv3890 uv2100 mk1 ag1_7700 87 5 3 2 uv1040 uv3770 uv3890 uv2100 mk1 .... .... , on
desired output
(1) #### criteria 4 grouped ag1_4099 13 4 2 2 uv1040 uv0000 uv3770 uv3890 ag1_9001 20 4 2 1 uv1040 uv0000 uv3770 uv3890 ag1_9011 63 4 2 4 uv1040 uv0000 uv3770 uv3890 ag1_7013 11 4 1 1 uv1040 uv0000 uv3770 uv3890 ag1_9010 37 4 1 1 uv1040 uv0000 uv3770 uv3890 ag1_1011 33 4 2 7 uv1040 uv2080 uv3770 uv3890 ag1_1013 101 4 1 1 uv1040 uv2080 uv3770 uv3890 ag1_0001 7 4 2 1 uv1040 uv3770 uv3890 ag1_1010 23 4 1 1 uv1040 uv3770 uv3890 ag1_2099 13 4 2 2 uv1040 uv3770 uv3890 #### singles ag1_0001 7 4 2 1 uv2100 ag1_1010 23 4 1 1 uv8000 ag1_2099 13 4 2 2 uv1000 (2) #### criteria 5 grouped ag1_8111 3 5 3 2 uv1040 uv2100 uv3770 uv3890 mk1 ag1_3430 84 5 2 2 uv1040 uv2100 uv3770 uv3890 mk1 ag1_7700 87 5 3 2 uv1040 uv2100 uv3770 uv3890 mk1 ag1_3133 24 5 2 2 uv1040 uv2100 uv3770 uv3890 ag1_3433 343 5 7 3 uv1040 uv2100 uv3770 uv3890 ag1_1100 254 5 1 4 uv2100 uv3770 uv3890 #### singles ag1_1100 254 5 1 4 uv2105 mk7 ag1_3133 24 5 2 2 uv300 ag1_3433 343 5 7 3 uv2118
code
after matching in innermost loop, can't form group. please , correct.
use strict; use warnings; #my $in = $argv[0]; chomp $in; $in = "test.txt"; open(in,"$in") or die "unable open $in:$!\n"; @multiarr = (); while(my $line = <in>) { chomp $line; @linearr = split(/\t/, $line); push (@multiarr, \@linearr); } close in; ($quant,$linecnt) = ""; @gnmarr = (); $count = 0; $tmpquant = ""; @tmpmulti = (); $out = ""; loop: (my $i = 5; $i < 6; $i++) { (my $line = 0; $line < scalar @multiarr ; $line++) { $quant = $multiarr[$line][2]; $linecnt = scalar @{$multiarr[$line]}-1; if($i == $quant) { $count++; push (@tmpmulti, \@{$multiarr[$line]}); $tmpquant = $multiarr[$line][2]; } } $c = ""; (my $cls = 0; $cls < scalar @tmpmulti ; $cls++) { print "start"; (my $move = scalar @tmpmulti-1; $move > $cls; $move--) { #print "$move\t$cls\n"; (my $gnm = 5; $gnm < scalar @{$tmpmulti[$cls]}; $gnm++) { #print "$gnm\n"; (my $g = 5; $g < scalar @{$tmpmulti[$move]}; $g++) { if($tmpmulti[$cls][$gnm] eq $tmpmulti[$move][$g]){ #print "$cls\t$gnm\n$move\t$gnm\n"; print "$tmpmulti[$cls][$gnm]\n"; $c++; } } } #print "$move\t$cls\t$c\n"; } print "\n"; #print "$c\n"; } if($i ne $tmpquant) { next loop; } }
Comments
Post a Comment