Hi people!
I have a fasta file with multiple sequence alignments. I´m trying to run my code with 2 alignments at a time and compare each with each. So alignment 1 with 2 runs the code then 1 with 3 and so on (after each comparison the results should be saved in the same hash). The problem is that my code compare for example alignment 1 and 2 .. and then later on again 2 with 1 so I get redundant information.
Any suggestions would be very appreciated!
thanks!
Here's my code:
$datei = '/Users/Maxi/Desktop/LernenPerl/alignmentlargo.txt';
open(my $fastd,'<', $datei) or die "die datei $datei wurde nicht geöffnet: $!\n";
my $sequences = ();
my $header = '';
my $reverse='';
my $dnaheaders= 0;
my $length=0;
while (my $line = <$fastd>) {
chomp $line;
if ($line =~ /^>/) {
$header = $line;
$header =~ s/>//g;
}
else {
$sequences->{$header} .= $line
}
}
my $seq1;
my $seq2;
foreach my $key (sort keys %$sequences) { ##interacting with all alignments in the file
for my $key2 (sort grep { $_ ne $key } keys %$sequences) {
$seq1 =$sequences->{$key};
$seq2 =$sequences->{$key2};
my $matrix={};
my @aminos= qw(A C D E F G H I K L M N P Q R S T V W Y);
foreach my $substr1 (@aminos){
foreach my $substr2 (@aminos){
$matrix->{$substr1}->{$substr2}=0;
}
}
my $eq={};
my $else={};
LINE: for (my $i=0; $i< length $seq1; $i++){
my ($substr1,$substr2) = (substr($seq1,$i,1),substr($seq2, $i,1));
next LINE if ("$substr1$substr2" =~ /-/);
if("$substr1$substr2"=~ /[^@aminos]/){
$else->{$substr1}->{$substr2}+=1;
$else->{$substr2}->{$substr1}+=1;
next LINE;
}
if ($substr1 eq $substr2){
$matrix->{$substr1}->{$substr2}++;
$eq->{$substr1}++;
}elsif ($substr1 ne $substr2){
$matrix->{$substr1}->{$substr2} += 1/2;
$matrix->{$substr2}->{$substr1} += 1/2;
}
}
Thank you! that solved my problem! :)