Skip to content

Instantly share code, notes, and snippets.

@MattOates
Created March 24, 2015 12:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MattOates/95470a79ea98f4e77357 to your computer and use it in GitHub Desktop.
Save MattOates/95470a79ea98f4e77357 to your computer and use it in GitHub Desktop.
Mising bits from P5 necessary for a port of the six-frame-translation perl6-bench benchmark
use strict;
use feature 'say';
use Data::Dumper;
use List::MoreUtils 'zip';
#Implement something similar to the Perl6 X meta operator
#probably not the best implementation in the world
sub X {
my ($callback, @sets) = @_;
my @cross_product = [];
foreach my $set (reverse @sets) {
my @set = @$set;
@cross_product = map {
my $item = $_;
map {
my @other_set_values = @$_;
[ $item, @other_set_values ]
} @cross_product
} @set;
}
@cross_product = map &$callback(@$_), @cross_product;
return @cross_product;
}
my @codons = X( sub {join '', @_}, ['T','C','A','G'] x 3 );
my @aminos = qw(F F L L S S S S
Y Y * * C C * W
L L L L P P P P
H H Q Q R R R R
I I I M T T T T
N N K K S S R R
V V V V A A A A
D D E E G G G G);
my %translation_tables = ( standard => { zip @codons, @aminos };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment