Here is some sample code to get you started
my @aminos = qw( A R N D C E Q G H I L K M F P S T W Y V );
# now A-R is the same as R-A in terms of interactions but if we
# only use one we need a sort so use both, duplicate data but lose sor
+t....
my @a_a;
for my $a1(@aminos) {
for my $a2(@aminos) {
push @a_a, ["${a1}_${a2}", (join '', sort $a1,$a2)];
}
}
# now prepare our lookup table for interactions
print "my \%interactions = (\n";
for my $a_ref( sort{ $a->[1] cmp $b->[1] }@a_a ) {
print "\t",$a_ref->[0], " => 0,\n";
}
print ");\n";
# this will give you a hash like this (except bigger)
# fill in the interaction values (note A-C and C-A are adjacent
# for convenience of filling these in. this is a do once
my %interactions = (
A_A => 0,
A_C => 1,
C_A => 1,
A_D => 2,
D_A => 2,
E_A => 0,
A_E => 0,
);
# next read in the sequences.
my @chains;
for my $file(@files) {
open F, $file;
my @residues = <F>;
chomp @residues;
push @chains, \@residues;
}
# fake it
@chains = ( [ qw( A C D ) ],[ qw( A C D ) ],[ qw( A C D ) ],
[ qw( A C D ) ],[ qw( D D D ) ],[ qw( E E E ) ],);
# we now have an array of arrays. top level is chain, next level resid
+ue
my $interact;
for my $ca_i( 0.. $#chains-1 ) {
for my $cb_i( $ca_i+1 .. $#chains ) {
print "Comparing chain $ca_i to $cb_i\n";
for my $res_a( @{$chains[$ca_i]} ) {
for my $res_b( @{$chains[$cb_i]} ) {
$interact = $res_a . '_' .$res_b;
print "\t$interact => $interactions{$interact}\n";
}
}
}
}
Using simulated data this algorithm does 3.75 million interaction mappings in under a minute. Including writing it all to a file.
my @aminos = qw( A R N D C E Q G H I L K M F P S T W Y V );
# now A-R is the same as R-A in terms of interactions but if we
# only use one we need a sort so use both, duplicate data but lose sor
+t....
my @a_a;
for my $a1(@aminos) {
for my $a2(@aminos) {
push @a_a, ["${a1}_${a2}", (join '', sort $a1,$a2)];
}
}
# now prepare our lookup table for interactions
my %interactions;
for my $a_ref( sort{ $a->[1] cmp $b->[1] }@a_a ) {
$interactions{$a_ref->[0]} = rand;
}
my @chains = map{ [(@aminos)x25] } 0..5;
my $interact;
for my $ca_i( 0.. $#chains-1 ) {
for my $cb_i( $ca_i+1 .. $#chains ) {
print "Comparing chain $ca_i to $cb_i\n";
for my $res_a( @{$chains[$ca_i]} ) {
for my $res_b( @{$chains[$cb_i]} ) {
$interact = $res_a . '_' .$res_b;
print "\t$interact => $interactions{$interact}\n";
}
}
}
}