for (my $j = 0; $j<=scalar(@sam2com);$j++){ my $s1 = $sam2com[ $j ] ; my $geno1 = $source_set->{$s1}; my $top_percent = 0; my $top = ''; for (my $k = 0;$k<=scalar(@sam2com);$k++){ my $match = 0; my $s2 = $sam2com[ $k ]; my $geno2 = $source_set->{$s2}; my $set = Array::Each->new(\@$geno1, \@$geno2); while (my($g1, $g2, $index2) = $set->each() ){ #print "$s1|$s2|$g1|$g2|$index2\n"; next if $g1 eq "" || $g2 eq ""; next if $g1 =~ /^NN/i || $g2 =~ /^NN/i; if($g1 eq $g2){ $match++; #print "$s1|$s2|$g1|$g2|$match|$index2\n"; }#end of if $g1 eq $g2 }#end of while loop $set->each my $percentage = sprintf "%.2f", ($match * 100)/( scalar @$geno1 ) ; print SUM $percentage, ","; next if ($percentage < 75); #print "$s1|$s2|$percentage\n"; if( ( $percentage >=$top_percent) and ($top ne $s1 ) ){ $top_percent= $percentage; $top = $s2; } #end of if $percentage >=$top_percent) and $top ne $s1 push @{ $com_sam->{ $s1 }->{ $percentage } }, { sample =>$s2, percent =>$percentage, match =>$match }; my $ge1 = join "", @$geno1; my $ge2 = join "", @$geno2; if( ( $ge1 eq $ge2 ) and ( $s1 ne $s2 ) ) { print LOG "$s1|$s2|$ge1 | $ge2\n"; } }#end of for $k sam2com print SUM "\n"; #sort by percentage in desending order. Get the samples match to other sample percentage of match and top hit . foreach my $percent ( sort { $b <=> $a } keys %{ $com_sam->{ $s1 } } ){ my $match_samples = $com_sam->{ $s1 }->{ $percent }; foreach my $matSam( @ { $match_samples } ){ if( ( $s1 ne $matSam->{ sample } ) and ($matSam->{ percent } >= $top_percent) ) {#check the sample1 matches with a different sample with a higher percntage. print LOG "Sample $s1 matches with $matSam->{ sample } with $matSam->{ percent }\n"; } #else{ my $l = sprintf "%s, %s, %0.2f, %s, %0.2f ", $s1, $matSam->{ sample }, $matSam->{ percent }, $top, $top_percent; print OUT $l,"\n"; #} }#end of forach $match->sample }#end of percentage foreach loop }#end of for $j @sam2com.