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"; } } } }

cheers

tachyon


In reply to Re: Iteration speed by tachyon
in thread Iteration speed by seaver

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.