I came back with another question. I have a list of data:
1 L DIELTQSPE H EVQLQESDAELVKPGASVKISCKASGYTFTDHE
2 L DIVLTQSPRVT H EVQLQQSGAELVKPGASIKDTY
3 A ALQLTQSPSSLSAS B RITLKESGPPLVKPTCS C ELDKWAN
4 A ALQLTQSPSSLSAS B RITLKESGPPLVKPTCS C ELDKWAG
5 A ALQLTQSPSSLSAS B RITLKESGPPLVKPTCS C LELDKWASL
6 L DIQMTQIPSSLSASLSIC H EVQLQQSGVEVKMSCKASGYTFTS
7 L SYELTQPPSVSVSPGSIT H QVQLVQSAKGSGYSFS P YNKRKAFYTTKNIIG
8 L SYELTQPPSVSVSPGRIT H EVQLVQSGAASGYSFS P NNTRKAFYATGDIIG
9 A MPIMGSSVAVLAIL B DIVMTQSPTVTI C EVQLQQSGRGP
10 A MPIMGSSVVLAIL B DIVMTQSPTVTI C EVQLQQSGRGP
11 L DVVMTQTPLQ H EVKLDESVTVTSSTWPSQSITCNVAHPASSTKVDKKIE
12 A DIVMTQSPDAQYYSTPYSFGQGTKLEIKR
And I would like to compare the 3rd element && the 5th elements of each row, then group them if they have the same 3rd and & 5th elements. For example, with the above data, the results are as follows:
3: 3 A ALQLTQSPSSLSAS B RITLKESGPPLVKPTCS C ELDKWAN
4 A ALQLTQSPSSLSAS B RITLKESGPPLVKPTCS C ELDKWAG
5 A ALQLTQSPSSLSAS B RITLKESGPPLVKPTCS C LELDKWASL
9: 9 A MPIMGSSVAVLAIL B DIVMTQSPTVTI C EVQLQQSGRGP
10 A MPIMGSSVVLAIL B DIVMTQSPTVTI C EVQLQQSGRGP
Fyi, in the actual data, the 3rd, 5th, 7th elements are very long. I made them cut themselves to see the whole.
This is what I did, I know that it is very clumsy, but as a beginner, I do my best. And the problem is that it shows only the first set of the "same" group. Could you show me where this went wrong and / or other beautiful methods to solve this, please?
my $file = <>;
open(IN, $file)|| die "no $file: $!\n";
my @arr;
while (my $line=<IN>){
push @arr, [split (/\s+/, $line)] ;
}
close IN;
my (@temp1, @temp2,%hash1);
for (my $i=0;$i<=$#arr ;$i++) {
push @temp1, [$arr[$i][2], $arr[$i][4]];
for (my $j=$i+1;$j<=$#arr ;$j++) {
push @temp2, [$arr[$j][2], $arr[$j][4]];
if (($temp1[$i][0] eq $temp2[$j][0])&& ($temp1[$i][1] eq $temp2[$j][1])) {
push @{$hash1{$arr[$i][0]}}, $arr[$i], $arr[$j];
}
}
}
print Dumper \%hash1;